D
devgrt
Checking if proper/best way to do this...
I have to pass a C# string to a C++ DLL. The function in the DLL
(gethostbyname) requires a null terminated string. It seems like when you do
byte [] var = Encoding.ASCII.GetBytes(string); that it only loads the byte
array with the chars and does not add a null at the end. I would like to
know if the below is proper way to deal with this:
byte [] var = Encoding.ASCII.GetBytes(string + '\0');
By using this when I pass var to C++ func char* I do get the correct string
and can call gethostbyname(var); and it works OK.
Thank you!
I have to pass a C# string to a C++ DLL. The function in the DLL
(gethostbyname) requires a null terminated string. It seems like when you do
byte [] var = Encoding.ASCII.GetBytes(string); that it only loads the byte
array with the chars and does not add a null at the end. I would like to
know if the below is proper way to deal with this:
byte [] var = Encoding.ASCII.GetBytes(string + '\0');
By using this when I pass var to C++ func char* I do get the correct string
and can call gethostbyname(var); and it works OK.
Thank you!