参考:#
#include
#include
#include
//GetProcAddresses
//Argument1: hLibrary - Handle for the Library Loaded
//Argument2: lpszLibrary - Library to Load
//Argument3: nCount - Number of functions to load
//[Arguments Format]
//Argument4: Function Address - Function address we want to store
//Argument5: Function Name - Name of the function we want
//[Repeat Format]
//
//Returns: FALSE if failure
//Returns: TRUE if successful
BOOL GetProcAddresses( HINSTANCE *hLibrary,
LPCSTR lpszLibrary, INT nCount, ... )
{
va_list va;
va_start( va, nCount );
if ( ( *hLibrary = LoadLibrary( lpszLibrary ) )
!= NULL )
{
FARPROC * lpfProcFunction = NULL;
LPSTR lpszFuncName = NULL;
INT nIdxCount = 0;
while ( nIdxCount < nCount )
{
lpfProcFunction = va_arg( va, FARPROC* );
lpszFuncName = va_arg( va, LPSTR );
if ( ( *lpfProcFunction = GetProcAddress( *hLibrary, lpszFuncName ) ) == NULL )
{
lpfProcFunction = NULL;
return FALSE;
}
nIdxCount++;
}
}
else
{
va_end( va );
return FALSE;
}
va_end( va );
return TRUE;
}
typedef int ( WINAPI *MESSAGEBOX ) ( HWND , LPCSTR, LPCSTR, DWORD );
typedef int ( WINAPI *MESSAGEBOXEX )( HWND , LPCSTR, LPCSTR, DWORD , WORD );
typedef BOOL(WINAPI *ISCHARUPPER) (TCHAR );
typedef LPTSTR ( WINAPI *CHARUPPER )( LPTSTR );
void main(void)
{
MESSAGEBOX lpfMsgBox = NULL;
MESSAGEBOXEX lpfMsgBoxEx = NULL;
CHARUPPER lpfCharUpper = NULL;
ISCHARUPPER lpfIsCharUpper = NULL;
HINSTANCE hLib;
if(GetProcAddresses( &hLib, "User32.dll", 4,
&lpfMsgBox, "MessageBoxA",
&lpfMsgBoxEx, "MessageBoxExA" ,
&lpfCharUpper, "CharUpperA",
&lpfIsCharUpper, 413/*"IsCharUpperA"*/)) 参考depends,以序号方式加载,
{
//lpfMsgBox( 0, "Test1", "Test1", MB_OK );
//lpfMsgBoxEx( 0, "Test2", "Test2", MB_OK, MAKELANGID( LANG_ENGLISH, SUBLANG_ENGLISH_US ) );
char aa[120] = "aB";
LPTSTR lpsz = "asddddffe";
BOOL b = IsCharUpper( 'A');
b = lpfIsCharUpper( 'b');
CharLowerA(aa);
lpfCharUpper(aa);
//strcpy(aa, CharUpper("asddddffe"));
printf("result = %s\n", lpsz);
}
if ( hLib != NULL )
FreeLibrary( hLib );
}
阅读(2306) | 评论(1) | 转发(0) |