Click here to Skip to main content
15,895,256 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: DLL Extension MFC Pin
sunit58-Mar-05 20:23
sunit58-Mar-05 20:23 
GeneralAllocating struct with malloc, shows as undefined in Visual C++ debugger Pin
Dave J Smith8-Mar-05 1:18
Dave J Smith8-Mar-05 1:18 
GeneralRe: Allocating struct with malloc, shows as undefined in Visual C++ debugger Pin
CP Visitor8-Mar-05 5:45
CP Visitor8-Mar-05 5:45 
Generalremove() files but not into recycle bin Pin
User 17288848-Mar-05 0:35
User 17288848-Mar-05 0:35 
GeneralRe: remove() files but not into recycle bin Pin
ThatsAlok8-Mar-05 2:13
ThatsAlok8-Mar-05 2:13 
GeneralRe: remove() files but not into recycle bin Pin
TheGreatAndPowerfulOz8-Mar-05 3:38
TheGreatAndPowerfulOz8-Mar-05 3:38 
GeneralRe: remove() files but not into recycle bin Pin
Mike Dimmick8-Mar-05 8:04
Mike Dimmick8-Mar-05 8:04 
GeneralProcess is signaled on start up if another instance is running Pin
lulacapixaba8-Mar-05 0:17
lulacapixaba8-Mar-05 0:17 
Some applications, like the "Windows Picture and Fax Viewer" do not allow multiple instances to be launched. In this case, if I use CreateProcess or ShellExecuteEx to launch another instance, what happens is that the existing instance receives the document (in this case a .gif file), replacing the one that was being shown before.

The problem is that, if I use ShellExecuteEx, the process handle returned is already signaled and the WaitForSingleObject does not block until the viewer is closed. If I use CreateProcess, the same thing happens with both the process and the thread handles.

The MSDN says that ShellExecuteEx may return NULL in this case, but it doesn't.

My code is as follows:

CString sType = _T(".gif");
CString sFile = _T("c:\\temp\\logo1.gif");
TCHAR pszOut[1024];
DWORD pcchOut = 1023;

HRESULT ret = AssocQueryString(ASSOCF_INIT_DEFAULTTOSTAR |ASSOCF_REMAPRUNDLL,
ASSOCSTR_COMMAND,
sType,
"open",
pszOut,
&pcchOut);

CString sCmd;
sCmd.Format("%s",pszOut);
sCmd.Replace("%1",sFile);

// Launch the viewer
STARTUPINFO si;
PROCESS_INFORMATION pi;

ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );

if (CreateProcess( NULL,
sCmd.GetBuffer(),
NULL,
NULL,
FALSE,
0,
NULL,
".",
&si,
&pi ))
{
WaitForSingleObject( pi.hProcess, INFINITE );
}

CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );

The first time this code executes, the "Windows Picture and Fax Viewer" is launched and the gif is displayed properly. If I leave the viewer running and try to execute the code again, but with a different .gif file, the file is replaced in the viewer but the returned handles are signaled, which means that the WaitForSingleObject returns immediately.

I've noticed, that the process returned by CreateProcess and ShellExecuteEx is always signaled if a previous instance of the viewer is running, even if it was started in the command line by the user. Therefore, the possibility of this effect being caused by me not closing handles (which I do) or doing something wrong the first time I launch the viewer, for example is not true.

The command line to launch the "Windows Picture and Fax Viewer" is something like this:

rundll32.exe c:\windows\system32\shimgvw.dll,ImageView_Fullscreen C:\temp\logo.gif

Because it runs in a dll.

Any thoughts?

Lula Capixaba
GeneralRe: Process is signaled on start up if another instance is running Pin
Mike Dimmick8-Mar-05 2:36
Mike Dimmick8-Mar-05 2:36 
GeneralRe: Process is signaled on start up if another instance is running Pin
lulacapixaba8-Mar-05 3:02
lulacapixaba8-Mar-05 3:02 
GeneralRe: Process is signaled on start up if another instance is running Pin
TheGreatAndPowerfulOz8-Mar-05 3:36
TheGreatAndPowerfulOz8-Mar-05 3:36 
GeneralUsing Regions Pin
Kyudos8-Mar-05 0:02
Kyudos8-Mar-05 0:02 
GeneralRe: Using Regions Pin
namaskaaram8-Mar-05 17:12
namaskaaram8-Mar-05 17:12 
Generalvideo codec Pin
codecfvc17-Mar-05 23:53
codecfvc17-Mar-05 23:53 
GeneralA program within a program Pin
Ubik K7-Mar-05 23:36
Ubik K7-Mar-05 23:36 
GeneralRe: A program within a program Pin
BlackDice8-Mar-05 2:38
BlackDice8-Mar-05 2:38 
GeneralRe: A program within a program Pin
u6ik8-Mar-05 3:00
u6ik8-Mar-05 3:00 
GeneralRe: A program within a program Pin
Phil J Pearson8-Mar-05 4:47
Phil J Pearson8-Mar-05 4:47 
GeneralRe: A program within a program Pin
David Crow8-Mar-05 3:56
David Crow8-Mar-05 3:56 
GeneralRe: A program within a program Pin
u6ik8-Mar-05 4:12
u6ik8-Mar-05 4:12 
GeneralRe: A program within a program Pin
David Crow8-Mar-05 4:41
David Crow8-Mar-05 4:41 
QuestionData types mismatches or just incompatibility? Pin
Axonn Echysttas7-Mar-05 23:18
Axonn Echysttas7-Mar-05 23:18 
AnswerRe: Data types mismatches or just incompatibility? Pin
Cedric Moonen8-Mar-05 0:02
Cedric Moonen8-Mar-05 0:02 
GeneralRe: Data types mismatches or just incompatibility? Pin
Axonn Echysttas8-Mar-05 3:16
Axonn Echysttas8-Mar-05 3:16 
Generalscreen capture driver Pin
TomLismont7-Mar-05 23:06
TomLismont7-Mar-05 23:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.