|
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?
|
|
|
|
|
hi thomasz
i managed to get them minimizing and stuff by doing a showwindow() before suspending the threads ... im ending them with terminateprocess() which it says in msdn is bad bad bad but it works ok ... unless there is a gotcha waiting for me?
two of the apps are the flash player showing diff movies and the other is an app im writing
another question that is baffling me is how do i get the apps to show on a particular display device in winxp with multiple monitors attached? i cant find anywhere in the createprocess() stuff that lets me specify that
thanks for help
"... 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
|
|
|
|
|
lauren wrote:
i managed to get them minimizing and stuff by doing a showwindow() before suspending the threads ... im ending them with terminateprocess()
er, you may not want to do that... Sounds like a prime way to cultivate memory leaks... maybe it's all good, donno... sounds dangerous though. You couldn't just hide the windows & send them WM_CLOSE messages?
lauren wrote:
another question that is baffling me is how do i get the apps to show on a particular display device in winxp with multiple monitors attached?
Think of it as just having a huge virtual screen, bits of which (not necessarily contiguous bits...) map to actual physical monitors. You can enumerate the available monitors, retreive the bounds for the one you want, and then just position the windows onto it the same way you'd move them around the screen normally.
---
Shog9
If I could sleep forever, I could forget about everything...
|
|
|
|
|
Hi..
I have did some simple graphic (not a bitmap) about texture mapping on a sphere in the CView (using MFC). Now I want to show it in a rectangle frame in a dialog box. I dont want the code anymore in CView but only as a preview in a dialog box. Is there any way to do this? Is there any website I can refer to?
|
|
|
|
|
Derive a class from CWnd and use it as user control in dialog. OnPaint handler should perform the texture mapping or whatever you want to display.
Tomasz Sowinski -- http://www.shooltz.com
What is "scratch" and why can everything be made from it?
|
|
|
|
|
Hi,
Is it possible that CFileDialog interferes somehow (for example due to some mistake) later opening of a file using fopen?
I have a setting dialog and its state can be loaded and saved. I'm using CFileDialog to get the file name and path to be saved/opened and serialization for the loading itself. The setting file is opened from the menu.
The error occurs if I first either load or save the settings and then try to run one thing in my program. In that "one thing" a file is tried to be opened using fopen but the opening fails. If I remove the CFileDialog from loading and use static file name instead when opening a file using CFile the opening succeedes.
Are there some other things that usually interfere fopen?
-Janetta
|
|
|
|
|
Can you check errno variable when fopen fails? This will give you more info on why fopen failed.
Tomasz Sowinski -- http://www.shooltz.com
What is "scratch" and why can everything be made from it?
|
|
|
|
|
Hi,
the CFileDialog changes the current working directory when you select a particular file. Are you using the value of current directory in any way for opening the file?
To prevent this change in the current directory, use the OFN_NOCHANGEDIR flag in the member variable m_ofn of CFileDialog.
HTH
|
|
|
|