Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. OLE Linker problem
Forum Updated to NodeBB v4.3 + New Features

OLE Linker problem

Scheduled Pinned Locked Moved General and Desktop
7 Posts 3 Posters 2.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Seajmoon
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • K Offline
      K Offline
      KrossedUp
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        Seajmoon
        wrote on last edited by
        #3

        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".
        @

        1 Reply Last reply
        0
        • K Offline
          K Offline
          KrossedUp
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          • S Offline
            S Offline
            Seajmoon
            wrote on last edited by
            #5

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

            1 Reply Last reply
            0
            • hskoglundH Offline
              hskoglundH Offline
              hskoglund
              wrote on last edited by
              #6

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

              1 Reply Last reply
              1
              • S Offline
                S Offline
                Seajmoon
                wrote on last edited by
                #7

                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.

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved