How can I create an instance for a class in c# dll that I imported in a c++ project? I have imported the c# library to c++ by following the instructions given here. I can call the functions using the public interface.
[EDIT] I want to set values for the attributes of the class in c# dll through c++ and to pass it to the dll. So that I can skip so many set functions in c# dll. If I can create object for the class, I will set the values using the object and pass the object to c# dll.
Asked
Active
Viewed 589 times
-1

Fresher
- 493
- 6
- 18
-
And then what are you going to do after you _pass the object to c# dll_? – mike Feb 18 '16 at 11:52
-
I will pass it to the xml serialization function. I want to set all the data in object and pass it to dll. Dll will use it for xmlserialization. – Fresher Feb 19 '16 at 12:17
1 Answers
0
In the link you provided, in the c++ client code description
// CPPClient.cpp: Defines the entry point for the console application.
// C++ client that calls a managed DLL.
#include "stdafx.h"
#include "tchar.h"
// Import the type library.
#import "..\ManagedDLL\bin\Debug\ManagedDLL.tlb" raw_interfaces_only
using namespace ManagedDLL;
int _tmain(int argc, _TCHAR* argv[])
{
// Initialize COM.
HRESULT hr = CoInitialize(NULL);
// Create the interface pointer.
ICalculatorPtr pICalc(__uuidof(ManagedClass));
long lResult = 0;
// Call the Add method.
pICalc->Add(5, 10, &lResult);
wprintf(L"The result is %d\n", lResult);
// Uninitialize COM.
CoUninitialize();
return 0;
}
the creation of the pointer, pICalc
is the pretty much the creation of the object of the class. Created in the line ICalculatorPtr pICalc(__uuidof(ManagedClass));

mike
- 455
- 2
- 6
-
I have some other classes in my dll. Can I create objects for those classes? I need to access data attributes too. – Fresher Feb 18 '16 at 06:54