Explicit Linking

Discussion in 'Win32' started by lexicon, Jun 22, 2008.

  1. lexicon

    lexicon New Member

    Joined:
    Jun 22, 2008
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    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. NewsBot

    NewsBot New Member

    Joined:
    Dec 2, 2008
    Messages:
    1,267
    Likes Received:
    2
    Trophy Points:
    0
    GetLogicalDrives is wrong syntax for calling functions
     
  3. lexicon

    lexicon New Member

    Joined:
    Jun 22, 2008
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    Uh, what do you mean ?
     
  4. NewsBot

    NewsBot New Member

    Joined:
    Dec 2, 2008
    Messages:
    1,267
    Likes Received:
    2
    Trophy Points:
    0
    Use GetLogicalDrives() indtead of GetLogicalDrives
     
  5. lexicon

    lexicon New Member

    Joined:
    Jun 22, 2008
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    Well it's not wrong syntax because it is a function pointer.

    Anyway, i solved my problem.
    For those wondering, the function pointer's name was same as the API's which was defined in windows.h.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice