调用activex方法
call activex methods
我有一个ocx文件,我想在win32应用程序中使用它,所以我从change USE of MFC
到USE MFC in a Static Library
,然后这样进行:
#import "C:\Program Files\GeoSDK\LiveX_8300.ocx"
int CALLBACK WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// Register our Window class
WNDCLASS wndclass;
wndclass.style = CS_VREDRAW | CS_HREDRAW;
wndclass.lpfnWndProc = &WindowProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = NULL;
wndclass.hCursor = NULL;
wndclass.hbrBackground = reinterpret_cast <HBRUSH> (COLOR_BTNFACE + 1);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName =windowClassName;
::RegisterClass(&wndclass);
// Create our main, raw win32 API window
// We create the window invisible (meaning that we do not provide WS_VISIBLE as the window style parameter), because making it visible and then
// adding a HwndSource will make it flicker.
HWND mainWindow = ::CreateWindow(
windowClassName,
windowTitle,
0,
CW_USEDEFAULT,
CW_USEDEFAULT,
windowWidth,
windowHeight,
NULL,
NULL,
hInstance,
0);
::ShowWindow (mainWindow, nCmdShow);
::UpdateWindow( mainWindow );
//ocx
//_DLiveX p;
typedef HRESULT (WINAPI *PFonc)(IUnknown*, HWND,IUnknown**);
HINSTANCE hDLL2 = ::LoadLibrary(TEXT("atl.dll"));
if (!hDLL2)
return 1;
PFonc AtlAxAttachControl = (PFonc) ::GetProcAddress(hDLL2,"AtlAxAttachControl");
CLSID clsid = GetClsid();
IID DIID__DLiveX = GetDIID__DLiveX();
RECT rect;
::GetClientRect(mainWindow,&rect);
container = ::CreateWindowEx(WS_EX_CLIENTEDGE, "EDIT","",WS_CHILD | WS_VISIBLE,100,100,rect.right,rect.bottom,mainWindow,0,hInstance,0);
AtlAxWinInit();
HRESULT hr = ::CoInitialize(NULL);
LIVEXLib::_DLiveX *p;
hr = CoCreateInstance(clsid,
0,
CLSCTX_ALL,
DIID__DLiveX,
reinterpret_cast<void**>(&p)) ;
if(FAILED(AtlAxAttachControl((IUnknown*)p, container, 0))){
p->Release();
return -1;
MessageBox(HWND_DESKTOP, "FAILED(AtlAxAttachControl(pitd, container, NULL))", "Error", MB_ICONERROR | MB_OK);
}
while(hr == S_OK)
p->CreateX();
当我出色地完成我的程序时,我得到了连接到wind的activex,但当我调用任何方法时,我都得到了这个错误Unhandled exception at 0x752a812f in test1.exe: Microsoft C++ exception: _com_error at memory location 0x0012fdbc..
我知道我应该调用SetProperty方法或类似的方法,但我不知道是如何
由于使用MFC,请使用COleControl
。MFC的全部目的是提供类,这样您就不必自己做所有事情。
相关文章:
- 为不同配置设置MSVC_RUNTIME_LIBRARY的正确方法是什么
- 通过方法访问结构
- 最小硬币更换问题(自上而下方法)
- C++为构建时间获取QDateTime的可靠方法
- 在C#中处理C++指针而不使用unsafe的最佳方法
- 处理多个异常集合的C++方法
- 如果C++类在类方法中具有动态分配,但没有构造函数/析构函数或任何非静态成员,那么它仍然是POD类型吗
- 有什么方法可以遍历结构吗
- 当类在C++中定义时,有什么方法可以"register"类吗?
- 在C++中,将大的无符号浮点数四舍五入为整数的最佳方法是什么
- 实现无开销push_back的最佳方法是什么
- 使用std::函数映射对象方法
- 有符号的int和int-有没有一种方法可以在C++中区分它们
- C++从另一个类访问公共静态向量的正确方法是什么
- C++优先级队列,按对象的唯一指针的特定方法升序排列
- 在没有包装程序类的情况下,在ActiveX接口上调用方法
- 创建一个仅提供通过javascript调用的函数的ActiveX控件.最好的方法
- 向activex dll (axvlc.dll)添加外部可访问的方法
- 如何确保ActiveX类中的方法进入DLL(ITypeLib检查)
- 调用activex方法