Solved

Cocreateinstance() call

Posted on 2011-02-24
12
667 Views
Last Modified: 2013-12-04
Hello
Am new to COM concept, please help me understand the 4 lines about COM jargon written in c++.
Sham
0
Comment
Question by:mohet01
  • 7
  • 3
  • 2
12 Comments
 

Author Comment

by:mohet01
ID: 34970153
Hello
Below are the 4 lines:
1) const IID IID_APP  =
{0xC2024555,0x3570,0x11D4,
{0xA5,0xC7,0x00,0x50,0xDA,0x63,0xC0,0xDD}
};
sham
0
 

Author Comment

by:mohet01
ID: 34970193
2)
const CLSID CLSID_APP   =
{0xC2024556, 0X3570,0X11D4,
{ 0xA5, 0xC7,0x00,0x50,0xDA ,0x63,0xC0, 0XDD}
};
SHAM
0
 

Author Comment

by:mohet01
ID: 34970272
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
 

Author Comment

by:mohet01
ID: 34970316
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
 
LVL 32

Accepted Solution

by:
sarabande earned 250 total points
ID: 34970526
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
 
LVL 7

Expert Comment

by:JimBeveridge
ID: 34971586
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

Author Comment

by:mohet01
ID: 34971942
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
 
LVL 7

Expert Comment

by:JimBeveridge
ID: 34972569
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
 
LVL 32

Expert Comment

by:sarabande
ID: 34973123
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
 

Author Comment

by:mohet01
ID: 34985352
Hello
with respect to your point about new objects, CLSID_APP corresponds to which object and IID_APP corresponds to which object?
Sham
 
0
 

Author Closing Comment

by:mohet01
ID: 36152272
Thank you
0
 
LVL 32

Expert Comment

by:sarabande
ID: 36164885
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

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
only14 challenge 19 64
Annoying "thing" blocks my view 4 54
Problem to event 3 52
Path to  STL Map header file 1 29
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…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
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…

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now