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. [SOLVED]QLibrary - load and using DLL
Forum Updated to NodeBB v4.3 + New Features

[SOLVED]QLibrary - load and using DLL

Scheduled Pinned Locked Moved General and Desktop
9 Posts 3 Posters 7.8k 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.
  • P Offline
    P Offline
    Peppy
    wrote on last edited by
    #1

    Well, I have Project.Configuration.dll, which exports function:
    @Q_DECL_EXPORT Configurator* getConfiguration(void);@

    I have got a lot of problems:

    • In debug directory is Project.Configuration.dll, but in Project.exe QLibrary can't find "Project.Configuration" (with omitted suffix)
    • I can't get that exported function because there are errors with this code:
      @
      typedef Configurator* (ConfigurationPrototype)(void);
      Configurator* Config = 0;
      QLibrary *ConfigLib = new QLibrary(QString("Project.Configuration.dll"));
      ConfigurationPrototype GetConfigurator = (ConfigurationPrototype)ConfigLib->resolve("getConfigurator"); // this makes errors
      @

    error: C2072: 'GetConfigurator' : initialization of a function

    error: C2205: 'GetConfigurator' : cannot initialize extern variables with block scope

    error: C2066: cast to function type is illegal

    error: C2440: 'initializing' : cannot convert from 'ConfiguratorPrototype (__cdecl *)' to 'ConfiguratorPrototype'

    There are no conversions to function types, although there are conversions to references or pointers to functions

    Could you tell me, where is the problem?

    1 Reply Last reply
    0
    • C Offline
      C Offline
      cincirin
      wrote on last edited by
      #2

      You should write typedef Configurator* (* ConfigurationPrototype)(void)

      1 Reply Last reply
      0
      • P Offline
        P Offline
        Peppy
        wrote on last edited by
        #3

        And the first problem?

        Well, I rewrote it. And hopefully it works! :) :D

        1 Reply Last reply
        0
        • C Offline
          C Offline
          cincirin
          wrote on last edited by
          #4

          Try to delete the Makefile and compile in Release mode ...
          OK, I don't see your edit post :-)

          1 Reply Last reply
          0
          • P Offline
            P Offline
            Peppy
            wrote on last edited by
            #5

            well, but how to export function?
            @Q_DECL_EXPORT void function(void);@
            Or:
            @void Q_DECL_EXPORT function(void);@

            ?

            1 Reply Last reply
            0
            • L Offline
              L Offline
              loladiro
              wrote on last edited by
              #6

              AFAIK,
              @void Q_DECL_EXPORT function(void);@
              Edit, also, if you want to use it you have to have something like this
              @
              #if defined(MY_LIBRARY)

              define MYHARED_EXPORT Q_DECL_EXPORT

              #else

              define MYHARED_EXPORT_EXPORT Q_DECL_IMPORT

              #endif
              @

              1 Reply Last reply
              0
              • P Offline
                P Offline
                Peppy
                wrote on last edited by
                #7

                No, that defintion doesn't work. I can't find exported function from library (through QLibrary::resolve)

                1 Reply Last reply
                0
                • C Offline
                  C Offline
                  cincirin
                  wrote on last edited by
                  #8

                  I use only the other :-) : @Q_DECL_EXPORT "function prototype"@ Also make sure your function is in @extern "C"@ body

                  1 Reply Last reply
                  0
                  • P Offline
                    P Offline
                    Peppy
                    wrote on last edited by
                    #9

                    Yes, "extern 'C'" working. :) :D Thank you very 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