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


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

VO + C again

Started by"Bernhard Mayer" <Idonotexisthere@nowhere.com>
First post2011-08-17 18:06 +0200
Last post2011-08-19 20:11 +0000
Articles 5 — 3 participants

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


Contents

  VO + C again "Bernhard Mayer" <Idonotexisthere@nowhere.com> - 2011-08-17 18:06 +0200
    Re: VO + C again "Karl-Heinz" <invalid@invalid.invalid> - 2011-08-17 19:52 +0200
      Re: VO + C again "Bernhard Mayer" <Idonotexisthere@nowhere.com> - 2011-08-18 08:11 +0200
        Re: VO + C again "Karl-Heinz" <invalid@invalid.invalid> - 2011-08-18 10:42 +0200
          Re: VO + C again "Uwe Heyer" <uwe.heyer@aristik.de> - 2011-08-19 20:11 +0000

#1839 — VO + C again

From"Bernhard Mayer" <Idonotexisthere@nowhere.com>
Date2011-08-17 18:06 +0200
SubjectVO + C again
Message-ID<4e4be6fa$0$1579$91cee783@newsreader04.highway.telekom.at>
Dear fellow VOers!

According to a .h file we got from the product owner, the prototype of a 
C/C++ function looks as follows:

POSNET_API      POSNET_HANDLE  __stdcall POS_CreateRequestEx(POSNET_HANDLE 
hLocalDevice, const char*
command,const char *parameters);

#define POSNET_API  __declspec(dllexport)
typedef  void*     POSNET_HANDLE;

I tried the "prototyping way" (according to Gunnar Bless' book, __stdcall 
requires the PASCAL convention)

_dll FUNCTION POS_CreateRequestEx(hLocalDevice as ptr, pszCmd as psz, 
pszParameters as psz) as ptr PASCAL:Libposcmbth.POS_CreateRequestEx
// Tried that one, too
// _dll FUNCTION POS_CreateRequestEx(hLocalDevice as ptr, pszCmd as psz, 
pszParameters as psz) as ptr STRICT:Libposcmbth.POS_CreateRequestEx

and the dynamic way

LOCAL pFunc AS PTR
LOCAL pReturn AS PTR

IF SELF:pFiscal != NULL_PTR  // pFiscal = Valid handle of dll loaded with 
LoadLibrary
   pFunc := GetProcAddress(SELF:pFiscal, String2Psz("POS_CreateRequestEx"))
   IF pFunc != NULL_PTR
       pReturn :=  PCALL(pFunc, hLocalDevice, String2Psz(cCmd), 
String2Psz(cParameters))
       // Tried that one, too:
       // pReturn :=  CCALL(pFunc, hLocalDevice, String2Psz(cCmd), 
String2Psz(cParameters))
   ENDIF
ENDIF

 RETURN pReturn

However, none of it works as it should; all I'm getting is an unhandled 
exception from the C dll. I would like it implemented the PCALL/CCALL way as 
this is an additional functionality which should not be available to all 
customers, most of them won't get the 3rd party C dll.

Can anyone help me in this matter? Some of the other C calls do work, but 
none of the calls having 2 PSZ params do work.

BR,
Bernhard 

[toc] | [next] | [standalone]


#1841

From"Karl-Heinz" <invalid@invalid.invalid>
Date2011-08-17 19:52 +0200
Message-ID<9b2dhoFlv7U1@mid.individual.net>
In reply to#1839
Bernhard,

> and the dynamic way
>
> LOCAL pFunc AS PTR
> LOCAL pReturn AS PTR
>
> IF SELF:pFiscal != NULL_PTR  // pFiscal = Valid handle of dll loaded with
> LoadLibrary
>   pFunc := GetProcAddress(SELF:pFiscal, String2Psz("POS_CreateRequestEx"))
>   IF pFunc != NULL_PTR
>       pReturn :=  PCALL(pFunc, hLocalDevice, String2Psz(cCmd),
> String2Psz(cParameters))
>       // Tried that one, too:
>       // pReturn :=  CCALL(pFunc, hLocalDevice, String2Psz(cCmd),
> String2Psz(cParameters))
>   ENDIF
> ENDIF
>
> RETURN pReturn

( sometimes ) i´m having problems too using PSZs in dynamics calls. In such
cases the only way to make it work is to use PTRs instead of PSZs

try this one first :
--------------- 1 ----------
LOCAL pszCmd, pszParams AS PSZ

pszCmd := stringalloc ( cCmd )
pszParams := stringalloc ( cParameters )

pReturn :=  PCALL(pFunc, hLocalDevice, pszCmd ,  pszParams )

memfree ( pszCmd  )
memfree ( pszParams )

if it doens´t help , try:
---------------  2 ----------
LOCAL ptrCmd, ptrParams AS PTR

//  simulate a PSZ
ptrCmd  := MemAlloc ( SLen ( cCmd) + 1  )
MemCopyString ( ptrCmd  , cCmd, SLen ( cCmd) )

//  simulate a PSZ
ptrParams := MemAlloc ( SLen ( cParameters) + 1  )
MemCopyString ( ptrParams , cParameters, SLen ( cParameters) )

pReturn :=  PCALL(pFunc, hLocalDevice, ptrCmd,  ptrParams )

memfree ( ptrCmd )
memfree ( ptrParams )


regards
Karl-Heinz

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


#1842

From"Bernhard Mayer" <Idonotexisthere@nowhere.com>
Date2011-08-18 08:11 +0200
Message-ID<4e4cacef$0$18680$91cee783@newsreader03.highway.telekom.at>
In reply to#1841
Thanks a lot - the PTR method seems to work!

HAND,
Bernhard

"Karl-Heinz" <invalid@invalid.invalid> schrieb im Newsbeitrag 
news:9b2dhoFlv7U1@mid.individual.net...
> Bernhard,
>
>> and the dynamic way
>>
>> LOCAL pFunc AS PTR
>> LOCAL pReturn AS PTR
>>
>> IF SELF:pFiscal != NULL_PTR  // pFiscal = Valid handle of dll loaded with
>> LoadLibrary
>>   pFunc := GetProcAddress(SELF:pFiscal, 
>> String2Psz("POS_CreateRequestEx"))
>>   IF pFunc != NULL_PTR
>>       pReturn :=  PCALL(pFunc, hLocalDevice, String2Psz(cCmd),
>> String2Psz(cParameters))
>>       // Tried that one, too:
>>       // pReturn :=  CCALL(pFunc, hLocalDevice, String2Psz(cCmd),
>> String2Psz(cParameters))
>>   ENDIF
>> ENDIF
>>
>> RETURN pReturn
>
> ( sometimes ) i´m having problems too using PSZs in dynamics calls. In 
> such
> cases the only way to make it work is to use PTRs instead of PSZs
>
> try this one first :
> --------------- 1 ----------
> LOCAL pszCmd, pszParams AS PSZ
>
> pszCmd := stringalloc ( cCmd )
> pszParams := stringalloc ( cParameters )
>
> pReturn :=  PCALL(pFunc, hLocalDevice, pszCmd ,  pszParams )
>
> memfree ( pszCmd  )
> memfree ( pszParams )
>
> if it doens´t help , try:
> ---------------  2 ----------
> LOCAL ptrCmd, ptrParams AS PTR
>
> //  simulate a PSZ
> ptrCmd  := MemAlloc ( SLen ( cCmd) + 1  )
> MemCopyString ( ptrCmd  , cCmd, SLen ( cCmd) )
>
> //  simulate a PSZ
> ptrParams := MemAlloc ( SLen ( cParameters) + 1  )
> MemCopyString ( ptrParams , cParameters, SLen ( cParameters) )
>
> pReturn :=  PCALL(pFunc, hLocalDevice, ptrCmd,  ptrParams )
>
> memfree ( ptrCmd )
> memfree ( ptrParams )
>
>
> regards
> Karl-Heinz
> 

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


#1845

From"Karl-Heinz" <invalid@invalid.invalid>
Date2011-08-18 10:42 +0200
Message-ID<9b41lkFt6lU1@mid.individual.net>
In reply to#1842
Bernhard,

>
> Thanks a lot - the PTR method seems to work!
>

no prob.

BTW. what happens when you try this slightly modified "PSZ-Version" ?

--------------
LOCAL pszCmd, pszParams AS PSZ

pszCmd := stringalloc ( cCmd )
pszParams := stringalloc ( cParameters )

pReturn :=  PCALL(pFunc, hLocalDevice, PTR ( _CAST , pszCmd  ) , PTR ( _CAST 
,  pszParams ) )

memfree ( pszCmd  )
memfree ( pszParams )

-----------

regards
Karl-Heinz

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


#1858

From"Uwe Heyer" <uwe.heyer@aristik.de>
Date2011-08-19 20:11 +0000
Message-ID<9b7ubeFh40U1@mid.individual.net>
In reply to#1845
Hi Karl-Heinz,

> pFunc 

> PCALL(pFunc,

I would use declared pointers for PCALL/CCALL


Ahoj
-Uwe

[toc] | [prev] | [standalone]


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


csiph-web