Here is a quick example of how to access a VB ActiveX class from VC++. Com components are intended to be language independent so the code here can be used with any com component. There are a lot of issues regarding com but this should provide a good start.
Beowulf
vb Active X dll (vbcomtest.dll) with a class called Class1:
Class1 code:
Public Function afunc(ByVal val As Long) As Long
afunc = val * 2
End Function
Win32 console app:
// Example use of vb com components
// Beowulf
#include "stdafx.h"
#include <objbase.h>
//import the VB dll - This will provide wrappers which will be more intuative to a VB programer
#import "vbcomtest.dll" no_namespace, named_guids
int main(int argc, char* argv[])
{
//Initalise COM
HRESULT hr = CoInitialize(NULL);
if( FAILED( hr ) )
{
printf("Failed to CoInitialize\n"
}
//get a smart pointer
//The main interface is called _Class1 not
//IClass1 as is common practice - the "_" is to prevent the
//VB development enviroment from displaying default interface
_Class1Ptr ptrMyClass;
//Create instance of Class1 - note the CLSID_Class1
hr = ptrMyClass.CreateInstance(CLSID_Class1,NULL);
if( FAILED( hr ) )
{
printf("Failed to CreateInstance\n"
}
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.