CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2008
    Posts
    2

    Explicit Linking Problem

    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 ?

    Code:
    #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;
    }

  2. #2
    Join Date
    Aug 2006
    Posts
    157

    Re: Explicit Linking Problem

    There is a function called GetLogicalDrives() in winbase.h which your project probably includes. Just choose a different name.
    s

  3. #3
    Join Date
    Jun 2008
    Posts
    2

    Re: Explicit Linking Problem

    Ah my foolishness :/

    Thanks for the solution.

  4. #4
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,633

    Re: Explicit Linking Problem

    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.
    Best regards,
    Igor

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured