Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

String issues with COM when used on .NET

Status
Not open for further replies.

phinoppix

Programmer
Jul 24, 2002
437
US
Hi,

I'm having a problem using a COM component on C#; the component is developed in Delphi 5. I have this function:
Code:
[COLOR=green]// Delphi COM[/color]
function  TestString(const strOMA: WideString): WideString; stdcall;
This is the callable wrapper:
Code:
[PreserveSig]
string TestString([In, MarshalAs(UnmanagedType.BStr)]string StrOma);
The error thrown from .NET is:

Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
I am expecting a debug string generated when TestString runs, but never happened (so the error might be during marshaling of parameters?). I also noticed that I only get the error when I have WideString as a parameter or as return type.

I changed WideString to PChar, and added a Marshal attribute on C#, and it worked. Still, I'm really hoping to fix this problem only on the .NET side. Can anyone shed a light on the probable cause of the error?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top