June 24, 2011

Peppy Peppy
Lab Rat
412 posts

[SOLVED]QLibrary - load and using DLL

 

Well, I have Project.Configuration.dll, which exports function:

  1. 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:
    1.     typedef Configurator* (ConfigurationPrototype)(void);
    2.                Configurator* Config = 0;
    3.     QLibrary *ConfigLib = new QLibrary(QString("Project.Configuration.dll"));
    4.     ConfigurationPrototype GetConfigurator = (ConfigurationPrototype)ConfigLib->resolve("getConfigurator"); // this makes errors
    1. error: C2072: ‘GetConfigurator’ : initialization of a function
    2. error: C2205: ‘GetConfigurator’ : cannot initialize extern variables with block scope
    3. error: C2066: cast to function type is illegal
    4. 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?

8 replies

June 24, 2011

cincirin cincirin
Ant Farmer
444 posts

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

June 24, 2011

Peppy Peppy
Lab Rat
412 posts

And the first problem?

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

June 24, 2011

cincirin cincirin
Ant Farmer
444 posts

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

June 24, 2011

Peppy Peppy
Lab Rat
412 posts

well, but how to export function?

  1. Q_DECL_EXPORT void function(void);

Or:
  1. void Q_DECL_EXPORT function(void);

?

June 24, 2011

loladiro loladiro
Lab Rat
596 posts

AFAIK,

  1. void Q_DECL_EXPORT function(void);

Edit, also, if you want to use it you have to have something like this
  1. #if defined(MY_LIBRARY)
  2. #  define MYHARED_EXPORT Q_DECL_EXPORT
  3. #else
  4. #  define MYHARED_EXPORT_EXPORT Q_DECL_IMPORT
  5. #endif

June 24, 2011

Peppy Peppy
Lab Rat
412 posts

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

June 24, 2011

cincirin cincirin
Ant Farmer
444 posts

I use only the other :-) :

  1. Q_DECL_EXPORT "function prototype"
Also make sure your function is in
  1. extern "C"
body

June 24, 2011

Peppy Peppy
Lab Rat
412 posts

Yes, “extern ‘C’” working. :) :D Thank you very much.

 
  ‹‹ [SOLVED] Qicon disabled full color      how to convert png to gif with QT ››

You must log in to post a reply. Not a member yet? Register here!