Click here to Skip to main content
15,892,161 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
From my knowledge, this should work:::

ITypeLib Viewer output:
library MyServerLib
{
    // TLib : OLE Automation : {00020430-0000-0000-C000-000000000046}
    importlib("stdole2.tlb");

    // Forward declare all types defined in this typelib
    interface IOPCServer;
    interface IOPCBrowseServerAddressSpace;
    ...
    [
      uuid(E31E5782-636C-11D2-B326-0000A0080AC8),
      helpstring("OPC Server Class")
    ]
    coclass OPCServer {
        [default] interface IOPCServer;
        interface IOPCBrowseServerAddressSpace;
    };

    [
      odl,
      uuid(39C13A4D-011E-11D0-9675-0020AFD8ADB3)
    ]
    interface IOPCServer : IUnknown {
        HRESULT _stdcall AddGroup(.....
    };
	...
	
    [
      odl,
      uuid(39C13A4F-011E-11D0-9675-0020AFD8ADB3)
    ]
    interface IOPCBrowseServerAddressSpace : IUnknown {
        HRESULT _stdcall QueryOrganization([out] tagOPCNAMESPACETYPE* pNameSpaceType);
     ....
    };
    ....
};


C++ code::>
const CLSID CLSID_OPCServer = {0xE31E5782,0x636C,0x11D2,{0xB3,0x26,0x00,0x00,0xA0,0x08,0x0A,0xC8}};
	const IID IID_IOPCBrowseServerAddressSpace = { 0x39c13a4f,0x011e,0x11d0,{ 0x96,0x75,0x00,0x20,0xaf,0xd8,0xad,0xb3 } };

	 hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
	 hr = CoCreateInstance( CLSID_OPCServer, NULL, CLSCTX_SERVER, 
											IID_IUnknown, (void **) &(p2sPtrs->pServer) );
	// this was successful and got a pServer pointer
	
	hr = p2sPtrs->pServer->QueryInterface(IID_IOPCBrowseServerAddressSpace, (void **)&m_spBrowse);
	// this fails with 'No such interface supported.'


How do I determine what the issue is?
Everything looks correct to me.
Is there a step missing?

What I have tried:

Tried initializing
COINIT_APARTMENTTHREADED
with no difference.
Posted
Updated 28-May-18 20:29pm

1 solution

Your only chance is to try it out and check each return value of each called functions (hr code) which may be an error. The first error breakes wins!!! Google for the meaning of that hex value.

Common issues are that the classes are not or not fully registered. Compare the uuids and re-register as admin.

COM works, most times it is some really stupid bug. ;-)
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900