?
Solved

COMPONENT.dll

Posted on 1999-11-24
8
Medium Priority
?
216 Views
Last Modified: 2010-04-01
Ok!
I have a someComponent.dll, that someone else have written in VB.
This component have a function I want to use.
I have registered the .dll, I can see the object in the object-viewer, I have an CLSID, I can call CoGetClassObject
successfully, now:
HOW THE HECK do I get the "IsomeComponent" interface....??
the next thing I need to do is calling
CreateInstance and send in a pointer to a IsomeComponent-class. Where do I get this class from??
I'm reading about importing .tbl-files,
including .h-files etc, but WHERE do they come from?? All I have is a .dll file and a classID.....
I'm not using MFC

THANKS!!
(I would put some more points there if I had some!)
0
Comment
Question by:Scattan
  • 4
  • 4
8 Comments
 

Author Comment

by:Scattan
ID: 2231280
Edited text of question.
0
 
LVL 32

Accepted Solution

by:
jhance earned 150 total points
ID: 2231401
1) Use CoCreateInstance like this:

CoCreateInstance(myClsid, NULL, CLSCTX_ALL, IID_IUnknown,  (LPVOID *)&pUnk)

This fills in the pUnk with a pointer to the IUnknown interface on the component.

2) Now use QueryInterface on IUnknown to get the interface you want:

pUnk->QueryInterface(IID_IDispatch, (LPVOID *)&pDisp)

In my case, I want the IDispatch interface but you can lookup whatever you you want.

3) Once you have the interface you want, then you can call its methods.

0
 

Author Comment

by:Scattan
ID: 2231584
Thanks, but what would the interface I want be in this case? It would probably be called IsomeComponent instead of IDispatch, I guess, but that interface isn't defined anywhere....

So what should be instead of the ???
 
pUnk->QueryInterface(IID_IDispatch, (LPVOID *)&???)

???->MyObjectFunction()?

Thank you!
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
LVL 32

Expert Comment

by:jhance
ID: 2231737
I can't say what interface you want.  IUnknown is the ONLY interface a COM object is required to have.  All the rest are up to the designer of the object.  For an VB Control (a.k.a ActiveX) the IDispatch must also be present.  This is how VB and other tools can determine what interfaces, methods, and properties are available on the object at design time without having any information except for the object itself.  In C++, however, calling the methods on the different interfaces is more efficient that using IDispatch because of the greater overhead involved with it.

If you've looked at the object in the OLE Viewer, you should have an idea of what's available.
0
 

Author Comment

by:Scattan
ID: 2231821
In the OLE Viewer, I can see the name of the interface. The problem is, where do I get the .h-file that defines the interface from?
If I had made the component myself, I would have an .h-file and _c -file etc,
and I could include this .h-file in my new project to define the interface.
But now, when I only have a .dll, my project doesnt now about this interface
, even though it's seen in object viewer.
Or is there a shared .h-filed where all registered components interface-definitions are saved?

Thanks for answering anyway.
0
 
LVL 32

Expert Comment

by:jhance
ID: 2231911
You should get the .h file from the company that developed the component.  If you can't get it you should be able to glean enough information from the OLE Viewer to build one yourself. In fact, if you are using VC++ 6, the ATL Wizard will create an interface to such an object for you automagically.

If all else fails, this component should have an IDispatch if it was for use with VB.  This is fundamental to the way VB controls work.
0
 

Author Comment

by:Scattan
ID: 2233678
The ATL Wizard creates an wrapperclass
derived from IDispatchDriver, which is
impossible to use since I'm not using MFC.
I don't think VB-components have .h-files, do they??
Yes I can get an IDispatch pointer to this object, but the dispatch pointer does not know about the function "MyObjectFunction()"

I still don't quite get it, but since you have helped me so much, I think you should have the points anyway.

Thanks!
0
 
LVL 32

Expert Comment

by:jhance
ID: 2233953
That's a drawback to not using MFC, you lose out on some work saving features in VC++.  Again, you can certainly build a .h file from the typelib information that is reported by OLE Viewer.  In fact, this is exactly what the ATL Wizard does programmatically.  The information is all there, you just need to sift through it and build a header file if you need one.

It wouldn't surprize me if someone has built a tool to generate a header file from a component already.  You might check out some of the COM/ActiveX web sites and look through the files available.  Heck, VC++ might even include one but the extra utilities that are included are so poorly documented you'd never know if it was there.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

607 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