3

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?

Idov
  • 5,006
  • 17
  • 69
  • 106
  • Could you elaborate on the late binding you are doing for functions ? – parapura rajkumar Jan 07 '12 at 20:24
  • I know the function's signature, so I define a function pointer that matches it. Then I just call "GetProcAddress" with the DLL handle and the function's name. I assign the result to an instance of my function pointer and then I can use it as any other function. – Idov Jan 07 '12 at 20:28
  • 1
    Odds are very high that this variable is just not getting exported. Use dumpbin.exe /exports on the DLL to double-check. – Hans Passant Jan 07 '12 at 22:46

2 Answers2

2

You can use GetProcAddress to get the address of a function or variable.

Jim Rhodes
  • 5,021
  • 4
  • 25
  • 38
1

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!

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278