VB function declaration (must be on a single line in VB) Declare Function SpawnAndWait& Lib "RUNLIB.DLL" (ByVal parenthwnd%, ByVal lpszOp$, ByVal lpszFile$, ByVal lpszParams$, ByVal lpszDir$, ByVal nShow%) DWORD SpawnAndWait(hwnd, lpszOp, lpszFile, lpszParams, lpszDir, fsShowCmd) HWND hwnd /* handle of parent window */ LPCSTR lpszOp /* address of string for operation to perform */ LPCSTR lpszFile /* address of string for filename */ LPCSTR lpszParams /* address of string for executable-file parameters */ LPSCTR lpszDir /* address of string for default directory */ int fsCmdShow /* whether file is shown when opened */ The SpawnAndWait function executes and waits for termination of the specified application or associated file. Parameter Description hwnd Identifies the parent window. This window receives any message boxes an application produces (for example, for error reporting). lpszOp Points to a null-terminated string specifying the operation to perform. This string can be "open" or "print". If this parameter is NULL, "open" is the default value. lpszFile Points to a null-terminated string specifying the file to open. lpszParams Points to a null-terminated string specifying parameters NULL, "open" is the default value. passed to the application when the lpszFile parameter specifies an executable file. If lpszFile points to a string specifying a document file, this parameter is NULL. lpszDir Points to a null-terminated string specifying the default directory. fsShowCmd Specifies whether the application window is to be shown when the application is opened. See ShowWindow for valid values. Returns HIWORD == hInstance of started application. Values less than 32 are errors returned from ShellExecute. 0xFFFF is general error LOWORD == return code of spawned application. 0xFFFF is general error Comments The file specified by the lpszFile parameter can be a document file or an executable file. If it is a document file, this function opens or prints it, depending on the value of the lpszOp parameter. If it is an executable file, this function opens it, even if the string "print" is pointed to by lpszOp. WARNING: This function will not wait on apps like Word and Excel that responsed to the DDE broadcast mad by ShellExecute or the second instance of multiple data applications. WARNING: This function supports only one block at a time per task. Calling tasks should not call this function when it has a prior pending SpawnAndWait call. DWORD SpawnAndWaitIndirect(lpSpawnWait) LPSPAWNWAIT lpSpawnWait /* far reference to SPAWNWAIT structure typedef struct tagSPAWNWAIT { HWND hwnd; LPCSTR lpszOp; LPCSTR lpszFile; LPCSTR lpszParams; LPCSTR lpszDir; int fsShowCmd; LPMSGPROC lpmsgproc; } SPAWNWAIT; Member Description hwnd handle of parent window lpszOp address of string for operation to perform lpszFile address of string for filename lpszParams address of string for executable-file parameters lpszDir address of string for default directory fsShowCmd whether file is shown when opened lpmsgproc address of application provided MessagePump (must load DS on entry) void CALLBACK MessagePump(lpmsg) LPSMG lpsg /* long pointer to MSG to process Message Proc is a place holder for an application provided callback function (which must load DS on entry) that will process messages retrieved in runlib's PeekMessage loop. Allows calling application to do modless dialog and accelerator message proccessing. lpmsgproc should be set to NULL if not used. RunLib will do a default TranslateMessage/DispatchMessage instead. example of message processing function for MDI application void CALLBACK MyMessagePump(LPMSG lpmsg) { if(!TranslateMDISysAccel(hClient, lpsmg) && !TranslateAccelerator(hFram, hAccel, lpsmg)) { TranslateMessage(lpsmg); DispatchMessage(lpmsg); } } Returns HIWORD == hInstance of started application. Values less than 32 are errors returned from ShellExecute. 0xFFFF is general error LOWORD == return code of spawned application. 0xFFFF is general error Comments The file specified by the lpszFile parameter can be a document file or an executable file. If it is a document file, this function opens or prints it, depending on the value of the lpszOp parameter. If it is an executable file, this function opens it, even if the string "print" is pointed to by lpszOp. WARNING: This function will not wait on apps like Word and Excel that responsed to the DDE broadcast mad by ShellExecute or the second instance of multiple data applications. WARNING: This function supports only one block at a time per task. Calling tasks should not call this function when it has a prior pending SpawnAndWait call.