Pls help

C

cecille

I have a C++ program that is giving me a CString type of data.

But I have a C# DLL that accepts a String input in its argument.

I need to access that C# dll that accepts a String parameter in the C++
program. but how can I pass the CString input into the C# dll.

I have created a managed C++ code to be able to connect the C++ application
and the C# DLL
but I dont know how to pass the parameters that will be accepted by my C#
dll.

Please look into the code below

Ex.

C# code
public class myClass
{
private string _property1;
private string _property2;


public string Property1
{
set{
_property1 = value;
}
get{
return _property1;
}
}

public string Property2
{
set{
_property2 = value;
}
get{
return _property2;
}
}
public Void SomeMethod()
{
dosomething ( Property1,out Pproperty2);
my code implementation here...
}
}

Unmanaged C++ Code
void CMethod::MyMethod()
{

CString input

SomeMethod(i dont know how to pass the input to this manage C++
method);
}

Manage C++ code
__declspec(dllexport) void _cdecl SomeMethod(i dont know what to put in here
that I can pass the CString input)
{

Call my C# MyClass

myClass::SomeMethod method1;

method1.Property1=(this should be the Input string )
}


If i put it this way

__declspec(dllexport) void _cdecl SOmeMethod(char* input, Char** &
retValue)
{

Call my C# MyClass

myClass::SomeMethod method1;

method1.Property1=input;
retValue = method1.Property2;
}
I will get the following errors :
1. Error C2664:''myClass::SomeMethod::property1::set':cannot convert
parameter 1 from 'char *' to 'Systems::String^'
2.Error C2440:'+':cannot convert from 'System::Collections::Arraylist^' to
'char **'


please help.

thanks
 
F

Frans Bouma [C# MVP]

cecille said:
I have a C++ program that is giving me a CString type of data.

But I have a C# DLL that accepts a String input in its argument.

I need to access that C# dll that accepts a String parameter in the
C++ program. but how can I pass the CString input into the C# dll.

I have created a managed C++ code to be able to connect the C++
application and the C# DLL
but I dont know how to pass the parameters that will be accepted by
my C# dll.

Convert the string to a BSTR and pass it to the C# code. .NET uses
BSTRs as strings, not CStrings.

FB

--
------------------------------------------------------------------------
Lead developer of LLBLGen Pro, the productive O/R mapper for .NET
LLBLGen Pro website: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top