Re: Can I not OpenProcess(PROCESS_ALL_ACCESS...) in DLL under WinXP?



No, I didn' call OpenProcess in DllMain... I am sure that the same
thing was done in dll and exe.
The following is my code:

bool __stdcall _FindApp(wstring sClass, wstring sImage,
PROCESS_INFORMATION *pi)
{
DECLARE_DBG_SCOPE(_FindApp, true)

TCHAR buf[MAXSTR]=NULLSTR;
HWND hWnd=NULL;

hWnd=FindWindow((TCHAR *)sClass.c_str(), NULL);
pi->dwThreadId=GetWindowThreadProcessId(hWnd, &pi->dwProcessId);
pi->hProcess=OpenProcess(PROCESS_ALL_ACCESS, FALSE, pi->dwProcessId);

ASSERT(pi->hProcess); //in debug mode or under vista, this line
passes. but in xp, pi->hProcess==NULL and
GetLastError()==ACCESS_DENIED

GetModuleBaseName(pi->hProcess, NULL, buf, MAXSTR);
if(!hWnd || wstring(buf)!=sImage)
{
CloseHandle(pi->hProcess);
return false;
}

pi->hThread=OpenThread(THREAD_ALL_ACCESS, FALSE, pi->dwThreadId);
return true;
}
.



Relevant Pages

  • Re: DLL and communication from another process exe
    ... It is risky to do cross-thread SendMessage, but if all you want is a bool, then if you are ... If I were doing this in a DLL, I might consider creating a UI thread in the DLL that ... creates an invisible window that handles the communication. ... EXE gets SendMessage from DLL ...
    (microsoft.public.vc.mfc)
  • Re: Editors
    ... some strip them on exe files by default. ... "preferred base address" and, yup, relocations are completely ... DLL files, though, aren't loaded into their own address space but are ... EXE's "entry-point", though, is not "special" in that it's just an ...
    (alt.lang.asm)
  • Re: MFC DLL - ExitInstance hang on WaitForSingleObject
    ... Here is a simple pooling class implemented into a MFC DLL project. ... BOOL CPooler::StartPooling ... // Look for empty place in the array and create the Pooler ... void Enqueue(POOLER_CALLBACK_FN f, LPVOID p); ...
    (microsoft.public.vc.mfc)
  • Re: DLL pass vector by value crash
    ... The prototype for testfunc is a by-value copy, so it has to make a copy of the value. ... Are you using static linking for either the .exe (if so, it probably won't work correctly, ... clearly using the shared CRT DLL for the DLL you are constructing. ... no crash occurs in either config. ...
    (microsoft.public.vc.mfc)
  • Re: DLL pass vector by value crash
    ... stack of the exe and may allocate default member element on the exe heap. ... If this is a dangerous situation, the simple app I set up calling testFunc() ... in a dll did not crash. ... msvcr90.dll!free and access the source code of free.c. ...
    (microsoft.public.vc.mfc)