Real Software Forums
http://forums.realsoftware.com/

STRANGE behaviour when passing a CString pointer (ByRef)
http://forums.realsoftware.com/viewtopic.php?f=6&t=42219
Page 1 of 1

Author:  georget [ Fri Jan 13, 2012 10:05 am ]
Post subject:  STRANGE behaviour when passing a CString pointer (ByRef)

Hi,

I have an external method that gets a string pointer as an input parameter, like below:
Declare Function ExternalFunction LIB "name.dll" ALIAS "SomeAlias" (ByRef strName As CString) As Integer


When I call this method, if my Cstring variable (in this case "strName ") has less than 140 characters and does not contain a new line character then
appears as empty in the external method.

If the strName variable has more than 140 characters and also contains a new line character, then everything works just fine.

Anyone can explain this please?
Any help is appreciated!!!!

Real Studio 2011, Release 4, on Windows 7.

Author:  georget [ Sun Jan 15, 2012 6:21 am ]
Post subject:  Re: STRANGE behaviour when passing a CString pointer (ByRef)

Hi,

I have an external method (created with PowerBasic) that gets a string pointer as an input parameter, like below:
Declare Function ExternalFunction LIB "name.dll" ALIAS "SomeAlias" (ByRef strName As CString) As Integer


When I call this method, if my Cstring variable (in this case "strName ") has less than 140 characters and does not contain a new line character then
appears as empty in the external method.

If the strName variable has more than 140 characters and also contains a new line character, then everything works just fine.

Anyone can explain this please?
Any help is appreciated!!!!

Real Studio 2011, Release 4, on Windows 7.[/quote]

Author:  timhare [ Sun Jan 15, 2012 5:10 pm ]
Post subject:  Re: STRANGE behaviour when passing a CString pointer (ByRef)

How is the parameter defined in the dll? char **? I presume you're passing a Memoryblock to the declare.

Author:  georget [ Mon Jan 16, 2012 3:53 am ]
Post subject:  Re: STRANGE behaviour when passing a CString pointer (ByRef)

Thanks for your response timhare.

In the PowerBasic method, the parameter is defined as "STRING POINTER" which is equivalent to char **.
In the RealBasic method, I'm calling the PB method using the string's pointer (use ByRef).

I tried to use memoryBlock but it didn't work at all.

Author:  timhare [ Mon Jan 16, 2012 1:40 pm ]
Post subject:  Re: STRANGE behaviour when passing a CString pointer (ByRef)

Declare it

(strname as Ptr)

and pass it a memoryblock.

Author:  georget [ Tue Jan 17, 2012 3:09 am ]
Post subject:  STRANGE behaviour when passing a CString pointer (ByRef)-SOL

Thank you very much timhare. It worked!!!!!
Actually I also had to change the string type in declaration of the PB method from STRING to STRINGZ (anyway this is PB).
But since I knew from your post what was the correct declaration in RB, I tried various declarations in the external method until it worked.

Page 1 of 1 All times are UTC - 5 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/