COMPONENT.dll

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!)
ScattanAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ScattanAuthor Commented:
Edited text of question.
0
jhanceCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ScattanAuthor Commented:
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
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

jhanceCommented:
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
ScattanAuthor Commented:
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
jhanceCommented:
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
ScattanAuthor Commented:
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
jhanceCommented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.