Solved

Cocreateinstance() call

Posted on 2011-02-24
12
676 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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 33

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
 

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 33

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 33

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Better understanding on C++ Class serialization and formats 9 78
Sed question 2 100
What is MicroStrategy.NET? 2 70
Installshield for Embarcadero EX 10.1 Berlin 4 60
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

839 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