|
|
CString s( _variant_t(FunctionReturningVariant()) );
Concussus surgo.
When struck I rise.
|
|
|
|
|
|
Nishant S wrote:
Is there any way to pass a user defined param to a WH_CBT hook?
AFAIK, not directly. Is your hook thread or global?
Tomasz Sowinski -- http://www.shooltz.com
What is "scratch" and why can everything be made from it?
|
|
|
|
|
|
Nishant S wrote:
The hook proc is a static method of a class. I want to pass the instance pointer to the hook proc as I need to access some instance variables there
You have a variety of solutions to consider, from simple global variable through static data members to super-dooper object-oriented function adapters.
I'd create another static method which gets the parameter, stores it in private static member and calls SetWindowsHookEx with address of static hook proc.
Tomasz Sowinski -- http://www.shooltz.com
What is "scratch" and why can everything be made from it?
|
|
|
|
|
Tomasz Sowinski wrote:
I'd create another static method which gets the parameter, stores it in private static member and calls SetWindowsHookEx with address of static hook proc.
Nope. I want thread-safety. Right now I am thinking in terms of using a CMapPtrToPtr.
Nish
Author of the romantic comedy
Summer Love and Some more Cricket [New Win]
Review by Shog9
Click here for review[NW]
|
|
|
|
|
Nishant S wrote:
Right now I am thinking in terms of using a CMapPtrToPtr.
Beware of CG, who's going to jump in and tell you that CMapPtrToPtr is a donkey crap and you should use std::map instead
If you're going to stick with CMap-based container, consider the typed variants (CTypedMapxxx). Or - you could use thread-local storage, which basically gives you per-thread statics. Check TlsXXX functions or __declspec(thread).
Tomasz Sowinski -- http://www.shooltz.com
What is "scratch" and why can everything be made from it?
|
|
|
|
|
Nishant S wrote:
Nope. I want thread-safety. Right now I am thinking in terms of using a CMapPtrToPtr
To map what exactly to what?
If you need thread safety, you could also use a thread local static class variable to store the instance pointer.
Of course, I would recommend to use a super-dooper object-oriented function adapter just as described in my article Use member functions for C-style callbacks and threads - a general solution
--
Daniel Lohmann
http://www.losoft.de
(Hey, this page is worth looking! You can find some free and handy NT tools there )
|
|
|
|
|
Check out the technique i used for hooks in this article. Maximilian Hänel introduced me to this technique (which is very similar to what ATL uses) in his WTL port; it uses a template wrapping a few asm instructions & a class pointer to store both along *with* the callback address.
---
Shog9
If I could sleep forever, I could forget about everything...
|
|
|
|
|
I'm a bit lost here. How can I add a popupmenu to, let's say, a listcontrol. The listcontrol is a member(m_ctrlList) of a dialog.
I've got already this:
CMenu menuPopup;
menuPopup.LoadMenu(IDR_POPUP_MENU);
Somebody knows what to do next? tnx...
[VISUAL STUDIO 6.0] [MFC] [WIN98/2]
Bluute tette!
|
|
|
|
|
menuPopup.GetSubMenu(0)->TrackPopupMenu(...);
This assumes that you want to show the leftmost submenu. Usually there's only one, but some people like to aggregate all right-click popups used in application in one menu resource.
You'll find detailed info on TrackPopupMenu arguments in MSDN.
Tomasz Sowinski -- http://www.shooltz.com
What is "scratch" and why can everything be made from it?
|
|
|
|
|
I've added this:
menu.GetSubMenu(0)->TrackPopupMenu(TPM_LEFTALIGN|TPM_RIGHTBUTTON,0,0,this);
I receive an access violation when running in CMenu::TrackPopupMenu, m_hMenu is NULL.
[VISUAL STUDIO 6.0] [MFC] [WIN98/2]
Bluute tette!
|
|
|
|
|
frisco wrote:
I receive an access violation when running in CMenu::TrackPopupMenu, m_hMenu is NULL.
That's because you don't have a popup menu. You've probably defined all items on top level. TrackPopupMenu can't use that - move the items into popup menu.
Tomasz Sowinski -- http://www.shooltz.com
What is "scratch" and why can everything be made from it?
|
|
|
|
|
In the resource browser, under the menu folder, I've got one menu resource called IDR_POPUP_MENU. Where and what should I add there, cause if we add a popupmenu there, we can't give it an ID, and if I add a normal menuitem, an error occures.
[VISUAL STUDIO 6.0] [MFC] [WIN98/2]
Bluute tette!
|
|
|
|
|
Never mind... it works
[VISUAL STUDIO 6.0] [MFC] [WIN98/2]
Bluute tette!
|
|
|
|
|
hi all,
i have a program started from SDK (no mfc) and i need add a listbox to it.
i've created a listbox on the screen with CreateWindowEX(). but, i don't know how to add and remove data from it.
could anyone give me idea?
i have included MFC support in the project. but, i write with IDE. i don't know how to add a CListBox to a program from SDK. do u think it is easier using CListBox instead of starting API?
pls give me some idea!
thanks,
jim
|
|
|
|
|
Check the MSDN for documentation for listbox messages and notifications. Their identifiers start with LB_ and LBN_ prefixes.
Tomasz Sowinski -- http://www.shooltz.com
What is "scratch" and why can everything be made from it?
|
|
|
|
|
Hi !
I have following problem.
I use threads to send data to another application (WM_COPYDATA), because I dont want to wait for SendMessage function finishes.
So, I have sendNotify function, that starts threads and passes some user-defined data to it. This functions looks like this:
<br />
void CHinfoServerApp::sendNotify(NotifyCode nCode, LPVOID data)<br />
{<br />
.<br />
.<br />
.<br />
case NC_SCREENLOG:<br />
{<br />
ScreenLogData slData = *((ScreenLogData*) data);
COPYDATASTRUCT cpd;<br />
SendNotifyThreadInfo sntInfo;
cpd.dwData = NC_SCREENLOG;<br />
cpd.cbData = sizeof(slData);<br />
cpd.lpData = (void*)&slData;<br />
sntInfo.cpd = cpd;<br />
sntInfo.hDestWnd = (HWND)hGUIManagerWindow;
AfxBeginThread(sendNotifyThread, (void*)&sntInfo);<br />
break;<br />
}<br />
.<br />
.<br />
}<br />
This function is used as follows:
.<br />
.<br />
ScreenLogData slData;<br />
LoadString(((CMainFrame*)m_pMainWnd)->getResHandle(), IDS_SERVICE_LOG_INIT, slData.text, 2 * MY_MAX_PATH);<br />
sendNotify(NC_SCREENLOG, (void*)&slData);<br />
.<br />
.<br />
The thread function looks like this:
<br />
UINT sendNotifyThread(LPVOID lParam)<br />
{<br />
SendNotifyThreadInfo sntInfo = *((SendNotifyThreadInfo*)(lParam));
COPYDATASTRUCT cpd = sntInfo.cpd; <br />
<br />
::SendMessage((HWND)(sntInfo.hDestWnd), WM_COPYDATA, (WPARAM) AfxGetApp()->m_pMainWnd->GetSafeHwnd(), (LPARAM)&cpd);<br />
return 0;<br />
}<br />
ScreenLogData and SendNorifyThreadInfo structures are defined as follows:
<br />
typedef struct {<br />
char text[2 * MY_MAX_PATH];<br />
} ScreenLogData;<br />
<br />
typedef struct {<br />
COPYDATASTRUCT cpd;<br />
HWND hDestWnd;<br />
} SendNotifyThreadInfo;<br />
In the thread function, I highlighted the problem line. On this line appears error - something with memory access. And I want to know why. I think that it is something with that the pointer in sendNotify function is created on stack and in the thread function it is no longer valid. Am I right ? And how can I do this safely ???
Any suggestion helps a lot.
Celebrate Mr. Cesilko!
|
|
|
|
|
You are passing the thread data that has been allocated on the stack. This is a big no no, because these variables may have gone out of scope even before the thread starts execution.
Parameters to threads should always be created on the heap and freed by the thread that takes the parameter.
BTW: Does anybody know why WM_COPYDATA should not be used with PostMessage()? The MSDN are a bit unclear about the reasons and I have a feeling that it is just to make sure the sended data is valid unitl the target process has recieved it.
--
Daniel Lohmann
http://www.losoft.de
(Hey, this page is worth looking! You can find some free and handy NT tools there )
|
|
|
|
|
Thanks a lot!
Everytime I used threads before, I used global variables as well. I was just wondering if there is some way to get safely data created on stack...
Celebrate Mr. Cesilko!
|
|
|
|
|
Daniel Lohmann wrote:
BTW: Does anybody know why WM_COPYDATA should not be used with PostMessage()?
I *guess* that SendMessage has the special code handling WM_COPYDATA (mapping between memory spaces of two processes). It's probably allocating some resources before passing control to target wndproc, and cleans up afterwards. With PostMessage cleanup would be more difficult.
Tomasz Sowinski -- http://www.shooltz.com
What is "scratch" and why can everything be made from it?
|
|
|
|
|
Tomasz Sowinski wrote:
I *guess* that SendMessage has the special code handling WM_COPYDATA (mapping between memory spaces of two processes). It's probably allocating some resources before passing control to target wndproc, and cleans up afterwards. With PostMessage cleanup would be more difficult.
Hm. Cleanup in the target process should not differ, regardless if the original message was queued via SendMessage or PostMessage. It is just cleaned up after it was taken from the message queue.
I suppose the problem is the source process. If you use PostMessage you never know when it is legal to destroy the buffer.
But you are right, obvioulsy there must exist some special handling for WM_COPYDATA in the Win32 message passing system (Win32 subsystem in CSRSS.EXE)
--
Daniel Lohmann
http://www.losoft.de
(Hey, this page is worth looking! You can find some free and handy NT tools there )
|
|
|
|
|
hi all
i'm trying to have an app that kicks off 3 or 4 child apps using CreateProcess() where only one is active at any one time ... i use SuspendThread() to make one stop and then ResumeThread() to make another start ... its all going fine except i cant find a way of telling the suspended thread's window to minimize itself ... am i being dumb or is there another whole approach i should be using to control the starting and stopping of these kiddy processes?
thanks for any pointers
"... and so i said to him ... if it don't dance (or code) and you can't eat it either f**k it or throw it away" sonork: 100.18128 8028finder.com
|
|
|
|
|
I don't think you'll be able to minimize window when its thread is suspended. What kind of applications are these child processes? Are there your apps or 3rd party code?
Tomasz Sowinski -- http://www.shooltz.com
What is "scratch" and why can everything be made from it?
|
|
|
|