Click to See Complete Forum and Search --> : Explicit Linking Problem


lexicon
June 22nd, 2008, 05:06 PM
Hello;
I am trying to understand the concept of "Explicit Linking" but the following code gives the error error C2365: 'GetLogicalDrives' : redefinition; previous definition was 'function'
Other API functions such as FindFirstVolume, FindNextVolume, FindVolumeClose etc works properly.
Any ideas ?


#include <windows.h>
#include <stdio.h>

DWORD (WINAPI *GetLogicalDrives) (VOID);
int main()
{
// Load the dll

HMODULE hmod;
if((hmod = LoadLibrary(TEXT("Kernel32.dll"))))
{
if((GetLogicalDrives = (DWORD (WINAPI*)(VOID))GetProcAddress(hmod,"GetLogicalDrives")))
{
DWORD drivesId = GetLogicalDrives();
}
}

return 0;
}

sockman
June 22nd, 2008, 08:26 PM
There is a function called GetLogicalDrives() in winbase.h which your project probably includes. Just choose a different name.
s

lexicon
June 23rd, 2008, 06:01 AM
Ah my foolishness :/

Thanks for the solution.

Igor Vartanov
June 24th, 2008, 02:41 AM
Besides, kernel32.dll is always loaded into any process, so you'd better use GetModuleHandle instead. :)

And once you use LoadLibrary, please don't forget to FreeLibrary as complementary action. This must become your the most basic instinct to treat resources right. :)