Click here to Skip to main content
15,894,314 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello,

How do I pass a string to C# from VC++ using the function described in
Codeproject[^]

If I use this in VC++:

TCHAR chMyString[256];
varArgs[0].vt = VT_BYREF|VT_BSTR;
varArgs[0].bstrVal = _bstr_t(chMyString);


and this in C#:

public void MyString([In, MarshalAs(UnmanagedType.BStr)] string chMyString)
{
    MessageBox.Show(chMyString); //ALWAYS EMPTY STRING
}


The varArgs[0].bstrVal is not passed to C#. Can someone help me? If there are other ways, please advise me.
Posted
Updated 19-Jul-10 2:38am
v4
Comments
Toli Cuturicu 20-Jul-10 10:54am    
Reason for my vote of 1
ask there (at the article forum), not here!

1 solution

The subtitle of the article you are referencing says: A simple way to call a managed method from the unmanaged world

What you are trying to do is the opposite!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900