0

我有一个 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();

当我执行我的 prog 时,我将 activex 附加到我的风中,但是当我调用任何方法时,我得到了这个错误Unhandled exception at 0x752a812f in test1.exe: Microsoft C++ exception: _com_error at memory location 0x0012fdbc.. ,我知道我应该调用 SetProperty 方法或类似的方法,但我不知道如何

4

1 回答 1

0

由于您使用的是 MFC,因此请使用COleControl. MFC 的全部意义在于提供类,这样您就不必自己做所有事情。

于 2013-02-11T13:27:02.627 回答