I successfully exported the following C# class and its method to COM.
namespace SRCSN
{
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
public interface _SRCSAux
{
void DisplayDLLInfo();
}
[ClassInterface(ClassInterfaceType.None)]
public class SRCSAux : _SRCSAux
{
public SRCSAux()
{
}
public void DisplayDLLInfo()
{
MessageBox.Show("Hello World!");
}
}
}
Everything works fine when I call DisplayDLLInfo()
from an unmanaged MFC application as follows.
#import "C:\...\bin\Debug\SRCSN.tlb"
using namespace SRCSN;
SRCSN::_SRCSAuxPtr com_ptr;
CoInitialize(NULL);
SRCSN::_SRCSAuxPtr p(__uuidof(SRCSN::SRCSAux)); // OK
com_ptr = p;
com_ptr->DisplayDLLInfo();
// OK
However, exactly the same code throws an exception when executed
within an exported function in an unmanaged C++ DLL.
#define DLLExport extern "C" _declspec(dllexport)
#import "C:\...\bin\Debug\SRCSN.tlb"
using namespace SRCSN;
DLLExport BOOL Func()
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
SRCSN::_SRCSAuxPtr com_ptr;
CoInitialize(NULL);
SRCSN::_SRCSAuxPtr p(__uuidof(SRCSN::SRCSAux)); // EXCEPTION :-(
com_ptr = p;
com_ptr->DisplayDLLInfo();
}
What's the problem with SRCSN::_SRCSAuxPtr p(__uuidof(SRCSN::SRCSAux)) ?
Any help would be greatly appreciated.
TIA,
-Alex
Alexander Paar - 09 Sep 2003 10:05 GMT
I nailed down the problem a little bit more.
I can call the CCW from an unmanaged MFC application and from an unmanaged
C++ DLL (using MFC) if and only if this DLL has been called from the
unmanaged MFC application. Does it matter _who_ called the unmanaged DLL
that employs my CCW?
-Alex
> I successfully exported the following C# class and its method to COM.
>
[quoted text clipped - 57 lines]
> TIA,
> -Alex