Thread: Run-time dynamic linking

  1. #1
    Registered User
    Join Date
    Feb 2006
    Posts
    15

    Run-time dynamic linking

    I've been trying to use run-time dynamig linking to import some apis. But GetProcAddress() can't find them.

    Everything seems to be in order, but still doesn't work.
    I'm using Visual Studio 2005.

    Code:
    #include "stdafx.h"
    #include <windows.h>
    #include <stdio.h>
    
    using namespace System;
    
    //typedef declarations from Kernel32.dll
    typedef  HANDLE (*MYPROC_FindFirstFile)(HANDLE, LPWIN32_FIND_DATA);
    typedef  bool (*MYPROC_FindNextFile)(HANDLE, LPWIN32_FIND_DATA);
     
    int main(int argc, char *argv[])
    {
     
    HMODULE hModule;
    TCHAR ModuleKernel32[] = TEXT("kernel32.dll");
    
            
    	MYPROC_FindFirstFile FindFirstFile;
    	MYPROC_FindNextFile FindNextFile;
    	
    	//load kernel32.dll
            if((hModule = LoadLibrary(ModuleKernel32)) == NULL){
    		printf("LoadLibrary error: %d\n",GetLastError());
    		exit(1);
    	}
    
    	//get address of *FindFirstFile* function
    	if((FindFirstFile = (MYPROC_FindFirstFile)GetProcAddress(hModule,"FindFirstFile")) == NULL){
    		printf("GetProcAddress FindFirstFile error: %d\n",GetLastError());
    	}
    
    	//get address of *FindNextFile* function
    	if((FindNextFile = (MYPROC_FindNextFile)GetProcAddress(hModule,"FindNextFile")) == NULL){
    		printf("GetProcAddress FindNextFile error: %d\n",GetLastError());
    	}
    }
    Last edited by XX@nnX; 08-24-2006 at 10:53 AM.

  2. #2
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    You have to FindFirstFileA or FindFirstFileW and FindNextFileA or FindNextFileW. Don't forget to FreeLibrary.

  3. #3
    Registered User
    Join Date
    Feb 2006
    Posts
    15
    That did it, thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to time how long a program takes to run?
    By advancedk in forum C Programming
    Replies: 2
    Last Post: 08-18-2008, 07:50 PM
  2. Dynamic Linking Library questions
    By Blackroot in forum C++ Programming
    Replies: 4
    Last Post: 10-11-2007, 03:04 AM
  3. need help in time zone
    By Gong in forum C++ Programming
    Replies: 2
    Last Post: 01-03-2007, 04:44 AM
  4. Read and set\change system time
    By Hexxx in forum C++ Programming
    Replies: 9
    Last Post: 01-02-2006, 07:11 AM
  5. I apologize. Good bye.
    By doubleanti in forum A Brief History of Cprogramming.com
    Replies: 14
    Last Post: 05-03-2002, 06:51 PM