Article View: borland.public.cppbuilder.nativeapi
Article #11756Re: SHExecInfo.hInstApp != GetWindowLong(hwnd,GWL_HINSTANCE);
From: Remy Lebeau (TeamB)
Date: Fri, 23 Jan 2004 22:12
Date: Fri, 23 Jan 2004 22:12
77 lines
3321 bytes
3321 bytes
"Rodrigo" <rmorteo@eudoramail.com> wrote in message
news:401190bb@newsgroups.borland.com...
> All right... If going for the ShellExecute way
I did not say to use ShellExecute(). I was merely mentioning that the
returned HINSTANCE from ShellExecuteEx() works the same as ShellExecute()
does.
> you said I would need to use a CreateProcess function so
> I could use retrieve the process handle
Sorry, I mean process *ID*, not handle.
> 1.- Would WaitForSingleObject accept a ProcessID, thread
> of process handle from the PROCESS_INFORMATION?
No, WaitForSingleObject needs a process handle, not a process ID. However,
CreateProcess() does provide both ID and handle at the same time.
> 2.-How do I retrieve the Application Name associated to
> the file extension?
Have a look at the FindExecutable() function.
> this is why I prefer the ShellExecute, however I'm not married
> to it, I just don't know how to use it properly
I already outlined what you can do if you intend to continue using
ShellExecuteEx() - use GetWindowThreadProcessId() and OpenProcess(). For
example (untested):
struct TWindowInfo
{
HANDLE hProcess;
HWND hWnd;
};
HWND TMainForm::LookForWindowHandle(HANDLE hProcess)
{
TWindowInfo info;
info.hProcess = hProcess;
info.hWnd = NULL;
EnumWindows((WNDENUMPROC)GetWinHandle, (LPARAM)&info);
return info.hWnd;
}
BOOL CALLBACK GetWinHandle(HWND hwnd, LPARAM lParam)
{
TWindowInfo *pInfo = (TWindowInfo*)lParam;
DWORD dwProcessId = 0;
GetWindowThreadProcessId(hwnd, &dwProcessId);
HANDLE hProcess = OpenProcess(0, FALSE, dwProcessId);
if( hProcess )
{
if( hProcess == pInfo->hProcess )
pInfo->hWnd = hwnd;
CloseHandle(hProcess);
}
return (pInfo->hWnd == NULL);
}
void TMainForm::AppSpawnFunction(NodeInfo *dataPtr)
{
//...
if( b_res )
{
dataPtr->hProcess = shExecInfo.hProcess;
dataPtr->hInstance = shExecInfo.hInstApp;
dataPtr->windowHandle = LookForWindowHandle(dataPtr->hProcess);
}
//...
}
Gambit
Technical Details
Message-ID:
<40119ad1$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<401157db$2@newsgroups.borland.com> <401171bf@newsgroups.borland.com> <401190bb@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,b936e6c0846d144e X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2004-01-23 14:10:04 PST From: "Remy Lebeau \(TeamB\)" <gambit47.no.spam@no.spam.yahoo.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <401157db$2@newsgroups.borland.com> <401171bf@newsgroups.borland.com> <401190bb@newsgroups.borland.com> Subject: Re: SHExecInfo.hInstApp != GetWindowLong(hwnd,GWL_HINSTANCE); Date: Fri, 23 Jan 2004 14:12:50 -0800 Lines: 79 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 NNTP-Posting-Host: 67.22.138.253 Message-ID: <40119ad1$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1074895569 67.22.138.253 (23 Jan 2004 14:06:09 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail