Solved

VB COM Server & VC COM Client !!!

Posted on 2002-03-04
5
413 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
ID: 6840892
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
ID: 6840955
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
ID: 6841364
> 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
ID: 6841396
> 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
ID: 6843307
Thank's alot guys !!!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
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…

912 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

17 Experts available now in Live!

Get 1:1 Help Now