Passing string to DLL truncates to first character

Just starting out? Need help? Post your questions and find answers here.
PeterJ
User
User
Posts: 11
Joined: Fri Jun 11, 2010 5:43 am

Passing string to DLL truncates to first character

Post by PeterJ »

Hello,

when passing a string to a DLL (also PB), only the first character is received in the DLL. I was able to reproduce it with one of the Help examples:

Code: Select all

Prototype.i ProtoMessageBox(Window.i, Body$, Title$, Flags.i = 0)
If OpenLibrary(0, "User32.dll") 
   MsgBox.ProtoMessageBox = GetFunction(0, "MessageBoxA")
   MsgBox(0, "Hello", "World") ; wir geben keine Flags an
EndIf
The message box pops up with the header "H" and Text "W".
Numeric parameters work find.

I am running PB 5.31; 5.30 shows same behaviour.

Peter
Little John
Addict
Addict
Posts: 4795
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Passing string to DLL truncates to first character

Post by Little John »

PeterJ wrote:Hello,

when passing a string to a DLL (also PB), only the first character is received in the DLL. I was able to reproduce it with one of the Help examples:

Code: Select all

Prototype.i ProtoMessageBox(Window.i, Body$, Title$, Flags.i = 0)
If OpenLibrary(0, "User32.dll") 
   MsgBox.ProtoMessageBox = GetFunction(0, "MessageBoxA")
   MsgBox(0, "Hello", "World") ; wir geben keine Flags an
EndIf
The message box pops up with the header "H" and Text "W".
Use MessageBoxA when your program is compiled in ASCII mode,
use MessageBoxW when your program is compiled in Unicode mode.

And your self-made DLL should be compiled in the same mode as your program, which calls functions in that DLL.
PeterJ
User
User
Posts: 11
Joined: Fri Jun 11, 2010 5:43 am

Re: Passing string to DLL truncates to first character

Post by PeterJ »

... there is always something :cry:
This was exactly the reason! Thanks for quick any easy solution!
Now my DLL perfectly runs !

Peter
User avatar
skywalk
Addict
Addict
Posts: 4229
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Passing string to DLL truncates to first character

Post by skywalk »

Even though PB is dropping Ascii compiles, you can still access Ascii libs with pseudotypes.

Code: Select all

Prototype.i ProtoMessageBox(Window.i, Body.p-Ascii, Title.p-Ascii, Flags.i = 0)
If OpenLibrary(0, "User32.dll") 
   MsgBox.ProtoMessageBox = GetFunction(0, "MessageBoxA")
   MsgBox(0, "Hello", "World") ; wir geben keine Flags an
EndIf
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Little John
Addict
Addict
Posts: 4795
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Passing string to DLL truncates to first character

Post by Little John »

Oh yes, I forgot about pseudotypes.
Post Reply