|
helpcode wrote: en i need to END-TASK the application. Here i want to increase the priority of SC_MAXIMIZE message. How can i do it? please help me ..
actually your main thread is calling the Function Thread, which seems to performing long function.. thats why it making the main thread hung!.. so better you try MultiThreading program! for that you have to implement some callback mechanism for same!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
The UI looks hung because messages have to actually be processed by the UI thread. While the thread is running code in the DLL, it's not processing messages in the queue. Changing to a multi-threaded design is often the best way to solve this problem.
|
|
|
|
|
hi all,
i am having one problem with threading
i created one dialog based application whose work is to read the data from serial port and display it.so i created one thred for this work.
means now i got two threads one is application thread and other is serial communication thread which is created in OnInitDialog.
now everything is working i mean the thread got created it read some bytes
from port and now it wants to show the data so need to send this data to main
thread. so i am doing this with ::SendMessage() but it is giving access violation. i don't know why this is happening and currently i am not sending the data also i.e. buffer so please help me
below is code (stepwise)
1)In Oninitdialog
THREADPARAM *ptp = new THREADPARAM;
if(ptp)
{
memset(ptp->array,0,30);
strcpy(ptp->array,"Harshal");
ptp->appHandle = this->m_hWnd;
hSerialThread = CreateThread( NULL,
0,
(LPTHREAD_START_ROUTINE) SerialCommunication,
(LPVOID) NULL,
0,
&dwSerialThreadID);
}
2)Thread function
UINT SerialCommunication(LPVOID pParam)
{
int write_req=0;
THREADPARAM *ptp = (THREADPARAM *)pParam;
while(1)
{
if(write_req == 2)// send write request and read it
{
DWORD length=0;
DWORD dwRead=0;
if (WriteFile(hCom,
SEND_CMD, // pointer to data to write to file
NOOFBYTE, // number of bytes to write
&length, // pointer to number of bytes written
NULL) == 0)
{// write failed
write_req = 0;
continue;
}
// writefile succeeded issue readfile
char buffer[MAX_MESSAGE];
memset(buffer,0,MAX_MESSAGE);
if (!ReadFile(hCom, buffer, MAX_MESSAGE, &dwRead, NULL))
{
write_req = 0;
continue;
}
if(dwRead > 0)
{
//MessageBox(NULL,buffer,"Data with packet",MB_OK);
::SendMessage(ptp->appHandle,MY_SHOW_DATA,0,0);// error is here
}
write_req = 0;
}
else // only read from port and increment counter
{
DWORD dwRead=0;
char buffer[MAX_MESSAGE];
memset(buffer,0,MAX_MESSAGE);
if (!ReadFile(hCom, buffer, MAX_MESSAGE, &dwRead, NULL))
{
write_req++;
continue;
}
if(dwRead > 0)
{// you are in thread you need to send message to
// main application
//char a;
HWND hwnd = (HWND)AfxGetApp()->m_pMainWindow;
::SendMessage(ptp->appHandle,MY_SHOW_DATA,0,0);
//MessageBox(NULL,buffer,"Data without packet",MB_OK);
}
write_req++;
}
}
return 0;
}
3) Sent message function
LRESULT CReadDataDlg::OnShowDataMessage(UINT wParam, LONG lParam)
{
return 0;
}
Thanks and regards
Harshal
|
|
|
|
|
harsha_1234 wrote: ::SendMessage(ptp->appHandle,MY_SHOW_DATA,0,0);
Use PostMessage() instead of SendMessage.. and look for difference between PostMessage and SendMessage in MSDN!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
From the 'serial port reader' thread I would place the data into a thread-safe queue of some sort and notify the 'display' thread that new data is available. The 'display' thread can pull it out of the queue and format as appropriate.
Any sufficiently gross incompetence is nearly indistinguishable from malice.
|
|
|
|
|
Hi, I am reading some float value from a file.
Code:
char tScaleLow[8],tScaleHigh[8],tAlarmLow[8],tAlarmHigh[8];
cfTag.Read(tScaleLow,sizeof(float));
cfTag.Read(tScaleHigh,sizeof(float));
cfTag.Read(tAlarmLow,sizeof(float));
cfTag.Read(tAlarmHigh,sizeof(float));
This is my code it reads the value fine.But the drawback is it reads only 4 characters i.e, if ScaleHigh is 100000 it reads only 1000.
So, i changed the code as follow...
float fScaleLow,fScaleHigh,fAlarmLow,fAlarmHigh;
cfTag.Read(&fScaleLow,sizeof(float));
cfTag.Read(&fScaleHigh,sizeof(float));
cfTag.Read(&fAlarmLow,sizeof(float));
cfTag.Read(&fAlarmHigh,sizeof(float));
This reads some garbage value like 6.002e+102 like this,all the four things reads like this.
Whats the wrong in my code?Or is there any way to read all values in that previous code.
Anu
|
|
|
|
|
Anu_Bala wrote: reads only 4 characters
That's because you are passing the sizeof(float) which is 4 on windows platform.
The second parameter for Read() - The maximum number of bytes to be read from the file. This is four and so it reads four.
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
Yes,
Any solution for this?
Anu
|
|
|
|
|
After each value that you write in a file put a comma ',' as a delimiter.Split the string of the file based on that ','.
Another option would be to read and write the full structure at a time and get/set the values in the file.(Use fread in this case)
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
Can u tell me why its not read in this code..
float fScaleLow,fScaleHigh,fAlarmLow,fAlarmHigh;
cfTag.Read(&fScaleLow,sizeof(float));
cfTag.Read(&fScaleHigh,sizeof(float));
cfTag.Read(&fAlarmLow,sizeof(float));
cfTag.Read(&fAlarmHigh,sizeof(float));
its read the wrong value..
Pls..
Anu
|
|
|
|
|
As it seems, the value in the file is a string.
If that is the case (and cfTag.Read is a functions to read a string from a file into a given char array), you are using it wrong. You should probably use something around the lines of (thats a guess):
char tScaleLow[TSCALELENGTH]; and<br />
cfTag.Read(tScaleLow,sizeof(char) * TSCALELENGTH);
Actually, without a definition of cfTag.Read, there is no way to tell what you are doing wrong, but I really suspect wrong use of "Read" to be the reason.
Cheers,
Sebastian
--
Contra vim mortem non est medicamen in hortem.
|
|
|
|
|
Hi all,
I hope you can give me a hint or help about a debugging issue.
Out of a minidump I got from a release build, the problem showed as follows:
The stack in VC++ debugger when opening the .dmp file, showed:
0x00000000
and nothing else. EIP of course also contained NULL.
I then looked at the ESP address to see the stack. There I found the jump-back address to see where the code would continue if the jump that now occurred to 0x00000000 would have been successful.
The C++ code there looks like the following:
if (variable && variable->SomeFunction() && .....)
"variable" is a pointer to an object of a class.
The question now is, how can I debug that further. Did "variable" maybe not contain - for some reason - a pointer to an object of the class it should point to where the offset to ->SomeFunction() would be NULL ?
Any idea how, for the next iteration of the release software, some code could be added to give more information about the problem - if it still crashes there ?
Thanks for any help,
Manfred
|
|
|
|
|
|
Well, I guess this won't help me when the EIP actually jumped to 00000000
I used the PDB anyway which got me enough information to find the code where the offending jump occured.
icke
|
|
|
|
|
Hi all,
all the links that appear in CRichEdit Ctrl are based on the window scheme i am using.
is there a way to tell the rich edit that all my link will apear in a blue color regardless the window scheme i am using?
thanks in advanced
Yaron
Interface basics click here :
http://www.codeproject.com/com/COMBasics.asp
don't forget to vote
|
|
|
|
|
Hi all,
i play a sound using:
PlaySound(MAKEINTRESOURCE(IDR_WAVE),AfxGetInstanceHandle(),SND_PURGE | SND_RESOURCE | SND_ASYNC);
i stop this sound using:
PlaySound(NULL,AfxGetInstanceHandle(),SND_PURGE | SND_RESOURCE | SND_ASYNC);
But when i call the above line again (PlaySound with NULL), the sound is being played again
is there a way to avoid this problem?
thanks
Yaron
Interface basics click here :
http://www.codeproject.com/com/COMBasics.asp
don't forget to vote
|
|
|
|
|
If you run PlaySound(null,SND_PURGE); whats happen?
|
|
|
|
|
you mean exactly as you wrote? hmm didn't give it a try , will do and let u know
thanks
Yaron
Interface basics click here :
http://www.codeproject.com/com/COMBasics.asp
don't forget to vote
|
|
|
|
|
WhiteSky wrote: If you run PlaySound(null,SND_PURGE);whats happen?
Where's the third argument?
"Talent without discipline is like an octopus on roller skates. There's plenty of movement, but you never know if it's going to be forward, backwards, or sideways." - H. Jackson Brown, Jr.
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Hi DavidCrow
wow David do you remember when i said to you one thing in The Lounge my guess was right but you said no but i said its fact .PlaySound(NULL,NULL,SND_PURGE);
|
|
|
|
|
WhiteSky wrote: David do you remember when i said to you one thing in The Lounge...
Are you referring to this? If so, I fail to see your point.
WhiteSky wrote: ...my guess was right...
About what?
WhiteSky wrote: PlaySound(NULL,NULL,SND_PURGE);
In your reply here, you only provided two arguments to PlaySound(). I "corrected" you by asking about the missing argument. What part of that did you not understand?
"Talent without discipline is like an octopus on roller skates. There's plenty of movement, but you never know if it's going to be forward, backwards, or sideways." - H. Jackson Brown, Jr.
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
I underestood your answer and got it ok and thanks.
--------------------
yes,you see a right point but Im wondering for a new thing the date from that message is 20 Jul and now is 5 Sep about two months ago it past very fast
|
|
|
|
|
hi all,
again i got this error
error LNK2001: unresolved external symbol _strnicmp
which library to link ?
plz help me
regards
venu
|
|
|
|
|
Hi,
good question ...
a) libc.lib -> single threaded, static link
b) libcmt.lib -> multithreaded, static link
c) msvcrt.lib -> multithreaded, dynamic link
and for debugging versions
libcd.lib
libcmtd.lib
msvcrtd.lib
HTH
Frank
|
|
|
|
|
hi Frank,
thank you for reply..
still i am getting this error
fatal error LNK1104: cannot open file libcd.lib
fatal error LNK1104: cannot open file libcmtd.lib
fatal error LNK1104: cannot open file 'msvcrtd.lib
do i need to add any include path ?
regards
venu
|
|
|
|
|