OLE Linker problem



  • Hello,

    i have a class that implements the QWinHost, so that i could use the win32 API and perform drag and drop with OLE.

    I have included the
    @#include <ole2.h>
    #include <shlobj.h>@ in my Droptarget class.

    But i get a problem tryint to initilize the OLE
    @void initOle(HWND parent){
    // initialize the OLE library
    OleInitialize(NULL);

        lpDropTarget = (LPDROPTARGET)new TDropTarget(parent);
        CoLockObjectExternal(lpDropTarget, true, true);
    
        // register the Handle to this Widget as a drop target
        RegisterDragDrop(parent, lpDropTarget);
    
    }@
    

    Error Message
    @
    hostwindow.obj:-1: Fehler: LNK2019: Verweis auf nicht aufgelöstes externes Symbol "__imp__OleUninitialize@0" in Funktion ""public: virtual __thiscall HostWindow::~HostWindow(void)" (??1HostWindow@@UAE@XZ)".

    hostwindow.obj:-1: Fehler: LNK2019: Verweis auf nicht aufgelöstes externes Symbol "__imp__CoLockObjectExternal@12" in Funktion ""public: virtual __thiscall HostWindow::~HostWindow(void)" (??1HostWindow@@UAE@XZ)".

    hostwindow.obj:-1: Fehler: LNK2019: Verweis auf nicht aufgelöstes externes Symbol "__imp__RevokeDragDrop@4" in Funktion ""public: virtual __thiscall HostWindow::~HostWindow(void)" (??1HostWindow@@UAE@XZ)".

    @

    Thanks in Advance



  • Inside the destructor of HostWindow, you're making a call to

    OleUninitialize(),
    CoLockObjectExternal(), and
    RevokeDragDrop()

    Do you have definitions for these functions? I'm pretty sure that is your problem.



  • THe functions are located in the header.

    To make the story easier to understand, i just created a simple window:
    @
    #include "mainwindow.h"
    #include <windows.h>
    #include <QApplication>

    void DisplayDataObject(IDataObject *pDataObject)
    {
    FORMATETC fmtetc = { CF_TEXT, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
    STGMEDIUM stgmed;

    // ask the IDataObject for some CF_TEXT data, stored as a HGLOBAL
    if(pDataObject->GetData(&fmtetc, &stgmed) == S_OK)
    {
        // We need to lock the HGLOBAL handle because we can't
        // be sure if this is GMEM_FIXED (i.e. normal heap) data or not
        char *data = (char
                      *)GlobalLock(stgmed.hGlobal);
    
        printf("%s\n", data);
    
        // cleanup
        GlobalUnlock(stgmed.hGlobal);
        ReleaseStgMedium(&stgmed);
    }
    

    }

    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);

    IDataObject *pDataObject;
    
    // Initialize COM and OLE
    if(OleInitialize(0) != S_OK)
            return 0;
    
     // Access the data on the clipboard
     if(OleGetClipboard(&pDataObject) == S_OK)
     {
       // access the IDataObject using a separate function
        DisplayDataObject(pDataObject);
        pDataObject->Release();
     }
    
    // Cleanup
    OleUninitialize();
    MainWindow w;
    w.show();
    
    return a.exec&#40;&#41;;
    

    }
    @

    THe code can be copied into the main.cpp of a new Qt-Widget-Application project.

    And i get the following error:
    @
    main.obj : error LNK2019: .......... "__imp__ReleaseStgMedium@4" in Funktion ""void __cdecl DisplayDataObject(struct IDataObject *)" (?DisplayDataObject@@YAXPAUIDataObject@@@Z)".

    main.obj : error LNK2019: ....... "__imp__OleUninitialize@0" in Funktion "_main".
    main.obj : error LNK2019:........ "__imp__OleGetClipboard@4" in Funktion "_main".
    main.obj : error LNK2019:......"__imp__OleInitialize@4" in Funktion "_main".
    @



  • Can you post the code for these functions?
    ReleaseStgMedium()
    OleUninitialize()
    OleGetClipboard()
    OleInitialize()

    Are these functions in a third party library? Either you need to add the dependency of the library to your solution, or you need to have the .cpp files that contains the definition of these functions in your code.

    It's not enough to have the functions listed in the header (unless they're inlined), you need to have the .cpp files that contain the definition of these functions.

    Example:

    In the header file

    // Example.h
    class Foo
    {
    Foo();
    ~Foo();
    int OleInitialize(); //Declaration
    int OleUninitialize(); // Declaration
    };

    // Example.cpp
    int Example::OleInitialize() // Definition
    {
    int x = 5;
    return x;
    }

    Every function needs to have a definition if it's being called. It's not enough to just have the declaration of a function and calling it. If you're using a third party library, you need to add that library to your dependency in order for it to work.



  • THe Functions are part of the Microsoft SDK.
    @
    #include <windows.h>
    @



  • Hi, insert
    LIBS += ole32.lib
    in your .pro file and run qmake, that should do it.



  • Hi hskoglund

    Your Post

    bq. Hi, insert
    LIBS += ole32.lib
    in your .pro file and run qmake, that should do it.

    solved my problem.

    Thanks so much.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.