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());
}
}