Path: csiph.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: "Wolfgang Riedmann" Newsgroups: comp.lang.clipper.visual-objects Subject: Re: DLL Definition/Third Party DLLs Date: Mon, 7 Dec 2020 16:39:56 +0100 Lines: 58 Message-ID: References: <0d99606e-aae6-4639-81fd-20c7f6840807n@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: individual.net DklJs12pQ4DEtWJLEuGsYAQjRWqySZZB0UPLpf9kR0LxLm5As= Cancel-Lock: sha1:s11MUDMTU1GUDVVzy7x+H6Qgdrc= User-Agent: XanaNews/1.18.1.6 Xref: csiph.com comp.lang.clipper.visual-objects:13166 Hi Sebastián, that should work.... I suspect that there is an error in the access of the PSZ. Ho do you retrieve the string? cString := StringAlloc( pszString, nLen) should work. Wolfgang > Hi, i need to use a third party dll in my application that > communicates with a device connected on a serial port. In > development i test my application with a simulator provided by the > manufacturer of the device. My application works fine but when i > change to use the physical device starts crash randomly with Access > Violation 5333. I have to add all the defines (based on a header C > file provided with the device) and maybe i do some wrong with that > step. One line in that header file is: > > DLL_EXPORT_IMPORT int DLL_STD_CALL QueryLastNumber(const char *type, > char *desc, int length, int *code); > > in Vo i add: > _DLL FUNCTION QueryLastNumber(type AS STRING, desc AS PSZ, length AS > INT, code AS INT PTR) AS INT PASCAL:DllName.QueryLastNumber > > Later in code i call: > > LOCAL hLibrary AS PTR > LOCAL pszDesc AS PSZ > LOCAL cType AS STRING > LOCAL iLenght, iCode AS INT > > hLibrary:= LoadLibrary(String2Psz(cDllName) > IF !IsNil(hLibrary) > // Code for interaction > pszDesc:= MemAlloc(50) > iResult:= QueryLastNumber(ctype, pszDesc, iLenght, @iCode) > MemFree(pszDesc) > ENDIF > > and finally > > FreeLibrary(hLibrary) > > For all the PSZ params i do MemAlloc and MemFree. > I look twice the code searching for some missing MemFree, but all > seems fine. This is the correct way? > Thanks --