Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 431
  • Last Modified:

VB COM Server & VC COM Client !!!

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
dineth
Asked:
dineth
1 Solution
 
Roshan DavisCommented:
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
 
peterdownesCommented:
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
 
ekcCommented:
> 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
 
ekcCommented:
> 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
 
dinethAuthor Commented:
Thank's alot guys !!!
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now