Mike Frank
11/3/2005 3:46:00 PM
You can''t use ShellExecute for that. It executes the process
asynchronously and just returns an error or success code.
You could use CreateProcess instead. An example for an Axapta wrapper
for this is listed below. The hProc variable (in my case this is a class
variable) will contain the process handle if the call was executed
successfully.
protected boolean createProcess(str _commandLine, str _currentDirectory)
{
#CBS_WinBase
#define.sizeOfprocInfo(16)
#define.sizeOfstartUpInfo(68)
DLLFunction createProcess = new DLLFunction(_winApiDLL,
"CreateProcessA");
Binary commandLine = new Binary(_commandLine);
Binary currentDirectory = new Binary(_currentDirectory);
Binary procInfo = new Binary(#sizeOfprocInfo);
Binary startUpInfo = new Binary(#sizeOfstartUpInfo);
boolean result;
startUpInfo.dWord(0, #sizeOfstartUpInfo); // DWORD cb;
createProcess.returns(ExtTypes::DWORD);
createProcess.arg(ExtTypes::DWORD,
ExtTypes::POINTER,
ExtTypes::DWORD,
ExtTypes::DWORD,
ExtTypes::DWORD,
ExtTypes::DWORD,
ExtTypes::DWORD,
ExtTypes::POINTER,
ExtTypes::POINTER,
ExtTypes::POINTER);
result = createProcess.call(null, commandLine, null, null, false,
/*#CREATE_NO_WINDOW*/ 0, null,
currentDirectory, startUpInfo, procInfo);
hProc = procInfo.dWord(0);
return result;
//BOOL CreateProcess(
// LPCTSTR lpApplicationName, // name of executable module
// LPTSTR lpCommandLine, // command line string
// LPSECURITY_ATTRIBUTES lpProcessAttributes, // SD
// LPSECURITY_ATTRIBUTES lpThreadAttributes, // SD
// BOOL bInheritHandles, // handle inheritance option
// DWORD dwCreationFlags, // creation flags
// LPVOID lpEnvironment, // new environment block
// LPCTSTR lpCurrentDirectory, // current directory name
// LPSTARTUPINFO lpStartupInfo, // startup information
// LPPROCESS_INFORMATION lpProcessInformation // process information
//);
//typedef struct _STARTUPINFO {
// DWORD cb;
// LPTSTR lpReserved;
// LPTSTR lpDesktop;
// LPTSTR lpTitle;
// DWORD dwX;
// DWORD dwY;
// DWORD dwXSize;
// DWORD dwYSize;
// DWORD dwXCountChars;
// DWORD dwYCountChars;
// DWORD dwFillAttribute;
// DWORD dwFlags;
// WORD wShowWindow;
// WORD cbReserved2;
// LPBYTE lpReserved2;
// HANDLE hStdInput;
// HANDLE hStdOutput;
// HANDLE hStdError;
//} STARTUPINFO, *LPSTARTUPINFO;
//typedef struct _PROCESS_INFORMATION {
// HANDLE hProcess;
// HANDLE hThread;
// DWORD dwProcessId;
// DWORD dwThreadId;
//} PROCESS_INFORMATION;
}