I've already tried using COM to do this but every time, I allow this line to run:
ICalculatorPtr pICalc(__uuidof(ManagedClass));
This line breaks my C++ function that calls it. I know the Microsoft Article is made for a C++ Client Console Application but shouldn't the COM approach work for a C++ DLL?
FYI, the C++ DLL is getting import into another program at runtime. (Design of the main application).
Is the only way to make three projects in my Visual Studio Solution: The C#.net DLL, the C++/CLI managed.DLL, then the C++ Native.DLL.
I added a catch to the com error:
try {
ICalculatorPtr myvalue(__uuidof(ManagedClass));
}
catch (_com_error &e)
{
// Crack _com_error
_bstr_t bstrSource(e.Source());
_bstr_t bstrDescription(e.Description());
std::ofstream out("C:\\Samples\\output.txt");
out << "Error 1: " << e.Error() << "\n" ;
out << "Error 2: " << e.ErrorMessage() << "\n";
out << "Error 3: " << (LPCTSTR)bstrSource << "\n";
out << "Error 4: " << (LPCTSTR)bstrDescription << "\n";
out.close();
}
Output was
Error 1: -2147221164 Error 2: 00000272EED86F40 Error 3: 0000000000000000 Error 4: 0000000000000000
This code is class not registered.
I did register the C# .dll in registry. RegAsm.exe ManagedDLL.dll /tlb:ManagedDLL.tlb /codebase
The code all works with a C++ Console App but not as a C++ DLL getting loaded into the client application.