c++comgoogletestatl

Test COM DLL without exporting methods explicitly


I created an ATL COM DLL. I now have to unit test the methods defined in the COM interface of the DLL. I created a console application "tester.exe" and wrote some google tests, which would talk to the COM DLL and its method. Problem is, the tester.exe only compiles if I explicitly export the COM method like:

__declspec(dllexport) STDMETHOD(Add)(DOUBLE Input1, DOUBLE Input2, DOUBLE* pOutput);

I want to test the COM interface directly and not rely on a DLL export. Is there any way my tester/com client can compile and run the dll without needing the dllexport, such that the method definition stays:

STDMETHOD(Add)(DOUBLE Input1, DOUBLE Input2, DOUBLE* pOutput);

Am I missing something very obvious? I tried looking at many resources and tutorials but none were very helpful.


Solution

  • I was able to resolve this issue by directly setting the CLSID and IDD in the test class:

    const CLSID CLSID_CTest = { 0x809a77g7,0x2624,0x453e,{0xb3,0xc6,0x2c,0x68,0x15,0xff,0xe3,0x23} };
    const IID IID_ICTest = { 0x0c832b41,0xbfe9,0x4a16,{0xb9,0x34,0xff,0x7f,0x8b,0x77,0x30,0x44} };
    

    and then using these to create a CoCreateInstance

    hr = CoCreateInstance(CLSID_CTest , NULL, CLSCTX_INPROC_SERVER, IID_ICTest , (LPVOID*)&ptrICTest);
    

    With this, I neither need the lib of the COM server when compiling, nor any header.