This is the mail archive of the cygwin@sourceware.cygnus.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Any idea?


> 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 <iostream.h>
#include <string.h>
#include <windows.h>
 
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@cygnus.com" with one line of text: "help".


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]