Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.clipper.visual-objects > #13165 > unrolled thread

DLL Definition/Third Party DLLs

Started bySebastián BASSANO <ccyasa.sbassano@gmail.com>
First post2020-12-07 05:40 -0800
Last post2020-12-09 03:24 -0800
Articles 10 — 3 participants

Back to article view | Back to comp.lang.clipper.visual-objects


Contents

  DLL Definition/Third Party DLLs Sebastián BASSANO <ccyasa.sbassano@gmail.com> - 2020-12-07 05:40 -0800
    Re: DLL Definition/Third Party DLLs "Wolfgang Riedmann" <wriedmann@gmail.com> - 2020-12-07 16:39 +0100
      Re: DLL Definition/Third Party DLLs Sebastián BASSANO <ccyasa.sbassano@gmail.com> - 2020-12-07 08:03 -0800
        Re: DLL Definition/Third Party DLLs "Wolfgang Riedmann" <wriedmann@gmail.com> - 2020-12-08 12:34 +0100
          Re: DLL Definition/Third Party DLLs Sebastián BASSANO <ccyasa.sbassano@gmail.com> - 2020-12-09 03:25 -0800
            Re: DLL Definition/Third Party DLLs Sebastián BASSANO <ccyasa.sbassano@gmail.com> - 2020-12-09 08:56 -0800
              Re: DLL Definition/Third Party DLLs "Wolfgang Riedmann" <wriedmann@gmail.com> - 2020-12-10 11:24 +0100
                Re: DLL Definition/Third Party DLLs Sebastián BASSANO <ccyasa.sbassano@gmail.com> - 2020-12-16 06:17 -0800
    Re: DLL Definition/Third Party DLLs Jamal <nospam@example.com> - 2020-12-08 01:56 -0500
      Re: DLL Definition/Third Party DLLs Sebastián BASSANO <ccyasa.sbassano@gmail.com> - 2020-12-09 03:24 -0800

#13165 — DLL Definition/Third Party DLLs

FromSebastián BASSANO <ccyasa.sbassano@gmail.com>
Date2020-12-07 05:40 -0800
SubjectDLL Definition/Third Party DLLs
Message-ID<0d99606e-aae6-4639-81fd-20c7f6840807n@googlegroups.com>
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

[toc] | [next] | [standalone]


#13166

From"Wolfgang Riedmann" <wriedmann@gmail.com>
Date2020-12-07 16:39 +0100
Message-ID<i370meF61isU1@mid.individual.net>
In reply to#13165
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



-- 

[toc] | [prev] | [next] | [standalone]


#13167

FromSebastián BASSANO <ccyasa.sbassano@gmail.com>
Date2020-12-07 08:03 -0800
Message-ID<d42de7a2-4dad-4f89-b9d4-5acf4d6b4fe7n@googlegroups.com>
In reply to#13166
El Monday, December 7, 2020 a la(s) 12:40:01 PM UTC-3, Wolfgang Riedmann escribió:
> 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
> --
Hi Wolfgang, i'm using:

	LOCAL iResult:= 0 AS INT
	LOCAL pszString:= NULL_PSZ AS PSZ
	LOCAL cString:= NULL_STRING AS STRING

	pszString:= MemAlloc(ERRORLENGHT)
	iResult:= ErrorDesc(iErrorCode, pszString, ERRORLENGHT + 1)
	IF (iResult == 0)
	   cString:= Psz2String(pszString)
	ENDIF
 	MemFree(pszString)
	pszString:= NULL_PSZ

[toc] | [prev] | [next] | [standalone]


#13169

From"Wolfgang Riedmann" <wriedmann@gmail.com>
Date2020-12-08 12:34 +0100
Message-ID<i396m8Fivo4U1@mid.individual.net>
In reply to#13167
Hi Sebastián,

what VO version do you use?

I have looked better at your declaration.

You should also use a ptr for the first parameter (type) since you
don't know what the function does internally with this value, and the
VO runtime moves strings in the memory.

Maybe the DLL later tries to access to that value and reads from a now
invalid memory location.

Wolfgang



 BASSANO wrote:

> El Monday, December 7, 2020 a la(s) 12:40:01 PM UTC-3, Wolfgang
> Riedmann escribió:
> > 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
> > --
> Hi Wolfgang, i'm using:
> 
> 	LOCAL iResult:= 0 AS INT
> 	LOCAL pszString:= NULL_PSZ AS PSZ
> 	LOCAL cString:= NULL_STRING AS STRING
> 
> 	pszString:= MemAlloc(ERRORLENGHT)
> 	iResult:= ErrorDesc(iErrorCode, pszString, ERRORLENGHT + 1)
> 	IF (iResult == 0)
> 	   cString:= Psz2String(pszString)
> 	ENDIF
>  	MemFree(pszString)
> 	pszString:= NULL_PSZ



-- 

[toc] | [prev] | [next] | [standalone]


#13172

FromSebastián BASSANO <ccyasa.sbassano@gmail.com>
Date2020-12-09 03:25 -0800
Message-ID<499292c1-11ad-4e85-b46c-3131b5b32f47n@googlegroups.com>
In reply to#13169
El Tuesday, December 8, 2020 a la(s) 8:34:35 AM UTC-3, Wolfgang Riedmann escribió:
> Hi Sebastián, 
> 
> what VO version do you use? 
> 
> I have looked better at your declaration. 
> 
> You should also use a ptr for the first parameter (type) since you 
> don't know what the function does internally with this value, and the 
> VO runtime moves strings in the memory. 
> 
> Maybe the DLL later tries to access to that value and reads from a now 
> invalid memory location. 
> 
> Wolfgang
> BASSANO wrote: 
> 
> > El Monday, December 7, 2020 a la(s) 12:40:01 PM UTC-3, Wolfgang 
> > Riedmann escribió: 
> > > 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 
> > > -- 
> > Hi Wolfgang, i'm using: 
> > 
> > LOCAL iResult:= 0 AS INT 
> > LOCAL pszString:= NULL_PSZ AS PSZ 
> > LOCAL cString:= NULL_STRING AS STRING 
> > 
> > pszString:= MemAlloc(ERRORLENGHT) 
> > iResult:= ErrorDesc(iErrorCode, pszString, ERRORLENGHT + 1) 
> > IF (iResult == 0) 
> > cString:= Psz2String(pszString) 
> > ENDIF 
> > MemFree(pszString) 
> > pszString:= NULL_PSZ
> --
Thanks, i will change that.

[toc] | [prev] | [next] | [standalone]


#13173

FromSebastián BASSANO <ccyasa.sbassano@gmail.com>
Date2020-12-09 08:56 -0800
Message-ID<6a6464bb-9b5d-40e5-8b4d-09e707fdf3e8n@googlegroups.com>
In reply to#13172
El Wednesday, December 9, 2020 a la(s) 8:25:11 AM UTC-3, Sebastián BASSANO escribió:
> El Tuesday, December 8, 2020 a la(s) 8:34:35 AM UTC-3, Wolfgang Riedmann escribió: 
> > Hi Sebastián, 
> > 
> > what VO version do you use? 
> > 
> > I have looked better at your declaration. 
> > 
> > You should also use a ptr for the first parameter (type) since you 
> > don't know what the function does internally with this value, and the 
> > VO runtime moves strings in the memory. 
> > 
> > Maybe the DLL later tries to access to that value and reads from a now 
> > invalid memory location. 
> > 
> > Wolfgang 
> > BASSANO wrote: 
> > 
> > > El Monday, December 7, 2020 a la(s) 12:40:01 PM UTC-3, Wolfgang 
> > > Riedmann escribió: 
> > > > 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 
> > > > -- 
> > > Hi Wolfgang, i'm using: 
> > > 
> > > LOCAL iResult:= 0 AS INT 
> > > LOCAL pszString:= NULL_PSZ AS PSZ 
> > > LOCAL cString:= NULL_STRING AS STRING 
> > > 
> > > pszString:= MemAlloc(ERRORLENGHT) 
> > > iResult:= ErrorDesc(iErrorCode, pszString, ERRORLENGHT + 1) 
> > > IF (iResult == 0) 
> > > cString:= Psz2String(pszString) 
> > > ENDIF 
> > > MemFree(pszString) 
> > > pszString:= NULL_PSZ 
> > --
> Thanks, i will change that.

I will change all functions and then test...

It's safe to change?

DLL_EXPORT_IMPORT int DLL_STD_CALL SetPort( const char *port );

From:
_DLL FUNCTION SetPort(cPort AS STRING) AS INT PASCAL:DllName.SetPort

to 
_DLL FUNCTION SetPort(pszPort AS PSZ) AS INT PASCAL:DllName.SetPort

and then call

LOCAL iResult:= 0 AS INT
LOCAL pszPort:= NULL_PSZ AS PSZ

pszPort:= StringAlloc(cPort)
iResult:= SetPort(pszPort)
MemFree(pszPort)
pszPort:= NULL_PSZ

Thanks!

[toc] | [prev] | [next] | [standalone]


#13175

From"Wolfgang Riedmann" <wriedmann@gmail.com>
Date2020-12-10 11:24 +0100
Message-ID<i3ebacFj6rqU1@mid.individual.net>
In reply to#13173
Hi Sebastián 

 
> I will change all functions and then test...
> 
> It's safe to change?
> 
> DLL_EXPORT_IMPORT int DLL_STD_CALL SetPort( const char *port );
> 
> From:
> _DLL FUNCTION SetPort(cPort AS STRING) AS INT PASCAL:DllName.SetPort
> 
> to 
> _DLL FUNCTION SetPort(pszPort AS PSZ) AS INT PASCAL:DllName.SetPort
> 
> and then call
> 
> LOCAL iResult:= 0 AS INT
> LOCAL pszPort:= NULL_PSZ AS PSZ
> 
> pszPort:= StringAlloc(cPort)
> iResult:= SetPort(pszPort)
> MemFree(pszPort)
> pszPort:= NULL_PSZ


That should work.

Wolfgang

-- 

[toc] | [prev] | [next] | [standalone]


#13183

FromSebastián BASSANO <ccyasa.sbassano@gmail.com>
Date2020-12-16 06:17 -0800
Message-ID<28701d27-8508-42ca-9fce-45aab5bca01dn@googlegroups.com>
In reply to#13175
El Thursday, December 10, 2020 a la(s) 7:24:15 AM UTC-3, Wolfgang Riedmann escribió:
> Hi Sebastián
> > I will change all functions and then test... 
> > 
> > It's safe to change? 
> > 
> > DLL_EXPORT_IMPORT int DLL_STD_CALL SetPort( const char *port ); 
> > 
> > From: 
> > _DLL FUNCTION SetPort(cPort AS STRING) AS INT PASCAL:DllName.SetPort 
> > 
> > to 
> > _DLL FUNCTION SetPort(pszPort AS PSZ) AS INT PASCAL:DllName.SetPort 
> > 
> > and then call 
> > 
> > LOCAL iResult:= 0 AS INT 
> > LOCAL pszPort:= NULL_PSZ AS PSZ 
> > 
> > pszPort:= StringAlloc(cPort) 
> > iResult:= SetPort(pszPort) 
> > MemFree(pszPort) 
> > pszPort:= NULL_PSZ
> That should work. 
> 
> Wolfgang 
> 
> --
Finally i got working, but the problem continues after my changes, the problem was the DLL, the provider doesn't update the file on the website download link. I have to contact them and they send me an updated DLL.
Thanks.

[toc] | [prev] | [next] | [standalone]


#13168

FromJamal <nospam@example.com>
Date2020-12-08 01:56 -0500
Message-ID<rqn83j$t3m$1@gioia.aioe.org>
In reply to#13165
On 12/7/2020 8:40 AM, Sebastián BASSANO wrote:

 > QueryLastNumber(const char *type, char *desc, int length, int *code);

Note: const char *type

You are passing a string for the above in the first argument. You should 
allocate a string pointer.

Declare as:

_DLL FUNCTION QueryLastNumber(pType AS PSZ, desc AS PSZ, length AS INT, 
code AS INT PTR) AS INT PASCAL:DllName.QueryLastNumber

HTH,
Jamal

[toc] | [prev] | [next] | [standalone]


#13171

FromSebastián BASSANO <ccyasa.sbassano@gmail.com>
Date2020-12-09 03:24 -0800
Message-ID<a7c943db-abe0-4468-b0dc-afafc253ca12n@googlegroups.com>
In reply to#13168
El Tuesday, December 8, 2020 a la(s) 3:56:53 AM UTC-3, Jamal escribió:
> On 12/7/2020 8:40 AM, Sebastián BASSANO wrote: 
> 
> > QueryLastNumber(const char *type, char *desc, int length, int *code);
> Note: const char *type 
> 
> You are passing a string for the above in the first argument. You should 
> allocate a string pointer. 
> 
> Declare as: 
> 
> _DLL FUNCTION QueryLastNumber(pType AS PSZ, desc AS PSZ, length AS INT,
> code AS INT PTR) AS INT PASCAL:DllName.QueryLastNumber
> HTH, 
> Jamal
Thanks Jamal, i will change that.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.clipper.visual-objects


csiph-web