我有一个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();
当我超越我的编程时,我将activex附加到我的风中,但当我调用任何方法时,我收到此错误Unhandled exception at 0x752a812f in test1.exe: Microsoft C++ exception: _com_error at memory location 0x0012fdbc..
我知道我应该调用SetProperty方法或类似的东西,但我不知道如何
答案 0 :(得分:0)
由于您使用的是MFC,请使用COleControl
。 MFC的重点是提供课程,这样你就不必自己做所有事情。