Cocreateinstance() call

Hello
Am new to COM concept, please help me understand the 4 lines about COM jargon written in c++.
Sham
mohet01Asked:
Who is Participating?
 
sarabandeConnect With a Mentor Commented:
the IID_APP and CLS_ID_APP are so-called GUID a 128-bit unique identifier. if you copied the code from somewhere you need to create new ids (use menu tools - create guid) or the uniqueness would not be valid.

the CLSCTX_SERVER is a defined macro  what most likely 'or's' some other integer constants where only one bit is set. by or-ing you get a bitmask which has all three bits set.

the CoCreateInstance "creates a single uninitialized object of the class associated with a specified CLSID" what means that it creates a valid handle for your COM app if it succeeds.

Sara
0
 
mohet01Author Commented:
Hello
Below are the 4 lines:
1) const IID IID_APP  =
{0xC2024555,0x3570,0x11D4,
{0xA5,0xC7,0x00,0x50,0xDA,0x63,0xC0,0xDD}
};
sham
0
 
mohet01Author Commented:
2)
const CLSID CLSID_APP   =
{0xC2024556, 0X3570,0X11D4,
{ 0xA5, 0xC7,0x00,0x50,0xDA ,0x63,0xC0, 0XDD}
};
SHAM
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
mohet01Author Commented:
3)
#define CLSCTX_SERVER
(CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER | CLSCTX_REMOTE_SERVER)
4)
hr = CoCreateInstance(CLSID_APP,NULL,CLSCTX_SERVER,IID_APP,(void **) pIsevprop);
Note: pIsevprop is just a pointer to the interface which is not clear for me.
Sham


0
 
mohet01Author Commented:
Hello
I also see the error :
hr=-2147024882, sysmsg= not enough storage is available to complete this operation.

How do I approach this problem?

This code is running on windows 2003 machine

Sham
0
 
JimBeveridgeCommented:
COM is challenging to understand, but it allows applications in different languages to talk to each other successfully (C++, Delphi, Perl, Visual Basic, .Net - you name it, it supports COM.)

COM is made up of Classes and Interfaces. A single class can have one or many interfaces. Classes are identified by their (CLSID) and interfaces are identified by the interface ID (IID).

In C++, a class is an object that inherits from one or more abstract base classes classes where all of the virtual functions are set =0). Each of the abstract interfaces corresponds to one interface. (It doesn't have to be this way, that's just typical.)

In C++, you create an object with "new". Most developers don't distinguish between the object and its interface. With COM, you use CoCreateInstance instead of new. An object has no default interface, so the IID_APP parameter says you want to start with the interface for the APP.

The CLSCTX_SERVER definition tells COM that the object can live anywhere - in a DLL, in an EXE, or even on another computer that may or may not be running Windows.

Also see the Wikipedi article at http://en.wikipedia.org/wiki/Component_object_model. The part you want is under "Technical Details".

0
 
mohet01Author Commented:
Hello
1) As per my latest update, I also an error in this problem, what is the meaning of this erroR?
2) sara, creating guids using menu tools, I did not get this point.
3)what exactly are we doing with this 4 lines conceptually?

Sham
0
 
JimBeveridgeCommented:
1. This needs to be moved to a separate question. It's unrelated to your original questions.
2. Since you are working with existing code, Sara's comment was just "FYI" - it doesn't apply to what you are doing.
3. Conceptually you are creating a 128bit unique ID. Because it's 128 bits, you have to break it apart into pieces. You can't say (for example) 0x2cd823513259017af.
0
 
sarabandeCommented:
you can create new guids like

 {0xC2024555,0x3570,0x11D4, {0xA5,0xC7,0x00,0x50,0xDA,0x63,0xC0,0xDD}}

in Visual Studio. use menu Tools -> Create GUID.

new guids are needed if you make a new app or a new com dll  and have new instances therefore. if you want to connect to an existing com object you need to use the GUID of that object.

the line 1 and 2 are defining a const IID global variable for later use.

the line 3 defines a macro that includes all three of

CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER | CLSCTX_REMOTE_SERVER

where each defines a possible 'context' as argument for CoCreateInstance. See help of CoCreateInstance.

the line 4 instantiates a new com object and returns a handle for further use.

The CoCreateInstance helper function provides a convenient shortcut by connecting to the class object associated with the specified CLSID, creating an uninitialized instance, and releasing the class object. As such, it encapsulates the following functionality:

CoGetClassObject(rclsid, dwClsContext, NULL, IID_IClassFactory, &pCF);
hresult = pCF->CreateInstance(pUnkOuter, riid, ppvObj)
pCF->Release();

Sara


0
 
mohet01Author Commented:
Hello
with respect to your point about new objects, CLSID_APP corresponds to which object and IID_APP corresponds to which object?
Sham
 
0
 
mohet01Author Commented:
Thank you
0
 
sarabandeCommented:
CLSID_APP is key to the COM class of the application in registry.

IID_APP is an application specific identifier which might be used in the interface provided by the class.

Sara

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.