Home > Software engineering >  Have a good way to use LoadLibrary Dll to the outbound?
Have a good way to use LoadLibrary Dll to the outbound?

Time:09-16

LoadLibrary can only obtain export function,
Can be used () function returns an abstract class pointer everywhere, to use,
The shortcoming of this approach is that if class a lot, need the export function is also very much,
Derived classes from the class returned bad also, combination can combination but more awkward to use,
Is there any way to LoadLibrary can do like implicit loading way of easy to use?

CodePudding user response:

Packaging again, to do export interface function, then load the implicit
Or define the interface LoadLibrary GetProcAddress call encapsulated into a class, such as global variables, which define a macro definition function


CodePudding user response:

Reference COM
Export function to obtain a pointer to class, class implements a similar QueryInterface can get to the other classes

CodePudding user response:

Using the principle of com, to export to the class definition into a pure virtual interface, each interface identified by a unique GUID, each DLL with own GUID registration interface, each DLL export the following functions:

//module supports the GUID for riid interface
BOOL __declspec (dllexport) __stdcall SupportedInterface (REFIID riid);
//create the current module supported by the interface
LPVOID __declspec (dllexport) __stdcall CreateInterFace (REFIID riid);

When using, need to use which class, enum DLL, see which DLL is registered the GUID, find the DLL call its CreateInterFace function after the interface created, you can use

CodePudding user response:

solitary guest tianya quoted 3 floor response:
using the principle of com, to export to the class definition into a pure virtual interface, each interface identified by a unique GUID, each DLL with own GUID registration interface, each DLL export the following functions:

//module supports the GUID for riid interface
BOOL __declspec (dllexport) __stdcall SupportedInterface (REFIID riid);
//create the current module supported by the interface
LPVOID __declspec (dllexport) __stdcall CreateInterFace (REFIID riid);

When using, need to use which class, enum DLL, see which DLL is registered the GUID, find the DLL call its CreateInterFace function after the interface created, you can use the


This return to create the object, return a pointer,
If the type is too much is bad to did,
  • Related