Returning String initialized from Unmanaged Code

  • Thread starter Thread starter skg
  • Start date Start date
S

skg

I have following function in unmanged code

BOOL _stdcall ExtractId(

String *psclr_File, String *psclr_Id)

{

....

BSTR *lplpszMessageId;

System::IntPtr target = lplpszMessageId;

psclr_Id= Marshal::PtrToStringBSTR(target); //psclr_Id shows correct value
assigned to it when debugging.

.....

}

when my call returns the value of psclr_Id is blank.

I have declared the function as follows in managed code.

[DllImport("msg.dll", CharSet=CharSet.Ansi,
CallingConvention=CallingConvention.Cdecl)]
public static extern bool ExtractId( String psg, String pID);

How can i return the string initialized from the unmanaged code.?
TIA
 
The code you are showing looks like it's managed C++, but when I look at the
function definition:

BOOL _stdcall ExtractId( String *psclr_File, String *psclr_Id)
I see __stdcall which is not valid in managed signatures, but the String
arguments are supposed to be a managed type right?
The function is a managed function else you could not have stuff like
System::IntPtr and Marshal::PtrToStringBSTR in it.

So I wonder how you managed to compile this compile this? Also I wonder why
you are using PInvoke to call managed functions?
Please post the real code if you need more help on this.

Willy.
 
Back
Top