Late binding to a library with “extern” defined variables
-
14-04-2021 - |
Pergunta
I'm trying to late bind my program to a DLL.
I know how to import its methods but in one its header files, I have a definition like this:
EXTERN_C const IID SomeVariable;
How can I refer to this variable in my program without getting the "unresolved external symbol" error?
Solução
You can use GetProcAddress to get the address of a function or variable.
Outras dicas
See GetProcAddr() at MSDN.
const IID *idp = reinterpret_cast<const IID *>(GetProcAddr(hLibrary, "SomeVariable"));
Now you can refer to SomeVariable
via the pointer - just like you can refer to the functions through their pointers. You should, of course, check that the pointer is not null before you actually use it!
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow