There are 2 ways of importing an ActiveX control into a Visual C++ MFC application: 1) By allowing the Class Wizard to generate wrapper classes for each one of the components contained inside the ActiveX. This is done automatically when you assign a member variable to the object. 2) By using the #import directive as follows: In your precompiled header (STDAFX.H) // DEFINITION of COM wrappers #import "sfxbar.dll" no_namespace no_implementation #import "Cfx4032.ocx" no_namespace no_implementation In your implementation (STDAFX.CPP) // IMPLEMENTATION of COM wrappers #import "sfxbar.dll" no_namespace implementation_only #import "Cfx4032.ocx" no_namespace implementation_only
VC6吗?Project->Add To Project->Components and Controls 楼上讲的也行,不过添加到窗体上时要自己写相应的代码,不能使用拖拽的方式
CoInitialize(NULL); short st = 2; short st1; // Declare the Interface Pointer for your Visual Basic object. Here, // _Class1Ptr is the Smart pointer wrapper class representing the // default interface of the Visual Basic object.
_Class1Ptr ptr; // Create an instance of your Visual Basic object, here // __uuidof(Class1) gets the CLSID of your Visual Basic object.
// DEFINITION of COM wrappers
#import "sfxbar.dll" no_namespace no_implementation
#import "Cfx4032.ocx" no_namespace no_implementation
In your implementation (STDAFX.CPP)
// IMPLEMENTATION of COM wrappers
#import "sfxbar.dll" no_namespace implementation_only
#import "Cfx4032.ocx" no_namespace implementation_only
楼上讲的也行,不过添加到窗体上时要自己写相应的代码,不能使用拖拽的方式
short st = 2;
short st1;
// Declare the Interface Pointer for your Visual Basic object. Here,
// _Class1Ptr is the Smart pointer wrapper class representing the
// default interface of the Visual Basic object.
_Class1Ptr ptr;
// Create an instance of your Visual Basic object, here
// __uuidof(Class1) gets the CLSID of your Visual Basic object.
ptr.CreateInstance(__uuidof(Class1));
st1 = ptr->MyVBFunction(&st);
}
catch(_com_error &e)
{
bstrDesc = e.Description();
}
CoUninitialize();