|
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
|
|
|
|
|
Problem solved. Thanks!
-Janetta
|
|
|
|
|
How can I get all key stoke events in my application, not just those
I get when my application window is active?
|
|
|
|
|
See SetWindowsHookEx with parameters WH_KEYBOARD and WH_KEYBOARD_LL.
|
|
|
|
|
I have seen those, but I still don't get it rigth. Can you give
me some example of it?
|
|
|
|
|
1) http://msdn.microsoft.com/msdnmag/issues/0700/Win32/Win320700.asp - example of WH_KEYBOARD_LL hook (works on WinNT and later)
2) Make search in CodeProject for "hook" word in article titles, you will see number of useful articles:
http://www.codeproject.com/dll/keyboardhook.asp, http://www.codeproject.com/dll/hooks.asp
|
|
|
|
|
Hello there,
I just add his classes to my project and i was just wondering when i got a strange error like this:
e:\microsoft visual studio\myprojects\dataentry\ado.cpp(2387) : fatal error C1010: unexpected end of file while looking for precompiled header directive
ado.cpp is his source file ...
What's the wrong ?
Help me, please ...
Regards,
My month article: Game programming by DirectX by Lan Mader.
Please visit in: www.geocities.com/hadi_rezaie/index.html
Hadi Rezaie
|
|
|
|
|
|
Hello,
Thanks for reply ...
I did a kiddy wrong, sorry :P
Thanks alot for your reply ...
My month article: Game programming by DirectX by Lan Mader.
Please visit in: www.geocities.com/hadi_rezaie/index.html
Hadi Rezaie
|
|
|
|
|
Consider declaration :
std::string s1=("command:userID:Password");
I want to separate s1 into three sub std::strings by searching colon ":"
How can i do so ???
|
|
|
|
|
|
Can't get this program to excute.I will be very happy if I can get help with it.I am trying to evaluate the file layout to determine the location and size of the following fields so it would look something like this: 10/06/99,3022362451,1214523251,9:00,23:00,9:00
Date
Origination Number
Destination Number
Call Durtion
Time of Call
Cost of Call
Origination Place(City,State)
Destination Place(City,State)
#include<stdio.h>
void main (void)
{
char student_name [50];
char student_class [50];
char student_id;
char course_name [50];
char student_address[50];
double quiz_grade,quiz_grade1,quiz_grade2,quiz_grade3;
double exam_grade,exam_grade1,exam_grade2,exam_grade3;
double daily_grade,daily_grade1,daily_grade2,daily_grade3;
double
assignment_grade,assignment_grade1,assignment_grade2,assignment_grade3;
double total_points;
}
student_rec student_data [3];
for(i=0.i<3,i++)
{
printf("/n Enter student name");
gets (student_data.student_name);
typedef struct student_rec;
printf("\n Enter class name");
gets(students_data.class_name);
printf("\n Enter student address");
gets(students_data.student_address);
printf("\n Enter class name");
gets(students_data.student_id);
printf("\n Enter Daily grade:");
gets(students_data.Daily_grade1);
printf("\n Enter Daily grade 2:");
gets(students_data.Daily_grade2);
printf("\n Enter Daily Grade 3:");
gets(students_data.daily_grade3 ;
daily_grade= daily_grade1+daily_grade2+daily_grade3/3*.10
printf("\n Enter quiz grade:");
gets(students_data.quiz_grade1);
printf("\n Enter quiz grade 2:");
gets(students_data.quiz_grade2);
printf("\n Enter quiz Grade 3:");
gets(students_data.quiz_grade3 ;
quiz_grade=quiz_grade1+quiz_grade2+quiz_grade3/3*.10
printf("\n Enter Assignment grade:");
gets(students_data.Assignment_grade1);
printf("\n Enter Assignment grade 2:");
gets(students_data.Assignment_grade2);
printf("\n Enter Assignment Grade 3:");
gets(students_data.Assignment_grade3 ;
Assignment_grade=Assignment_grade1+Assignment_grade2+Assignment_grade3/3*.30
printf("\n Enter exam grade:");
gets(students_data.exam_grade1);
printf("\n Enter exam grade 2:");
gets(students_data.exam_grade2);
printf("\n Enter exam Grade 3:");
gets(students_data.exam_grade3 ;
exam_grade=exam_grade1+exam_grade2+exam_grade3/3*.50
total=Assignment_grade+daily_points+quiz_point+exam_points
gets(student_data.total);
}
Can anyone help me finish it.
awillie
|
|
|
|