Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with some COM questions

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I am attempting to do some COM stuff, but I don't really know where to start. We are using a "pre-packaged" COM .dll that has functions and stuff in it. I'm not quite sure how to initialize a COM object. Do I need to use #import in my VC++ program if the .dll file has already been registered? I saw somewhere in VC++ where I could take a .dll and export it, or the functions, to a .h file of some sort. But I couldn't get it to work properly. Any and all help would be GREATLY appreciated. n Thanks in advance!

Niky Williams
NTS Marketing
 
Dear Niky,

You are on the right track. A complete discussion of #import it's options and type libraries and DLL's are quite lengthy. You can find much information and sample/example code at msdn.microsoft.com on this topic.

Good luck
-pete
 
Here is a chunk of code that I use to import a "pre-packaged" COM .DLL, and we use both properties and methods of the COM object. The #import causes two files (.tlh and .tlb) to be created and used -- the .tlh is similar to a header file and it defines the properties and methods available to you.

#import "newstuff.dll" no_namespace
/***********************************************/
/* we have now defined a class called NewStuff */
/***********************************************/

...

CoInitialize(NULL);
GUID TempG = __uuidof(NewStuff);
HRESULT hr = ptr.CreateInstance(TempG,NULL,CLSCTX_LOCAL_SERVER);
if (FAILED(hr))
CoUninitialize();
else
ptr->Initialize(); // call the object's initialization method

Hope that helps!!

Pat Gleason
gleason@megsinet.net

 
Well, that does help a lot, however, the HRESULT keeps coming back as failed. This is what I have so far.

IEICConnectionPtr Conn=NULL;

HRESULT hr = Conn.CreateInstance(_uuidof(IEICConnection));

if (FAILED(hr))
CoUninitialize();
else
{
//initialize here
}

I step through it and every time, hr fails. The .tlh file has a bunch of smart pointer declaration that I am using. And I think I am doing it right. Any other suggestions? Thanks in advance for all your help!

Niky Williams
NTS Marketing
 
DOH...Found my problem. I was missing an '_' in my _uuidof...Hate it when that happens...thank you to everyone who has helped me!

Niky Williams
NTS Marketing
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top