Sijin and Salvador,
A ref byte won't work because the marshaller doesn't know how much
information to marshal back.
The string builder doesn't work because when marshaling back, it takes
the string terminator ('\0') and stops marshaling at that point.
To get around this, declare the paramter as type IntPtr. Allocate
unmanaged memory using the static methods on the Marshal class. Pass that
pointer, and upon return, pass the pointer to PtrToAnsiString.
This is the important part. Once you do that, you have to advance the
pointer instance past the end of the first '\0' character, and then read the
memory again. You do this until you have read all the content.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
-
mv*@spam.guard.caspershouse.com
"Sijin Joseph" <si***************@hotmail.com> wrote in message
news:uv**************@TK2MSFTNGP11.phx.gbl...
Have you tried passing a ref byte[] to the DLL instead of a stringbuilder,
since the return value has NULL chars in it the StringBuilder will not
interpret the value correctly.
Sijin Joseph
http://www.indiangeek.net
http://weblogs.asp.net/sjoseph
Salvador wrote: Hi, I am using an old Win32 DLL that expects a LPBYTE as a parameter.
The Stringbuilder appears to be working, the problem is that the
component is sending me a string with NULL characters in the middle, and
my StringBuilder is shrinking the message. Example
StringBuilder buffer = new StringBuilder(255);
Win32 sends : VB123421414\0\0\0\0HRA0021331
StringBuilder reads : VB123421414
Is there any way to read the full buffer? The capacity is 255, how can I
read position 240 for example? is raising an error if I put buffer[240]
Thanks!!!!
SAlva