[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

CoGetClassObject API

Posted on 1997-12-30
7
Medium Priority
?
541 Views
Last Modified: 2013-12-03
The 1,4 parameters are difficult.
In order to use this API, it is required to provide
the CLSID in the first variable (in REFCLSID type).

The question is: How can I receive this parameter ?
0
Comment
Question by:gilad111397
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 7

Accepted Solution

by:
galkin earned 600 total points
ID: 1409714
coGetClassObject is usually used to create class factory, small object intended to create desired object itself. This function as oppose to CoCreateInstance allows you to create IClassFactory(2) interface only once store its pointer somewhere and then use IClassFactory::CreateInstance to create object. It means you avoid creating class factory each time, as it happens to CoCreateInstance. This function should be used if you need create a lot of objects or you need to create then very often.
The first parameter is CLSID of the object server. It is unique in time and space identifier. To be used this server must be register in OLE register data base, i.e. it must create several keys to be identified by OLE. The most important key is key representing server CLSID and it must be created under HKEY_CLASSES_ROOT/CLSID. Look at this key and you will find a lot CLSIDs. This key in turn contains several key, but only one is reqired, namely InProcServer(32) if the server is DLL and LocalServer(32) if it is exe. This Key has default value, full path to server file. So if you know server file you can serach in registry for its CLSID. In coGetClassObject you usually use IID_IClassFactory(2) as 4 parameter since I this function is usually intended to create class factory. When obtaining pointer to class factory via 5 parameter in GoGetClassObject you cann use IClassFactory::CreateInstance passing UUID of interface quired as first parameter and reference to interface as second.  
 
0
 

Author Comment

by:gilad111397
ID: 1409715
Thank you for answering my question.
I am sorry I wasn't very specific, so I'll ask again:

(not only in this API) how can the compiler know my interface
name when I want to receive it and not IID_IUnknown ?


0
 
LVL 7

Expert Comment

by:galkin
ID: 1409716
Each interface is identified by global unique identifier which is 128 bit number and is garanteed to be unique in space in time. This number can be generated using rather complicated mechanism, involving current time, network card and so on. OLE provides uuidgen.exe utility for generating this number. VC++ also provides visual tool called GUIDGEN.exe found in VC/bin derectory. When client asks server to create object and return reference to specific interface it passes IID_IYourInterface either to CoCreateInstance or IClassFactory::CreateInstance. This number is global unique indentifier of the requested interface. So client must know this interface number as well as interface structure to be able to ask server to return it. Besides if you want to marshal your interface acroll tread or process boundaries you must write specific piece of code called marshaller to pass interface reference across these boundaries and you must register your marshaler under HKEY_CLASSES_ROOT/Interface/<UUID of your interface> key. Server when being asked to create object and return reference to specific interface intentified by UUID checks this number and because it is unique create object of specified type or return error indicating it is unable to create object with requested UUID.
0
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

 

Author Comment

by:gilad111397
ID: 1409717
Thanks again.

one last clarification: am I suppose to write the UUID as
a number or by the name ?
If it is name, how will the compiler know this name ?
If it is UUID, how can I define it in a variable ?

0
 
LVL 7

Expert Comment

by:galkin
ID: 1409718
This number is stored as structure of fore members since it is very large 128 bit number. You should use special macro DEFINE_GUID() which takes several parameters and creates necessary structure. If you use GUIDGEN.exe it allows you to generate this UUID and put necessary string containing DEFINE_GUID() to the clipboard so what you need to do then is to paste it into your source code where you need.
0
 

Author Comment

by:gilad111397
ID: 1409719
Hello Galkin,

how can I pull it if I didn't create it, e.g if it is
exist.
I need it for QueryInterface function. the interface name is
required in this function and I can't simply write it because
the compiler doesn't recognize it.
The function :
HRESULT QueryInterface(
  REFIID iid,
  void ** ppvObject
  );
and iid is my problem.


0
 
LVL 7

Expert Comment

by:galkin
ID: 1409720
I see you don't distinguish between CLSID and interface ID. Inspite of the fact they are both 128 bit number unque in space and time they play diffrent role in OLE. CLSID is class ID and is intended to help OLE to locate server. This is its only purpose. Each server be out of proc(exe) or in proc(DLL) must have this unique numbe and create corresponding key under HKEY_CLASSES_ROOT/CLSID. This key may contain several subkeys but only one is requried is InprocServer(32) if it is DLL or LocalServer(32) if it is EXE which has only one string entry(default) full path to server file. When client wants to create a object it calls OLE helper API CoCreateInstance or CoGetClassObject passing CLSID of the objects server. Client doesn't know where the server resides. It can be in the same computer, on corporate network or even on the Internet. It is InprocServer(32) key by which OLE locates server and loads it in memory if it is DLL or launches it if it is EXE. This feature is called local/remote transparency and is one of the main advantages of OLE/COM. But to retreive reference to specific interface client must somehow identify this interface and interface ID is important. Each interface msut have this unique identifier which is generated by the same mechanism I already described. When client asks server for specific interface it uses IUnknown::QueryInterface which has two parameters. The first is this interface unique identifier and the second is indirect reference to the quired interface returned. So you must know ID of interface you want to quire for. All OLE stundard interfaces(IUnknown, IDispatch, IAdviseSing etc.) already have their unique IDs and they are defined in OLE standard include files and exported from OLE standard DLL(OLe32.DLL, OLEAUT32.DLL etc.). They are defined as IID_IUnknown for IUnknown, IID_IDispatch for IDispatch, IID_IViewObject for IViewObject and so on. If you define your own custom interface you must generate its unique ID by the tools I told you and define it in the same file when interface declaration is defined so client can look at it and can create object retreiving this interface reference.
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question