
Using a VB Active X DLL's functions in C++
Quote:
> I've created an ActiveX DLL in VB and would like to load it into a VC++
> project. I've never done this before, so I am mightily confused.
> If I had a class called, TestClass, say, with one function:
> Option Explicit
> Public Sub PutMessageBox()
> MsgBox "Hello World!"
> End Sub
> What would the code look like to load the DLL (LoadLibrary?) in VC++ and run
> the PutMessageBox method?
In a header (typically, stdafx.h)
// I used no_namespace to simplify my example code, but you may
// wish to omit this directive and add namespace qualifiers to
// the identifiers from the library.
#import "yourvbdll.dll" no_namespace
(Note that if you use something like Collection, you may also need to
#import the VB runtime.)
In your code,
// Rough VB equivalent code in comments
// Dim pTest As TestClass
// Set pTest = New TestClass
_TestClassPtr pTest(__uuidof(TestClass));
// pTest.PutMessageBox
pTest->PutMessageBox();
--
Craig Powers
MVP - Visual C++