From: <kp...@ya...> - 2002-01-24 09:10:31
|
Hi ( sorry I cant english ) I made DLL and DLL client linking function without imports using GetProcAddress but the functionn name exported Dll do not equal exactrlly Dll Client function name here my source 1. DLL Server a) DLL Server header fike #if BUILDING_DLL # define DLLIMPORT __declspec (dllexport) #else # define DLLIMPORT __declspec (dllimport) #endif DLLIMPORT BOOL APIENTRY DllMain(HANDLE hModule, DWORD dwReason, LPVOID lpReserved); DLLIMPORT WINAPI int sum( int x, int y ); b) DLL Server header source #include <windows.h> #include <stdio.h> #include "C:\Dev-C++\MyProject\testdll\mdsum\mdsum1.h" BOOL APIENTRY DllMain(HANDLE hModule, DWORD dwReason, LPVOID lpReserved) { switch(dwReason) { case DLL_PROCESS_ATTACH : printf("DLL_PROCESS_ATTACH Hello I am mdsum.Dll\n"); break; case DLL_PROCESS_DETACH : printf("DLL_PROCESS_DETACH mdsum.Dll killed by Windows\n"); break; } return TRUE; } WINAPI int sum( int x, int y ) { long total=0; printf( "x = %d, y = %d\n", x,y); total = x + y; return total; } 2. Dll Client source #include <windows.h> #include <stdio.h> typedef int (WINAPI *MDPROC)(int, int); main() { HINSTANCE hmdsum=NULL; MDPROC lpSqure=NULL; int dOutput=0; hmdsum = LoadLibrary("mdsum.dll"); if( hmdsum == NULL ) { printf("Can't load [mdsum.dll]\n"); getchar(); return -1; } lpSqure = (MDPROC) GetProcAddress( hmdsum, "sum@8"); // here Dll Server function name //lpSqure = (MDPROC) GetProcAddress( hmdsum, "sum"); // I can't use origninal function name if( lpSqure == NULL ) { printf("Can't get function point of sum [mdsum.dll]\n"); } else { dOutput = (*lpSqure)( 3, 3 ); printf( "3 + 3 = %d\n", dOutput); } FreeLibrary( hmdsum ); getchar(); return 0; } MinGW (Win32 gcc) compiler export allway function name with @ + ordinal number. @ + ordinal number need only linking, why exported _____________________________________________________________________ 맛보기 강좌를 듣고 수강소감을 적으면 경품이 와르르~ - 야후! 배움터 http://education.yahoo.co.kr/ 하루종일 이야기해도 시간가는 줄 모르는 - 야후! 채팅 http://kr.chat.yahoo.com/ |