[SOLVED]QLibrary - load and using DLL
-
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?
-
You should write typedef Configurator* (* ConfigurationPrototype)(void)
-
And the first problem?
Well, I rewrote it. And hopefully it works! :) :D
-
Try to delete the Makefile and compile in Release mode ...
OK, I don't see your edit post :-) -
well, but how to export function?
@Q_DECL_EXPORT void function(void);@
Or:
@void Q_DECL_EXPORT function(void);@?
-
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
@ -
No, that defintion doesn't work. I can't find exported function from library (through QLibrary::resolve)
-
I use only the other :-) : @Q_DECL_EXPORT "function prototype"@ Also make sure your function is in @extern "C"@ body
-
Yes, "extern 'C'" working. :) :D Thank you very much.