C
Capsule
Hi all,
I'm trying to call a C# dll from c++. I followed an example from the
MSDN site, and I am able to get their example working, however, I
believe their example is a console application, as it takes in command
args.
I'd like to be able to do the same thing, but from a c++ dll. However,
when I port the same code over, it says it cannot create the instance
(from the CoCreateInstance).
The code is the same from the console app, so I'm not sure what the
problem is.
To be honest, I'm no c++ guy, so I'm stumped as to even choose an
avenue to try next. I'm hoping it's a build setting or something, but
I'm just not sure... Any help would be appreciated.
Thanks in advance
//////// c++ Snip:
-----------------------------------------------
IManagedInterface *cpi = NULL;
// Initialize COM and create an instance
// of the InterfaceImplementation class:
CoInitialize(NULL);
HRESULT hr = CoCreateInstance(CLSID_InterfaceImplementation,
NULL,
CLSCTX_INPROC_SERVER,
IID_IManagedInterface,
reinterpret_cast<void**>(&cpi));
// CoCreateInstance works great in the console app,
// but fails when called in the dll
if (FAILED(hr))
{
MessageBox(NULL, L"Couldn't create the instance! 0x%x\n", L"",
0);
}
cpi->PrintHi("team");
cpi->Release();
// Be a good citizen and clean up COM:
CoUninitialize();
/////C# interface server snip
-------------------------------------------------
[Guid( "DBE0E8C4-1C61-41f3-B6A4-4E2F353D3D05" )]
public interface IManagedInterface {
int PrintHi( string name );
}
[Guid( "C6659361-1625-4746-931C-36014B146679" )]
public class InterfaceImplementation : IManagedInterface {
public int PrintHi( string name ) {
MessageBox.Show( "Hello " + name );
return 33;
}
}
I'm trying to call a C# dll from c++. I followed an example from the
MSDN site, and I am able to get their example working, however, I
believe their example is a console application, as it takes in command
args.
I'd like to be able to do the same thing, but from a c++ dll. However,
when I port the same code over, it says it cannot create the instance
(from the CoCreateInstance).
The code is the same from the console app, so I'm not sure what the
problem is.
To be honest, I'm no c++ guy, so I'm stumped as to even choose an
avenue to try next. I'm hoping it's a build setting or something, but
I'm just not sure... Any help would be appreciated.
Thanks in advance
//////// c++ Snip:
-----------------------------------------------
IManagedInterface *cpi = NULL;
// Initialize COM and create an instance
// of the InterfaceImplementation class:
CoInitialize(NULL);
HRESULT hr = CoCreateInstance(CLSID_InterfaceImplementation,
NULL,
CLSCTX_INPROC_SERVER,
IID_IManagedInterface,
reinterpret_cast<void**>(&cpi));
// CoCreateInstance works great in the console app,
// but fails when called in the dll
if (FAILED(hr))
{
MessageBox(NULL, L"Couldn't create the instance! 0x%x\n", L"",
0);
}
cpi->PrintHi("team");
cpi->Release();
// Be a good citizen and clean up COM:
CoUninitialize();
/////C# interface server snip
-------------------------------------------------
[Guid( "DBE0E8C4-1C61-41f3-B6A4-4E2F353D3D05" )]
public interface IManagedInterface {
int PrintHi( string name );
}
[Guid( "C6659361-1625-4746-931C-36014B146679" )]
public class InterfaceImplementation : IManagedInterface {
public int PrintHi( string name ) {
MessageBox.Show( "Hello " + name );
return 33;
}
}