Checking return codes and calling GetLastError() will set you free. You should be checking return codes twice here. You are actually checking return codes zero times.
hDLL = LoadLibrary(L"MYDLL.DLL");
Check hDLL. Is it NULL? If so, call GetLastError() to find out why. It may be as simple as "File Not Found".
lpGetNumber = (LPGETNUMBER)GetProcAddress((HMODULE)hDLL, "GetNumber");
If lpGetNumber is NULL, call GetLastError(). It will tell you why the proc address could not be found. There are a few likely scenarios:
- There is no exported function named
GetNumber
- There is an exported function named
GetNumber, but it is not marked extern "c", resulting in name mangling.
hDLL isn't a valid library handle.
If it turns out to be #1 above, you need to export the functions by decorating the declaration with __declspec(dllexport) like this:
MyFile.h
__declspec(dllexport) int GetNumber();
If it turns out to be #2 above, you need to do this:
extern "C"
{
__declspec(dllexport) int GetNumber();
};