home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c495 / 5.ddi / WATCM955.ARJ / DLL.SDK / GEN32.C < prev    next >
Encoding:
C/C++ Source or Header  |  1993-02-16  |  2.3 KB  |  85 lines

  1. /*
  2.  *  GEN32.C
  3.  *
  4.  *  Compile:    wcc386 gen32 /zw
  5.  *  Link:    wlink @gen32
  6.  *  Bind:    wbind gen32 -n
  7.  */
  8. #include <windows.h>
  9. #include <stdio.h>
  10.  
  11. /*
  12.  * comment out this line if you do not want do the 16-bit
  13.  * dll call test
  14.  */
  15. #define DO_16BIT_TEST
  16.  
  17. extern char end;
  18. extern int _curbrk;
  19.  
  20. #pragma aux default modify[fs gs];
  21. #define DLL_1 1
  22. #define DLL_2 2
  23. #define DLL_3 3
  24.  
  25. int PASCAL WinMain( HANDLE hInstance,
  26.             HANDLE hPrevInstance,
  27.             LPSTR lpCmdLine,
  28.             int nCmdShow )
  29. {
  30.   FARPROC fp;
  31.   HANDLE hlib16, hlib32;
  32.   HINDIR hIndira;
  33.   HINDIR hIndir1, hIndir2, hIndir3;
  34.   DWORD cb;
  35.   char buf[128];
  36.  
  37. #ifdef DO_16BIT_TEST
  38.   /*
  39.    * 16-bit DLL test, calling with Microsoft C calling conventions
  40.    */
  41.   hlib16 = LoadLibrary( "dll16.dll" );
  42.   fp = GetProcAddress( hlib16, PASS_WORD_AS_POINTER( 1 ) );
  43.  
  44.   hIndira = GetIndirectFunctionHandle( fp, INDIR_CDECL, INDIR_WORD,
  45.           INDIR_DWORD, INDIR_WORD, INDIR_WORD,
  46.           INDIR_DWORD, INDIR_ENDLIST );
  47.  
  48.   cb = InvokeIndirectFunction( hIndira,
  49.                    0x1, 0x11110000, 0x1100, 0x10,
  50.                    0x22222222 );
  51.   sprintf( buf, "CDECL RC = %lx", cb );
  52.   MessageBox( NULL, buf, "Gen32", MB_OK | MB_TASKMODAL );
  53.   FreeLibrary( hlib16 );
  54. #endif
  55.  
  56.   /*
  57.    * 32-bit DLL test
  58.    */
  59.   hlib32 = LoadLibrary( "dll32.dll" );
  60.   fp = GetProcAddress( hlib32, "Win386LibEntry" );
  61.  
  62.   hIndir1 = GetIndirectFunctionHandle( fp, INDIR_WORD, INDIR_DWORD,
  63.           INDIR_WORD, INDIR_WORD, INDIR_ENDLIST );
  64.   hIndir2 = GetIndirectFunctionHandle( fp, INDIR_DWORD, INDIR_WORD,
  65.           INDIR_WORD, INDIR_ENDLIST );
  66.   hIndir3 = GetIndirectFunctionHandle( fp, INDIR_PTR, INDIR_WORD, INDIR_WORD,
  67.       INDIR_DWORD, INDIR_WORD, INDIR_DWORD, INDIR_WORD, INDIR_ENDLIST );
  68.  
  69.   cb = InvokeIndirectFunction( hIndir1, 0x666, 0x77777111, 0x6969, DLL_1 );
  70.   sprintf( buf, "RC1 = %lx", cb );
  71.   MessageBox( NULL, buf, "Gen32", MB_OK | MB_TASKMODAL );
  72.  
  73.   cb = InvokeIndirectFunction( hIndir2, 0x12345678, 0x8888, DLL_2 );
  74.   sprintf( buf, "RC2 = %lx", cb );
  75.   MessageBox( NULL, buf, "Gen32", MB_OK | MB_TASKMODAL );
  76.  
  77.   cb = InvokeIndirectFunction( hIndir3, "A Test String", 1, 2,
  78.                    0xabcddcba, 3, 0x12344321, DLL_3 );
  79.   sprintf( buf, "RC3 = %lx", cb );
  80.   MessageBox( NULL, buf, "Gen32", MB_OK | MB_TASKMODAL );
  81.   FreeLibrary( hlib32 );
  82.  
  83.   return( 0 );
  84. }
  85.