Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Cocreateinstance() call

Posted on 2011-02-24
12
Medium Priority
?
696 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
[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
  • 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
Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

 

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 35

Accepted Solution

by:
sarabande earned 1000 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
 

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 35

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 35

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

618 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