calling c# dll from c++ dll

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;
}
}
 
V

Victor Bazarov

Capsule said:
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.[...]

C#, dll, are both off-topic here. C++ does not have 'dll', it is
a feature of your operating system. There are newsgroups dealing with
your operating system. Post there. Alternatively, if you're using
a compiler capable of creating system-specific results, post to a forum
dedicated to your compiler.

V
 

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

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top