0

I want to connect to a running object using COM. I have this code.

  CLSID clsid;
  CLSIDFromProgID(L"CSI.ETABS.API.ETABSObject", &clsid);

  // get the active ETABS object
  CComPtr<IUnknown> pUnk;
  auto hRes = GetActiveObject(clsid, NULL, (IUnknown**)&pUnk);
  if(!CheckHRESULT(hRes, L"Cannot get active ETABSObject!")) return (hRes);
  hRes = pUnk->QueryInterface(__uuidof(ETABSv17::cOAPI), (void **) &pETABSObject);
  if(!CheckHRESULT(hRes, L"Cannot attach to ETABSObject!")) return (hRes);

However the compiler complains that no GUID is assocaited with ETABS:cOAPI. How to resolve this issue ?

exact error message is: can not call operator __uuidof on object with no guid.

Ring Zero.
  • 459
  • 3
  • 12
  • To use __uuidof you need to import the typelibrary for the object first, and this typelibrary needs to be registered. – Pepijn Kramer Dec 27 '21 at 11:26
  • I have used the dumpcpp tool to get the .h and .cpp files (tool comes with qtcreator) dumpcpp etabsv17.tlb produces the header and definitions. – Ring Zero. Dec 27 '21 at 11:28
  • Do you use MSVC? If so try the #import statement with raw_interfaces_only this will also get the __uuidof to work. It will generate a tlh file with the uuid's in it. https://learn.microsoft.com/en-us/cpp/preprocessor/hash-import-directive-cpp?view=msvc-170 – Pepijn Kramer Dec 27 '21 at 11:33
  • I am using qtcreator and clang it seems does not support import statement. Though my compiler is visual c++19. – Ring Zero. Dec 27 '21 at 11:47
  • qtcreator (libclang) complains that import of type library is an unsupported feature. any other way to give guid of the class manually ? – Ring Zero. Dec 27 '21 at 11:54
  • Can you find any guids (constants) in the generated header file? And use that instead of __uuidof? – Pepijn Kramer Dec 27 '21 at 12:30
  • No, but I have the GUID of the dll from the registry. – Ring Zero. Dec 27 '21 at 12:33
  • I used this approach as well: using activeqt wrapping cOAPI* etabs = new cOAPI(); etabs->setControl("{C5430F44-B761-463E-9E5B-477C64AC0CFA}"); etabs->setObjectName(QString("ETABSv17.Helper")); etabs->ApplicationStart(); but I get id < 0 assertion error at runtime. something is missing. – Ring Zero. Dec 27 '21 at 12:34
  • If you know the GUID's value and if cannot be found anywhere, just declare it "manually". With MSVC, the manual definition would be something like this: `static GUID MyGuid = { 0x5f41de3d,0x8e80,0x41f1,{0xae,0x92,0xc3,0xf9,0x41,0x63,0x51,0xde} };` for this guid: `5F41DE3D-8E80-41F1-AE92-C3F9416351DE` – Simon Mourier Dec 27 '21 at 17:18

0 Answers0