|
Yes, if you use not-overlapped I/O. This way the application probably needs an additional thread always waiting for incoming data on the serial line.
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.
[my articles]
|
|
|
|
|
It depends of the timeouts you specified on the comm port. Basically, you can configure your COM port so that it never waits for data (ReadFile returns immediately) or that it blocks forever until some characters have been received, or something in the middle. Check the SetCommTimeouts[^] function.
Anyway working with the serial port is not something easy for a beginner. So expect some frustration because nothing works as expected. But we're to help if needed .
modified on Monday, January 21, 2008 2:37:11 AM
|
|
|
|
|
Try using CMSCommCtrl class . for this you have to add MSCOMM32.ocx control activex control to your project.
|
|
|
|
|
Check Ramon Klein's very nice implementation, he should have an article here on CP and
his web page for updated source code.
|
|
|
|
|
Hello,
I am using a windows hook for keyboard using the command:
SetWindowsHookEx(WH_KEYBOARD, CallWndProcHook_KEY, g_hinstDll,NULL);
which catches all windows's keyboard messages.
my question is how do I find the target window which the the message (WM_KEYDOWN) is being sent to? I want to get the window's handle inside my callback function CallWndProcHook_KEY.
I know its possible because the spy++ presents the message's window.
Can sombody please help me?
Thanks,
T.R.
|
|
|
|
|
I think you have to go through EnumThreadWindows [^] function.
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.
[my articles]
|
|
|
|
|
Thank you,
But I still dont understand: I want to get the specific window which the message WM_KEYDOWN is being sent to.
how do I know which of the EnumThreadWindows retuned windows is the one I want?
Actually, what I am trying to do is to get the caret position from an edit of another application, for example internet explorer, by using the code: HWND hCaret = ::GetForegroundWindow().
Unfortunatly the window which is returned is the iexplorer main window and not it's child window which holds the caret. My idea was to get the inner edit box's handle from the WM_KEYDOWN message that is being sent to it.
Do you have some better idea (I am sure that there must be a much simpler way...)
Thanks very much,
T.R.
|
|
|
|
|
tal1111 wrote: how do I find the target window which the the message (WM_KEYDOWN) is being sent to?
I haven't tested this, but I would guess ::GetFocus() will give you the target window.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hello everyone,
I am new to asynchronous I/O. Could anyone recommend some tutorials for beginners, especially how to handle asynchornous I/O with network input/output.
The set of APIs I want to learn is like CreateIoCompletionPort, GetQueuedCompletionStatus, etc. I can not find related samples from MSDN, so I am wondering if you have any recommended articles.
thanks in advance,
George
|
|
|
|
|
|
Thanks Hamid,
I looked through this article, it is not covering Window Server 2003, but I am using Windows Server 2003.
regards,
George
|
|
|
|
|
|
Perfect, Mark!
regards,
George
|
|
|
|
|
From a standard win32 app, or from an MFC app, how can I execute a command line program and capture its output to a buffer? In my particular case, I want to run perforce's command line tool. e.g.: "p4 dirs //depot/subdir/*".
Any recommendations?
modified on Sunday, January 20, 2008 3:48:23 PM
|
|
|
|
|
If your program writes to console and you want to get that output in buffer
create a bat file similar to this
p4 dirs //depot/subdir/ > C:\sample.txt
instead p4 now spwan the bat file.
after your program is executed you can find all data written in sample.txt
to spwan other apps you can use ShellExecute or CreateProcess functions.
Thanks,
Sandip.
|
|
|
|
|
hi,
i have across a problem that is my program will warn me when executing for the code below
recv_server_thread=AfxBeginThread(recv_server, this);
UINT CTest2Dlg::recv_server(LPVOID param)
{
CTest2Dlg* pp=(CTest2Dlg*)param;
...
pp->m_string_peer="Number of Peers: "+Display_integer;
pp->UpdateData(FALSE);
the program can successfully be compiled,
but when it executes to that position,
it pops a windows "Microsoft Visual C++ Debug Library",
saying "Debug Assertion Failer!,
program: <my prgram..skip="">
File: wincore.cpp
Line: 895 ..."
but if i click skip,
the program can continue to run and update the string correctly.
SO is there any problem i have made?
AND using what program code instead of that I using can solve the problem?
Thank you very much~
|
|
|
|
|
drfankw wrote: AND using what program code instead of that I using can solve the problem?
The correct approach, IMHO, is posting a message to the main dialog, asking the latter to call UpdateData .
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.
[my articles]
|
|
|
|
|
Short answer:
MFC does not work from multiple threads.
Longer:
The HWND -> CWnd mapping is on a per-thread basis, and you have to be VERY careful. I normally use class Win32 stuff in threads, and save MFC for the main thread only.
But you should be very careful when using multiple threads anyway.
Iain.
|
|
|
|
|
Dear all
the following is what i created 10 arrays, how to save these 10 arrays in a file using ofstream? i would like to name each array as 0,1,2,3,..9..late when i wanna use them, i can take it directly. another quession is why here setw(3) is not available? thanks.
#include <iostream>
using std::cout;
using std::endl;
#include <iomanip>
using std::ios;
using std::setw;
using std::fixed;
using std::showpoint;
using std::setprecision;
int main ()
{
double a[3][4];
for (int j = 0; j <10; j++)
{
double a[3][4] = {{(double)rand()/RAND_MAX, (double)rand()/RAND_MAX, (double)rand()/RAND_MAX,( double)rand()/RAND_MAX},{(double)rand()/RAND_MAX,(double)rand()/RAND_MAX,(double)rand()/RAND_MAX,(double)rand()/RAND_MAX},{(double)rand()/RAND_MAX,(double)rand()/RAND_MAX,(double)rand()/RAND_MAX,(double)rand()/RAND_MAX}};
cout<< setw(3)<< "Particle" << setw(3) << j << endl << endl;
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 4; j++)
cout <<setw(3)<< setprecision(6) << fixed << showpoint << a[i][j] << " ";
cout << endl;
}
cout<< endl;
}
}
Li Zhiyuan
5/10/2006
|
|
|
|
|
What is your problem with ofstream ?
As a kick-off hint I suggest you to store your array element values in binary form.
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.
[my articles]
|
|
|
|
|
i would like to use each array of a[3][4] as named for example arry[10],if one condition is right, i will use arry[0]= a[3][4];if another condition is right, i use arry[1] = a[3][4],ihave 10 different arrays.. and so on....because i already got 10 3x4 arrays,....in previous ....
by the way, how to use ofstream to create 10 random arrays? thanks
Li Zhiyuan
5/10/2006
modified on Sunday, January 20, 2008 8:03:11 AM
|
|
|
|
|
li zhiyuan wrote: i would like to use each array of a[3][4] as named for example arry[10],if one condition is right, i will use arry[0]= a[3][4];if another condition is right, i use arry[1] = a[3][4],ihave 10 different arrays.. and so on....because i already got 10 3x4 arrays,....in previous ....
A bit confused. Please explain the requiremnt more clearly.
li zhiyuan wrote: by the way, how to use ofstream to create 10 random arrays? thanks
I guess do you mean serialization , i.e. that you need to store the array content to disk and, later, retrieve the values and build again the array. Aren't you able to perform such task? Why?
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.
[my articles]
|
|
|
|
|
yes, you are right, i just want to build 10 arrays using ofstream, in my whole program, i need to use it and one of friends suggested me i can create such 10 arrays and save them, late if i want to use, just open using ifstream.
which way is better, can you give me another way? how to create 10 3x4 random value arrays using ofstream? thanks
Li Zhiyuan
5/10/2006
|
|
|
|
|
li zhiyuan wrote: one of friends suggested me i can create such 10 arrays and save them, late if i want to use, just open using ifstream
Your friend was right. The above is the right way to go on.
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.
[my articles]
|
|
|
|
|
how to create 10 3x4 random value arrays using ofstream? thanks a lot.
Li Zhiyuan
5/10/2006
|
|
|
|
|