|
-
October 27th, 2010, 02:41 PM
#1
Sending handle out of bool callback
This callback function is called when I press a button, but I wanted to pass the handle out of it to use it in another button or something else, and use openprocess out of it. How?
Thanks.
Code:
static BOOL CALLBACK EnumWindowsProcb(HWND hwnd, LPARAM lParam)
{
if (hwnd)
{
DWORD pid;
char windowname[1024];
GetWindowText(hwnd, windowname, 100);
if (strstr(windowname, "Untitled - Notepad"))
{
DWORD pidx;
GetWindowThreadProcessId(hwnd, &pidx);
if(pidx == lParam)
{
HANDLE hProcess = OpenProcess(PROCESS_CREATE_THREAD | PROCESS_VM_READ | PROCESS_VM_OPERATION | PROCESS_VM_WRITE, FALSE, (DWORD) pid);
}
}
return TRUE;
}
-
October 27th, 2010, 02:48 PM
#2
Re: Sending handle out of bool callback
Best regards,
Igor
-
October 27th, 2010, 02:50 PM
#3
Re: Sending handle out of bool callback
Ok but don't I need a function to send it out as I used EnumWindows() to send a lparam in?
-
October 27th, 2010, 02:50 PM
#4
Re: Sending handle out of bool callback
 Originally Posted by lucastonon
This callback function is called when I press a button, but I wanted to pass the handle out of it to use it in another button or something else, and use openprocess out of it. How?
What is "EnumWindowsProcb"?
If you mean "EnumWindowsProc", then that's what the second parameter to EnumWindowsProc is for.
http://msdn.microsoft.com/en-us/libr...=VS.85%29.aspx
Code:
HANDLE myHandle = NULL;
EnumWindows(whatever, (LPARAM)&myHandle);
//....
Code:
static BOOL CALLBACK EnumWindowsProcb(HWND hwnd, LPARAM lParam)
{
//...
HANDLE *pHandle = (HANDLE*)lParam;
*pHandle = hProcess;
....
Regards,
Paul McKenzie
-
October 27th, 2010, 04:07 PM
#5
Re: Sending handle out of bool callback
Ok but don't I need a function to send it out as I used EnumWindows() to send a lparam in?
No you don't need any. And Paul kindly showed how the whole thing should look like.
Best regards,
Igor
-
October 27th, 2010, 05:55 PM
#6
Re: Sending handle out of bool callback
I mean, I want to use hProcess out of the bool, the lparam I sent with enumwindows() is going to be used at the bool, but the variables I declare inside the bool can't be used out of it. Example:
Code:
EnumWindows(EnumWindowsProcb, NULL);
Code:
static BOOL CALLBACK EnumWindowsProcb(HWND hwnd, LPARAM lParam)
{
DWORD pidx;
GetWindowThreadProcessId(hwnd, &pidx);
}
Code:
void CAttachDlg::OnBnClickedButton1()
{
AfxMessageBox(pidx);
}
Then I'll have 'pidx' : undeclared identifier
Last edited by lucastonon; October 27th, 2010 at 06:01 PM.
-
October 27th, 2010, 08:42 PM
#7
Re: Sending handle out of bool callback
 Originally Posted by lucastonon
I mean, I want to use hProcess out of the bool, the lparam I sent with enumwindows() is going to be used at the bool, but the variables I declare inside the bool can't be used out of it.
I have no idea what you are trying to say.
If you are saying that you want that variable set, then pass the entire object as the second parameter and store the value there in the EnumWindowProcb function.
Code:
class CAttachDlg
{
HANDLE pidx;
//...
public:
void SetMyHandle(HANDLE h) { pidx = h; }
//...
};
Code:
CAttachDlg dlg;
EnumWindows(EnumWindowsProcb, &dlg);
Code:
static BOOL CALLBACK EnumWindowsProcb(HWND hwnd, LPARAM lParam)
{
DWORD pidx;
GetWindowThreadProcessId(hwnd, &pidx);
CAttachDlg* pDlg = (CAttachDlg*)lParam;
pDlg->SetMyHandle( pidx );
//...
}
Code:
void CAttachDlg::OnBnClickedButton1()
{
AfxMessageBox(pidx);
}
Regards,
Paul McKenzie
-
October 28th, 2010, 12:33 AM
#8
Re: Sending handle out of bool callback
but the variables I declare inside the bool can't be used out of it.
I doubt you are interesting in accessing precisely a variable of the callback context. Your interest is the value of the variable, and this is where lParam gives you the pointer to the variable from original function context:
From Paul's example:
Code:
static BOOL CALLBACK EnumWindowsProcb(HWND hwnd, LPARAM lParam)
{
//...
HANDLE *pHandle = (HANDLE*)lParam;
*pHandle = hProcess; // here you copy the value of local variable hProcess
....
Last edited by Igor Vartanov; October 28th, 2010 at 12:37 AM.
Best regards,
Igor
-
October 28th, 2010, 05:25 PM
#9
Re: Sending handle out of bool callback
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|