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. How To Load (C++) Library in QT and Call function ?
Forum Updated to NodeBB v4.3 + New Features

How To Load (C++) Library in QT and Call function ?

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 2 Posters 1.4k Views
  • 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.
  • Taz742T Offline
    Taz742T Offline
    Taz742
    wrote on last edited by
    #1
    bool GlobalAll::WhatisMyIP(std::wstring& out_name )
    {
        typedef bool (* LPDLLFUNC) (std::wstring&);
    
        QLibrary lib("ELService.dll");
        lib.load();
    
        if(lib.isLoaded())
            qDebug() << "its loaded";
    
        HINSTANCE hDLL;
        LPDLLFUNC lpfnDllFunc = NULL;
    
        if(!hDLL )
            return false;
    
        lpfnDllFunc = (LPDLLFUNC)lib.resolve("WhatIsMyIP");
        if(!lpfnDllFunc )
            return false;
    
        lpfnDllFunc(out_name);
    
        qDebug() << QString::fromStdWString(out_name);
    
        return true;
    }
    

    Do what you want.

    m.sueM 1 Reply Last reply
    0
    • Taz742T Taz742
      bool GlobalAll::WhatisMyIP(std::wstring& out_name )
      {
          typedef bool (* LPDLLFUNC) (std::wstring&);
      
          QLibrary lib("ELService.dll");
          lib.load();
      
          if(lib.isLoaded())
              qDebug() << "its loaded";
      
          HINSTANCE hDLL;
          LPDLLFUNC lpfnDllFunc = NULL;
      
          if(!hDLL )
              return false;
      
          lpfnDllFunc = (LPDLLFUNC)lib.resolve("WhatIsMyIP");
          if(!lpfnDllFunc )
              return false;
      
          lpfnDllFunc(out_name);
      
          qDebug() << QString::fromStdWString(out_name);
      
          return true;
      }
      
      m.sueM Offline
      m.sueM Offline
      m.sue
      wrote on last edited by m.sue
      #2

      Hi @Taz742

      There is just one problem. This is a C interface. So, no reference, no bool, no classes, etc.

      Just pointers and C standard types. If some C++ types work anyway, please consider it as a happy co-incidence that may not work on someone else's machine.

      -Michael.

      Taz742T 1 Reply Last reply
      0
      • m.sueM m.sue

        Hi @Taz742

        There is just one problem. This is a C interface. So, no reference, no bool, no classes, etc.

        Just pointers and C standard types. If some C++ types work anyway, please consider it as a happy co-incidence that may not work on someone else's machine.

        -Michael.

        Taz742T Offline
        Taz742T Offline
        Taz742
        wrote on last edited by
        #3

        @m.sue
        I can not understand exactly what you want to say.
        Can you write any example?

        Do what you want.

        m.sueM 1 Reply Last reply
        0
        • Taz742T Taz742

          @m.sue
          I can not understand exactly what you want to say.
          Can you write any example?

          m.sueM Offline
          m.sueM Offline
          m.sue
          wrote on last edited by m.sue
          #4

          Hi @Taz742

          Your code is correct, but you can only use C standard types or pointers to such types.

          typedef bool (* LPDLLFUNC) (std::wstring&);
          ->
          typedef int (* LPDLLFUNC) (char *, int len);

          You maybe lucky that a class pointer works but I would not bet on it.

          -Michael.

          Taz742T 1 Reply Last reply
          0
          • m.sueM m.sue

            Hi @Taz742

            Your code is correct, but you can only use C standard types or pointers to such types.

            typedef bool (* LPDLLFUNC) (std::wstring&);
            ->
            typedef int (* LPDLLFUNC) (char *, int len);

            You maybe lucky that a class pointer works but I would not bet on it.

            -Michael.

            Taz742T Offline
            Taz742T Offline
            Taz742
            wrote on last edited by Taz742
            #5

            @m.sue

            bool GlobalAll::GetContactNameByID(string tin, std::wstring& out_name )
            {
                typedef bool (* LPDLLFUNC) (string, string, string, std::wstring&);
            
                HINSTANCE hDLL;
                LPDLLFUNC lpfnDllFunc = NULL;
            
                hDLL = LoadLibrary (L"C:\\Users\\tleladze\\Desktop\\build-user_-Desktop_Qt_5_7_0_MinGW_32bit-Debug\\debug\\ELService.dll");
                wstring sName;
            
                if(!hDLL )
                    return false;
            
                lpfnDllFunc = (LPDLLFUNC)GetProcAddress(hDLL, "GetContactNameByID");
                if(!lpfnDllFunc )
                    return false;
            
                lpfnDllFunc("arkania:206322102", "123456", tin, out_name);
            
                FreeLibrary (hDLL);
            
                return true;
            }
            

            i copy this code, and it worked fine in c++. but QT not.

            Do what you want.

            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