Solved

VB COM Server & VC COM Client !!!

Posted on 2002-03-04
5
412 Views
Last Modified: 2013-11-25
Hello Experts !!!

I have created a VisualBasic DLL and want to use it VC++. When using CoCreateInstance() to instantiate the VB DLL how can I pass the REFFID of the Interface which I want to get a pointer to.

Or are VB Dll's not supportive when using VC++ as COM Clients ??

ThankX !!
--Din--
0
Comment
Question by:dineth
5 Comments
 
LVL 23

Accepted Solution

by:
Roshan Davis earned 100 total points
Comment Utility
I Answered this Q. previously
As this

1) Create an ActiveX dll in VB. When you create the dll,
     VB will add a class to it by default - Class1.
2) Add your function to it. Make the function public.
3) Click on View->Project Explorer if Project Explorer is not already open. In Class Modules, you will see Class1.
4) Right click on it. A menu pops up. Select Properties. Change the name to whatever you want. 5) From combo box next to instancing, select Global Multiuse.
6) Make the dll and register it.
7) Open your MFC exe project. Click on View->Class Wizard.
8) Click on Add Class->from a type library. A dialog box will open. From this select the VB dll. 9) In the class name text box, you will find the name of the
class. You will notice that it starts from underscore. Replace this underscore by letter I (it is not
necessary but looks better).
10) Click on Ok. Again, click on OK.

Use the class as follows:
Assume that the name of ActiveX dll project is MyProject and the name of the class is MyClass. Assume
that the name of the method is f.

IMyClass obj;
obj.CreateDispatch("MyProject.MyClass");

obj.f(pass the parameters if any);

Once you have finished using obj, write:
obj.ReleaseDispatch();

You will have to include the file "MyProject.h"

GOOD LUCK
0
 
LVL 6

Expert Comment

by:peterdownes
Comment Utility
Have you considered using #import from your C++ program.

E.g.,

#import "MyVBDll.dll" no_namespace

This will create a ".tli", ".tlh" file for you which wraps your COM class.

Instantiating your object can be as simple as:

IMyVBDllPtr p(__uuidof(MyVBDll));

Regards.
0
 
LVL 5

Expert Comment

by:ekc
Comment Utility
> roshmon  - 7) Open your MFC exe project. Click on View->Class Wizard.
8) Click on Add Class->from a type library. A dialog box will open. From this select the VB dll. 9)

> peterdownes - Have you considered using #import from your C++ program.

Those are the two options in reusing the COM object from the VC++.
I don't think dineth needs to actually think about this choice, since it is higly dependent on the platform he already use.
dineth, if you are using MFC to develop you client VC++ app, the roshmon's answer is excactly what you need. It is based on the MFC's COleDispatchDriver class, and you are invited to do some further reading on the subject.
If you, on the contrary are using ATL or neighter of those two class libraries, the peterdownes's solution is what you need. In this case, the IDE will generate some CComPtr derived classes wrapping your COM object.
0
 
LVL 5

Expert Comment

by:ekc
Comment Utility
> When using CoCreateInstance() to instantiate
the VB DLL how can I pass the REFFID of the Interface which I want to get a pointer to.

If you finnaly decide to use lowest level aproach and this function, a straightforward way is:

1. Open the OleView utility (from the Tools menu from VC++ IDE, or menu Programs) and in its section "Type Libraries" find excact name of your COM object ("library_name.coclass_name").
2. Use the CLSIDFromProgID() to get clsid from its name.
3. Call the CoCreateInstance(), passing it the clsid.
0
 

Author Comment

by:dineth
Comment Utility
Thank's alot guys !!!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

772 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now