|
I am not able to understand your design, do you want to have worker thread active all the time and do you want to create workerthread everytime request came
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
I am fully confused.. Again I am explaining you...This is my problem.
I have a file(let us say 5MB size). I need to send this file over serial port to a client.
As I can't send whole file at a time, I am reading the file into a structure(let us say 50 bytes), and sending.
After receiving 50 bytes of data the client will send back some acknowledgment. If acknowledgment is proper, I will send the next 50 bytes of data. Otherwise I will send the previous 50 bytes of data.
So this cycle repeats until the end of the file.
Now tell me how can I proceed. Am I going in a right path.
Thanks in advance
msr_codeproject
|
|
|
|
|
msr_codeproject wrote: Am I going in a right path.
Sounds like it. I would opt for synchronous communication so that the "send" and "receive" packets match up. Asynchronous communication would allow them to happen concurrently.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
#include <iostream.h>
I want to print the "helloworld" but it print "hell" ,why??
void show( char str[])
{
for (int i=0; i < sizeof(str)/sizeof(str[0]); ++i)
cout << str[i];
}
int main()
{
char str[]="helloworld!";
show(str);
return 0;
}
|
|
|
|
|
wbgxx wrote: I want to print the "helloworld" but it print "hell" ,why??
Because the size of a pointer is 4. Try strlen() instead.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
'str' is a pointer.
sizeof a pointer is 4 (on Win32). so you get four characters: h,e,l,l.
if you want to get the length of a character string, use strlen .
|
|
|
|
|
wbgxx wrote: void show( char str[])
{
for (int i=0; i < sizeof(str)/sizeof(str[0]); ++i)
cout << str[i];
}
This code is the same as this:
void show(char *str)
{
for (int i=0; i < sizeof(str)/sizeof(str[0]); ++i)
cout << str[i];
}
The array decays to a pointer. The size of a pointer is 4 bytes and the size of a char is 1.
Steve
|
|
|
|
|
It's worth noting this way it would work:
void show( char str[], int size)
{
for (int i=0; i < size; ++i)
cout << str[i];
}
int main()
{
char str[]="helloworld!";
show(str, sizeof(str)/sizeof(str[0]));
return 0;
}
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Yeah, thanks for advantage!
|
|
|
|
|
Here's another alternative (MSVC6 can't handle it):
void show(const char *pStr, int size)
{
for (int i=0; i<size; ++i)
{
cout << pStr[i];
}
}
template <int N>
inline
void show(const char (&a)[N])
{
show(a, N-1);
}
int _tmain(int argc, _TCHAR* argv[])
{
char str[] = "Hello world!";
show(str);
cout << endl;
return 0;
}
Steve
|
|
|
|
|
Interesting example, Steve. In your example, does the compiler set N to 12 or 13? I ask because the for loop increments i up to but not including the size, but your template function call passes the value of N-1 to the function. So characters 0-11, all 12 of them, would only be output if the value of N was set to 13. 13 being the 'correct' size when you include the NULL terminator as part of the size of the string. Just an interesting little difference from a lot of the std C string functions.
On a side note, is it the array reference that MSVC6 doesn't like or something about the template function declaration?
Chris Meech
I am Canadian. [heard in a local bar]
In theory there is no difference between theory and practice. In practice there is. [Yogi Berra]
|
|
|
|
|
Chris Meech wrote: Interesting example, Steve. In your example, does the compiler set N to 12 or 13? I ask because the for loop increments i up to but not including the size, but your template function call passes the value of N-1 to the function. So characters 0-11, all 12 of them, would only be output if the value of N was set to 13. 13 being the 'correct' size when you include the NULL terminator as part of the size of the string. Just an interesting little difference from a lot of the std C string functions.
Mine (VS 2010) puts (as it should) 13 .
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
You don't need the loop at all. cout is savvy enough to know where your string ends. Unless there's some other reason for the loop then your show() function is simply:
void show( char str[] )
{
cout << str;
}
Although in C/C++ we tend to use pointer notation:
void show (char* str)
{
cout << str;
}
And now, given that your function is doing so little you might question its usefulness and move the code into main:
int main()
{
char str[] = "helloworld!";
cout << str;
return 0;
}
Or, finally, you might prefer to use a string constant:
int main()
{
cout << "helloworld!";
return 0;
}
None of which is particularly useful if all you wanted to know is why sizeof() returned 4.
|
|
|
|
|
I assumed printing a string was used as an example of the general problem of passing an array and determining its size automatically.
Steve
|
|
|
|
|
Hello people!
Yes, i was stupid enough to use the "Data Exchange and validation" method of MFC (UpdateData, CDialog::DoDataExchange and co.) and now i have to suffer the consequences. Is there a way to easily retrieve the values the user entered into the edit fields with this BUT do not let DDX do validation, or at least do it silently. What i did was to create a few dialogs with a whole bunch of edit controls on them that let the user hammer in all kinds of data, mostly numbers, when the OK button is hit, i called UpdateData to move the user's entries into integer values and then check these for correctness and display a message box if something's wrong. This works ok as long as the user entered something into the edit fields, but if the user leaves one empty, then during the Dataexchange process a nice little "Please enter an integer" message box is spit up, after dismissing this the user gets my own message. I googled around and found only solutions like:
-don't use DDX at all (I really don't like DDX, now i wonder why i thought i would use it now, probably because it seemd faster to implement than having to manually retrieve entries and convert them to needed types...)
-don't use integers, use CString-s to get the data and then convert to numbers yourself...
-use CEdit instead of simple data members and retrieve the value using GetWindowText and then convert to number
-before calling DoDataExhcnage put a "0" into every numeric edit field on the dialog that is empty
All of these might work but they all require a lot of "rewriting the whole thing" which i would like to avoid if possible, so my question is: does anyone of you know of any way to make DDX retrieve values from the controls silently, so without throwing up message boxes and stopping after the first problem it hits? DDX should be way more flexible then this...nice one MS...
Thanks in advance.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Sometimes you just have to hate coding to do it well. <
|
|
|
|
|
You could use the returned value by UpdataData(TRUE)
to leave CYourDialog::OnOK() if it (the value) is FALSE
virtual void BeHappy() = 0;
|
|
|
|
|
Thanks for your answer, however, i believe you don't understand the problem. What i want is UpdateData to not display any message boxes about errors during validation, it would be best if it would just simply move values from the edit controls to the data members silently, if it hits a problem, it can default to 0 or somehow report back at which edit it hit the problem so one can display customized error messages...
Guess i will have to try and give some custom implementation for DDX...
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Sometimes you just have to hate coding to do it well. <
|
|
|
|
|
OK
Just define your own macro DDX_CheckNumEditControl(pDX, IDC, iVar) ,
that does fill an empty edit box by the value of the variable,
if (TRUE == pDX->m_bSaveAndValidate),
and set it above the exchange line of the box
virtual void BeHappy() = 0;
|
|
|
|
|
Yes, i'm already doing this, disapointing how the DDX system is so non-configurable when it comes to validation... thank you.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Sometimes you just have to hate coding to do it well. <
|
|
|
|
|
You can easily write your own DDX_* function to do validation.
This can be an option for you if all your fields are of the same type. Otherwise you will still end up with a lot of different functions you must implement. The easiest way to to do this is to set a breakpoint on your current DDX_* function call, step in and see what it does. Then write your own handler with your own error handling. This is mostly copy&paste work. I have done this many times, not having your problem, but e.g to get user data from a selected row in a CList and such.
|
|
|
|
|
Thank you for your reply, i am already in the process of doing this, it is really disapointing how the "original" DDX system is non-configurable when it comes to "what to do when validating"...
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Sometimes you just have to hate coding to do it well. <
|
|
|
|
|
Code-o-mat wrote: What i did was to create a few dialogs with a whole bunch of edit controls on them that let the user hammer in all kinds of data, mostly numbers, when the OK button is hit, i called UpdateData to move the user's entries into integer values and then check these for correctness and display a message box if something's wrong. This works ok as long as the user entered something into the edit fields, but if the user leaves one empty, then during the Dataexchange process a nice little "Please enter an integer" message box is spit up...
While not a direct solution to your problem, you should consider disabling the OK button until all the edit controls are non-empty. This works for other controls, too. You can ensure that items in comboboxes and listboxes have been selected, checkboxes have been checked, etc, all before enabling the OK button.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
Code-o-mat wrote: before calling DoDataExhcnage put a "0" into every numeric edit field on the dialog that is empty
Unless 0 (zero) is a valid input.
Watched code never compiles.
|
|
|
|
|
Hi,
My application requires printing of data on different printers.
Is it possible to ensure that after a printer has been chosen (that may not be the default printer), the print layout is in Landscape mode?
I have looked at examples from MSDN, mfcdvmdvcnet.exe (I can't remember the Q number), but that seems oriented to using the default printer, whereas I want to ensure that after printer selection the print format is landscape using the DEVMODE structure.
EDITTED TO ADD - is there also anyway to detect the name of the chosen printer after it has been selected if it is not the default printer?
EDITTED TO CLARIFY - I have two printers, printer1 - the default A4 printer, and printer2 - my A3 printer. When I print I want to select printer2 and set it to be Landscape. How do I, using EnumPrinters or an alternative, get the name of the now selected printer, printer2, and change the DEVMODE to ensure that Landscape is used?
If anyone has a pointer to some code, or an article, that would be great.
TIA
Tony
modified on Wednesday, April 14, 2010 6:06 AM
|
|
|
|
|
maycockt wrote: EDITTED TO ADD - is there also anyway to detect the name of the chosen printer after it has been selected if it is not the default printer?
Are you using PrintDlg() for this? If so, look at the hDevNames member of the PRINTDLG structure.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|