From: papilla AT cs DOT tamu DOT edu (Benoit Papillault) Subject: Re: Any idea? 3 Jun 1998 07:06:01 -0700 Message-ID: References: <00014319021586 AT artnetonline DOT com> Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII To: Vincent - Dirk Ertner Cc: gnu-win32 AT cygnus DOT com > Could anyone gimme a short statement, how to code the DLL access under C++ > (g++)? I have never heard about this function and do not have capi2032.dll on my system. But I known hwo to use LoadLibrary() and GetProcAddress() and all thr strange stuff for pointer to function casting. So: o to declare a pointer to a function: just put (* xxx) instead of xxx if xxx is the name of your function. o to call a "Windows" function: Windows use pascal call conventions which are different from C call conventions. So you need to use WINAPI keywork in the declaration of your function: ... WINAPI (* xxx) ... o the cast construction is ( new_type ) value. So for a pointer to function, it will be (take care abut parenthesis): ( DWORD (*)(DWORD, DWORD)) value for example. So here is my suggestion: (also don't forget ; at end of you lines and uses cout << "msg" << endl; instead of cout << "msg\n"; It is because of buffering reason (I think, not sure). ------------------------------------>8----------------------------------------- #include #include #include using namespace std; main() { cout << "Program CAPI.CC\n"; DWORD dwRet, dwWritten; // HINSTANCE? HMODULE hDll=LoadLibrary("kernel32.dll"); if (hDll == 0) cout << "DLL not found!\n"; else cout << "DLL found.\n"; BOOL WINAPI (*pfn)(HANDLE, const VOID *, DWORD, PDWORD, OVERLAPPED *) = (BOOL (*)(HANDLE,const VOID *,DWORD,PDWORD,OVERLAPPED *)) GetProcAddress(hDll,"WriteFile"); if (pfn == NULL) cout << "Address not found." << endl; dwRet = pfn(GetStdHandle(STD_OUTPUT_HANDLE),"super\r\n",7,&dwWritten,NULL); cout << "Result is " << dwRet << endl; FreeLibrary(hDll); } -------------8<-------------------8<-------------------8<---------------------- Benoit Papillault - For help on using this list (especially unsubscribing), send a message to "gnu-win32-request AT cygnus DOT com" with one line of text: "help".