Click here to Skip to main content
15,880,796 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I Created a C# Dll that use it in my C++ project. First i register and create a tlb file from that dll file, then i use it in my C++ project:

in my c++ project:
#import "..\..\dll\PMI_EPD.tlb" raw_interfaces_only


I pass a string to function of dll, as a parameter. but in dll it is empty!

in C# dll code:
public int GetText(string ss)
{
   return 5;
}


in c++ code:
InterfacePtr pmi(__uuidof(MY_Class));
int i;
pmi->GetText(L"2279947463", &i);


if i change string type in c#, StringBuilder, it will be correct. but when the function returns it crashes.

XML
<pre>public int GetText(StringBuilder ss)
{
   return 5;
}</pre>


what do i do, please help me.
Posted
Updated 19-May-15 22:32pm
v2

1 solution

I solved myself,

in C++ code , I should pass string by AllocSysString():

CString str = L"2279947463";
pmi->GetText(str.AllocSysString(), &i);
 
Share this answer
 
Comments
Philippe Mori 20-May-15 20:24pm    
And you should also free the string after use.

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