S
S
Slavka2016-02-18 17:13:50
Qt
Slavka, 2016-02-18 17:13:50

Using functions from Dll library?

QDir path;
    QLibrary myLib("C:\\Windows\\SysWOW64\\regsvr32\\Adaptor.dll");
    if(!myLib.load())
        qDebug()<<"Error";

     void (*myFunction)()  = myLib.resolve("OpenConnection");
     if (!myFunction)
          qDebug() << "NULL";
         //if (myFunction())
          //     qDebug() << "Error";

I registered the library through regsvr32 and "Error" is no longer displayed, but the function pointer is still not created.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Mercury13, 2016-02-18
@Mercury13

The question arises. Is it a simple DLL with functions sticking out or COM?
• QLibrary - for DLLs.
• regsvr32 is for COM.
• The first time it didn't boot and the second time it booted because 32-bit programs with a standard manifest mistake the "SysWOW64" directory for "System32". When a DLL is not found, the program looks for it in some standard places, and these may be active COM servers.
• OpenConnection could not be found for a hell of a lot of reasons. It may turn out that the name of the OpenConnection is "goat" and you need something like "[email protected]". It may turn out that the library is really a COM server and QLibrary is useless here.

P
Peter, 2016-02-18
@petermzg

1. If this is a COM library that can be registered via regsvr32, then the following functions should be available to you.
DllCanUnloadNow, DllGetClassObject, DllRegisterServer, DllUnregisterServer
Through DllGetClassObject you can create a COM object, knowing its IID.
If it's a regular library, then maybe OpenConnection. (Although developers can export other functions with COM servers, they usually do not)
2. If the COM server is correctly registered, then you do not need to load the library yourself, you can create an object through CoCreateInstance
3. If this is a regular library, then you can load only if it matches the bitness of the current process. That is, 32-bit, only 32-bit applications, and 64 only from 64-bit applications.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question