Solved

VB COM Server & VC COM Client !!!

Posted on 2002-03-04
5
416 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Get MongoDB database support online, now!

At Percona’s web store you can order your MongoDB database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card. Handle your MongoDB database support now!

Question has a verified solution.

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

After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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…

630 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