POV-Ray : Newsgroups : povray.windows : Calling Povray from an other program : Re: Calling Povray from an other program Server Time
2 Jul 2024 23:04:12 EDT (-0400)
  Re: Calling Povray from an other program  
From: Philippe Lhoste
Date: 8 Aug 2002 11:11:08
Message: <Xns9264AEAAD8065PhiLho@204.213.191.226>
"wkx" <nomail@nomail> wrote in 
news:web.3d528293c353cbdab4b13400@news.povray.org:

> Hi all
> I write a small app in VC which uses POV-Ray for Window to render some
> bitmaps. Then I postprocess the Bitmaps created by POV-Ray so it is
> important to wait until the rendering is complete. I achieve this by
> synchronizing with POV-Ray which works fine, but it is very annoying
> that you have to close all POV-Ray windows manually.
> 
> In a batch-file it worked with the parameter "/EXIT" but in my app
> this parameter seems to have no effect (POV-Ray does not close when
> the render is complete).
> 
> Here is a piece of code:
> 
> HANDLE hProcess;
> PROCESS_INFORMATION ProcessInfo;
> STARTUPINFO StartupInfo;
> CString sParams;
> sParams.Format("/EXIT /NR +I%s +w%d +h%d +kfi0 +kff%d -p -a", sFileName,
> nSize, nSize, m_nStates-1);
> FillMemory(&StartupInfo, sizeof(STARTUPINFO), 0);
> StartupInfo.cb = sizeof(STARTUPINFO);
> CString strPovray = m_pProperties->m_path.m_strPovray;
>::CreateProcess(strPovray, strParams, NULL, NULL, true, 0, NULL, NULL,
> &StartupInfo, &ProcessInfo);

You should check the result of CreateProcess... Why are you setting the 
bInheritHandles parameter to true? It is traditionally set to FALSE, 
unless really needed.

> hProcess = ::OpenProcess(SYNCHRONIZE | PROCESS_TERMINATE, false,
> ProcessInfo.dwProcessId);

No need for this call, you can use ProcessInfo.hProcess.

> if (::WaitForSingleObject(hProcess, 30000) == WAIT_TIMEOUT) {
>  ::TerminateProcess(hProcess, 0);
> }

Mmm, using TerminateProcess is very bad, it kills the process without 
closing DLLs, releasing memory, etc. It really should be used only in 
extreme cases, like debugging. 30s is quite short for a POV-Ray rendering, 
but now I don't know your scenes.

>::CloseHandle(hProcess);

::CloseHandle(ProcessInfo.hThread);
::CloseHandle(ProcessInfo.hProcess);

Seems cleaner... At least, that's what Microsoft says...

Now, I didn't answered your question... :-(
I have a meeting, I will look closer after.

Regards.

-- 
--=#=--=#=--=#=--=#=--=#=--=#=--=#=--=#=--=#=--
Philippe Lhoste (Paris -- France)
Professional programmer and amateur artist
http://jove.prohosting.com/~philho/


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.