Post Reply

Forums -> UltraMon™ SDK -> Error in adding a process to run in the detached monitor
Von.Tao   2005-04-23 01:47
IUltraMonUtility* pUtil = 0;
CoCreateInstance(CLSID_UltraMonUtility, 0, CLSCTX_ALL, IID_IUltraMonUtility, reinterpret_cast(&pUtil));

ComString cmd = ".\\MMT.exe";
VARIANT vt_b;
vt_b.vt = VT_BOOL;
pUtil->Run(cmd.operator BSTR(),SHOWSTATE_NORMAL,VARIANT_TRUE,NULL,&vt_b.boolVal);
long pVal;
pUtil->get_ProcessId(&pVal);
HRESULT r5 = pApps->Add(pVal,monId);
HRESULT r6 = pUtil->ResumeProcess();

Above is my codes. monId=1.The number of my secondary monitor is "1". I have Detached the Secondary monitor successfully.
my problem is the given process don't display to the secondary monitor, in stead of the primary.
I feel puzzled very much!
Thanks in advance, I'm sorry to trouble you so much.

Von.Tao
Christian Studer   2005-04-23 02:14
Try using IUltraMonDetachedApps::LaunchAndAdd instead, this should fix the problem.

Most likely what happens is that when Add gets called the process hasn't created its windows yet, so Add won't move any windows to the target monitor.

IUltraMonDetachedApps::Add currently isn't that useful due to the limitation of only being able to add processes which aren't already running. This limitation has been removed for the next release (2.6).

Christian Studer - www.realtimesoft.com
Von.Tao   2005-04-23 14:19
I have tried LaunchAndAdd(), it seems to be not satisfying yet. Some applications are normal, such as word, notepad, but others such as acdsee and several personal apps. Is it normal thing in ultramon or bug?

Von.Tao
Christian Studer   2005-04-24 08:34
IUltraMonUtility::Run (which is also used by IUltraMonDetachedApps::LaunchAndAdd) doesn't support launching applications which need custom paths to be set (such as ACDSee).

You would need to launch these applications manually, or add the custom path to your process's environment before calling
IUltraMonUtility::Run.

Christian Studer - www.realtimesoft.com
Von.Tao   2005-04-25 15:22
VARIANT_BOOL vt_b;
pUtil->Run(cmd.operator BSTR(),SHOWSTATE_NORMAL,1,0,&vt_b);
pUtil->get_ProcessId(&lProcId);
pApps->Add(lProcId,1);
pUtil->ResumeProcess();

long iHProc;
pUtil->get_HProcess(&iHProc);
...
...
DWORD lpExitCode;
GetExitCodeProcess(&iHProc, &lpExitCode);
BOOL b = TerminateProcess(&iHProc,lpExitCode);

Is it Correct way to get the last Run process handle. The value of iHProc i got is a long int(1676), it seems to normal, but the function termintateprocess() return 0(the value of b).The termination fail?

Von.Tao
Christian Studer   2005-04-26 08:15
The only issue I see is that you pass a pointer to the process handle to GetExitCodeProcess and TerminateProcess, you should pass the handle value instead: TerminateProcess(iHProc, lpExitCode)

Christian Studer - www.realtimesoft.com
Von.Tao   2005-04-26 23:00
pUtil->get_HProcess() return a long value, not a handle.
I can't understand the the out parameter of function get_HProcess(long *lVal);

Von.Tao
Christian Studer   2005-04-27 08:33
UltraMon uses long instead of HANDLE in order to be compatible with scripting clients.

You can just cast the long to HANDLE, for example with LongToHandle: GetExitCodeProcess(LongToHandle(iHProc), &lpExitCode)

Christian Studer - www.realtimesoft.com
Von.Tao   2005-04-28 01:36
very grateful to you!

Von.Tao
Forums -> UltraMon™ SDK -> Error in adding a process to run in the detached monitor

Post Reply