passing VB.NET Strings to VC dll.
Posted on 2004-03-27
I want to pass a VB.NET string variable to my VC dll. The function in dll uses LPSTR. why is it that i have to set the string to some initial value and then pass this string. This style works, but it is not a proper one. for example -
Dim str as String
str = "11111111111"
if i don't do this, i get an error of Nullreference ptr. this style is quite an improper one. if the new value put by the DLL is greater than the size specified, i.e., "11111111111", then that value is truncated to the VB String size. if the new value filled in by DLL is less than initial size of "11111111111", then that much goes as a waste.
is there any other method to do this stuff. i've tried interop marshal concept using Intptr. that too fails. Intptr works fine when i've a string inside a structure. but if that string goes individually, IntPtr fails. i don't understand why it fails here.