We are faced with the interaction problem, we write client exe in C #, we have some inherited code written in COM dll and one native C ++ static library. We demanded to use both of them to perform functions in the C # client. We added a link to COM-dll using interop and were able to create an instance of the COM class inside C # code. Now these COM class methods take arguments that are inactive C ++ objects. Some of the methods in a COM class need arguments that are objects of classes declared in the C ++ static library. Since we won’t be able to instantiate native C ++ classes in C #, we decided to write a C ++ / CLI wrapper in our native class and create a warpper instance in C # code and access the native class instance through warpper and pass it to the COM class created on a C # client.The problem is when we pass our own pointer to an object (like IntPtr) in the COM class, we do not get our own object initialized with its values. What could be the problem? How do we pass our own object through a managed C ++ shell to C # code?
class __declspec(dllexport) CConfiguration
{
public :
CConfiguration(void);
virtual ~CConfiguration(void);
void SetIPAddress(const char *IPAddress);
void SetPort(const char*Port);
void GetIPAddress(char *IPAddress);
void GetPort(char *Port);
Private:
std::string IPAddress;
std::string Port;
}
public ref class ManagedConfigruation
{
public :
ManagedConfigruation(){}
~ManagedConfigruation(){}
CConfiguration *myConfiguration;
IntPtr GetObjectOfConfigurationPtr();
}
IntPtr ManagedConfigruation::GetObjectOfConfigurationPtr()
{
myConfiguration = new CConfiguration();
myConfiguration.SetIPAddress("127.0.0.1");
myConfiguration.SetPort("6200");
return System::IntPtr(myConfiguration);
};
public class CSharpClass
{
ManagedConfiguration objManagedConfiguration = new ManagedConfiguration();
IntPtr objPtr = objManagedConfiguration.GetObjectOfConfigurationPtr();
COMObject.Initialize(objPtr);
}