B
Bob
I have a managed C++ class that uses an unmanaged C++ library. That library
stores some character strings which I access through a char*. I use that
string as an argument to a String::IndexOf(). When I run, I sometimes get
either of the following exceptions:
"System.ArgumentException: The pointer passed in as a String must not be in
the bottom 64K of the process's address space."
"System.ArgumentOutOfRangeException: Pointer startIndex and length do not
refer to a valid string."
When I look at the string in the debugger, it is garbage. (e.g.
"ô<hT.,½/"). The string was set in the unmanaged library with the
following code:
System::IntPtr imagePointer =
(System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(imageName));
char* charPointer = (char*)imagePointer.ToPointer();
unmanagedLib->SetString(charPointer);
System::Runtime::InteropServices::Marshal::FreeHGlobal(imagePointer);
Why is this? What am I missing that I need to do to use these strings? Do
I need to also marshal the unmanaged string somehow?
Thanks! Bob
stores some character strings which I access through a char*. I use that
string as an argument to a String::IndexOf(). When I run, I sometimes get
either of the following exceptions:
"System.ArgumentException: The pointer passed in as a String must not be in
the bottom 64K of the process's address space."
"System.ArgumentOutOfRangeException: Pointer startIndex and length do not
refer to a valid string."
When I look at the string in the debugger, it is garbage. (e.g.
"ô<hT.,½/"). The string was set in the unmanaged library with the
following code:
System::IntPtr imagePointer =
(System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(imageName));
char* charPointer = (char*)imagePointer.ToPointer();
unmanagedLib->SetString(charPointer);
System::Runtime::InteropServices::Marshal::FreeHGlobal(imagePointer);
Why is this? What am I missing that I need to do to use these strings? Do
I need to also marshal the unmanaged string somehow?
Thanks! Bob