Beispiel #1
0
/*
 * MySpawn - spawn a windows app
 */
int MySpawn( char *cmd )
{
    FARPROC             proc;
    HANDLE              inst;
    cmd_struct          cmds;
    char                path[FILENAME_MAX];
#ifndef __WINDOWS_386__
    char                buffer[FILENAME_MAX];
#endif
    int                 rc;

    GetSpawnCommandLine( path, cmd, &cmds );
    cmds.cmd[cmds.len] = 0;
    proc = MakeProcInstance( (FARPROC)NotifyHandler, InstanceHandle );
    if( !NotifyRegister( (HANDLE)NULLHANDLE, (LPFNNOTIFYCALLBACK)proc, NF_NORMAL ) ) {
        FreeProcInstance( proc );
        return( -1 );
    }
    strcat( path, " " );
    strcat( path, &(cmds.cmd[0]) );
    inst = (HANDLE) WinExec( (LPCSTR)path, SW_SHOWNORMAL );
    if( inst > (HANDLE)32 ) {
        union REGS in_regs, out_regs;

        doneExec = FALSE;
#ifdef __WINDOWS_386__
        moduleHandle = GetModuleHandle( PASS_WORD_AS_POINTER( inst ) );
#else
        GetModuleFileName( inst, buffer, FILENAME_MAX - 1 );
        moduleHandle = GetModuleHandle( buffer );
#endif

        // waiting doesn't work under win-os2 so don't wait!
        in_regs.h.ah = 0x30;
        in_regs.h.al = 0x0;
        intdos( &in_regs, &out_regs );
        if( out_regs.h.al == 20 ) {
            doneExec = TRUE;
        }

        instanceHandle = inst;
        EditFlags.HoldEverything = TRUE;
        while( !doneExec ) {
            MessageLoop( TRUE );
            Yield();
        }
        EditFlags.HoldEverything = FALSE;
        rc = 0;
    } else {
        rc = -1;
    }
    NotifyUnRegister( (HANDLE)NULLHANDLE );
    FreeProcInstance( proc );
    return( rc );

} /* MySpawn */
Beispiel #2
0
int PASCAL WinMain( HINSTANCE hInstance,
                    HINSTANCE hPrevInstance,
                    LPSTR lpCmdLine,
                    int nCmdShow )
{
  FARPROC fp, fp1, fp2, fpWEP;
  HANDLE hlib16, hlib32;
  HINDIR hIndira, hIndirb;
  HINDIR hIndir1, hIndir2, hIndir3, hIndirWEP;
  DWORD cb;
  char buf[128];

#ifdef DO_16BIT_TEST
  /*
   * 16-bit DLL test, calling with Microsoft C calling conventions
   */
  hlib16 = LoadLibrary( "dll16.dll" );
  fp1 = GetProcAddress( hlib16, PASS_WORD_AS_POINTER( 1 ) );
  fp2 = GetProcAddress( hlib16, PASS_WORD_AS_POINTER( 2 ) );

  hIndira = GetIndirectFunctionHandle( fp1, INDIR_WORD,
              INDIR_DWORD, INDIR_WORD, INDIR_WORD,
              INDIR_DWORD, INDIR_ENDLIST );
  hIndirb = GetIndirectFunctionHandle( fp2, INDIR_CDECL, INDIR_WORD,
              INDIR_DWORD, INDIR_WORD, INDIR_WORD,
              INDIR_DWORD, INDIR_ENDLIST );

  cb = InvokeIndirectFunction( hIndira,
                               0x1, 0x11110000, 0x1100, 0x10,
                               0x22222222 );
  #ifdef __cplusplus
  {
    ostrstream sout( buf, sizeof( buf ) );
    sout << "RC = " << hex << cb << ends;
    MessageBox( NULL, sout.str(), "Gen32", MB_OK | MB_TASKMODAL );
  }
  #else
    sprintf( buf, "RC = %lx", cb );
    MessageBox( NULL, buf, "Gen32", MB_OK | MB_TASKMODAL );
  #endif

  cb = InvokeIndirectFunction( hIndirb,
                               0x1, 0x11110000, 0x1100, 0x10,
                               0x22222222 );
  #ifdef __cplusplus
  {
    ostrstream sout( buf, sizeof( buf ) );
    sout << "RC (cdecl) = " << hex << cb << ends;
    MessageBox( NULL, sout.str(), "Gen32", MB_OK | MB_TASKMODAL );
  }
  #else
    sprintf( buf, "RC (cdecl) = %lx", cb );
    MessageBox( NULL, buf, "Gen32", MB_OK | MB_TASKMODAL );
  #endif
  FreeLibrary( hlib16 );
#endif

  /*
   * 32-bit DLL test
   */
  hlib32 = LoadLibrary( "dll32.dll" );
  fp = GetProcAddress( hlib32, "Win386LibEntry" );
  fpWEP = GetProcAddress( hlib32, "WEP" );

  hIndir1 = GetIndirectFunctionHandle( fp, INDIR_WORD, INDIR_DWORD,
              INDIR_WORD, INDIR_WORD, INDIR_ENDLIST );
  hIndir2 = GetIndirectFunctionHandle( fp, INDIR_DWORD, INDIR_WORD,
              INDIR_WORD, INDIR_ENDLIST );
  hIndir3 = GetIndirectFunctionHandle( fp, INDIR_PTR, INDIR_WORD, INDIR_WORD,
          INDIR_DWORD, INDIR_WORD, INDIR_DWORD, INDIR_WORD, INDIR_ENDLIST );
  hIndirWEP = GetIndirectFunctionHandle( fpWEP, INDIR_WORD,
              INDIR_ENDLIST );

  cb = InvokeIndirectFunction( hIndir1, 0x666, 0x77777111, 0x6969, DLL_1 );
  #ifdef __cplusplus
  {
    ostrstream sout( buf, sizeof( buf ) );
    sout << "RC1 = " << hex << cb << ends;
    MessageBox( NULL, sout.str(), "Gen32", MB_OK | MB_TASKMODAL );
  }
  #else
    sprintf( buf, "RC1 = %lx", cb );
    MessageBox( NULL, buf, "Gen32", MB_OK | MB_TASKMODAL );
  #endif

  cb = InvokeIndirectFunction( hIndir2, 0x12345678, 0x8888, DLL_2 );
  #ifdef __cplusplus
  {
    ostrstream sout( buf, sizeof( buf ) );
    sout << "RC2 = " << hex << cb << ends;
    MessageBox( NULL, sout.str(), "Gen32", MB_OK | MB_TASKMODAL );
  }
  #else
    sprintf( buf, "RC2 = %lx", cb );
    MessageBox( NULL, buf, "Gen32", MB_OK | MB_TASKMODAL );
  #endif

  cb = InvokeIndirectFunction( hIndir3, "A Test String", 1, 2,
                               0xabcddcba, 3, 0x12344321, DLL_3 );
  #ifdef __cplusplus
  {
    ostrstream sout( buf, sizeof( buf ) );
    sout << "RC3 = " << hex << cb << ends;
    MessageBox( NULL, sout.str(), "Gen32", MB_OK | MB_TASKMODAL );
  }
  #else
    sprintf( buf, "RC3 = %lx", cb );
    MessageBox( NULL, buf, "Gen32", MB_OK | MB_TASKMODAL );
  #endif

  /*
   * this function call invokes the Supervisor WEP function
   */
  cb = InvokeIndirectFunction( hIndirWEP, 1 );
  #ifdef __cplusplus
  {
    ostrstream sout( buf, sizeof( buf ) );
    sout << "RC WEP = " << hex << cb << ends;
    MessageBox( NULL, sout.str(), "Gen32", MB_OK | MB_TASKMODAL );
  }
  #else
    sprintf( buf, "RC WEP = %lx", cb );
    MessageBox( NULL, buf, "Gen32", MB_OK | MB_TASKMODAL );
  #endif

  FreeLibrary( hlib32 );

  return( 0 );
}