|
If that's too "heavy", and onlystdout is needed, a plain call to _popen will do. Example
#include <stdio.h>
#include <stdlib.h>
void main( void )
{
char psBuffer[128];
FILE *chkdsk;
if( (chkdsk = _popen( "dir *.c /on /p", "rt" )) == NULL )
exit( 1 );
while( !feof( chkdsk ) )
{
if( fgets( psBuffer, 128, chkdsk ) != NULL )
printf( psBuffer );
}
printf( "\nProcess returned %d\n", _pclose( chkdsk ) );
}
|
|
|
|
|
good idea, thanks. i will try more once i have time.
cheers.
includeh10
|
|
|
|
|
What is the wrong ?
#include <stdio.h>
#include <conio.h>
#include <iostream.h>
class MyMath
{
public:
friend int Sum(int v1, int v2);
};
int Sum(int v1, int v2)
{
return v1 + v2;
}
void main()
{
MyMath obj;
cout << "Result: " << obj.Sum(1, 3);
_getch();
}
My month article: Game programming by DirectX by Lan Mader.
Please visit in: www.geocities.com/hadi_rezaie/index.html
Hadi Rezaie
|
|
|
|
|
Your MyMath class's Sum function is public to other classes so there is not need to declare it as friend. And you can declare the method as friend if you are writing a class template(generating new classes depending upon what type of parameters you pass to the function). In your code I do not see a reason for declaring it as a friend or also it not possible to declare it as a friend.
Einstein's Assistant
|
|
|
|
|
Hi.
I have uploaded my whole application in my temp. yahoo account. I could not locate the source of memory leak. Please help me to pin point source of serious memory leak. I have uploaded a zip file in the yahoo briefcase.
Yahoo details
userid : moswal0071
password : cooldude
Thanx in advance.
Einstein's Assistant
|
|
|
|
|
Can anyone provide an example of a circular queue in C? I've never used one before and researching on the net has shown a whole host of approaches of which I think have alot of overhead.
1) I don't want to and can't use STL since this is a C program.
2) All examples I've seen use data structures like a linked list with "next" pointers and one of the attributes is the data itself.
3) They also have all of the functions which add, delete, check for empty, etc. but I don't want to spend the time doing this for the reason specified below. I don't want to call functions but do this on the fly as I add or remove data from the queue.
4) I'm reading from a serial port at 115k baud in a read thread and don't have any time to format the data so I would like to do a memcopy to an array or circular buffer so it must be contiguous but then there is the wraparound problem I'm aware of. Worst case, a for loop. I will process or format the data into it's proper format in another thread which will access this circular queue as the read thread is putting data into it.
5) Shouldn't it be as simple as a char array of certain size with two char pointers; one to head and one to tail? I know how to see if the queue is empty but how do I detected overrun? If detecting overrun is simply is head > tail then what about when I wrap around to the beginning of the buffer?
Any code examples and suggestions would be appreciated.
John
|
|
|
|
|
I imagine most modern programs use FIFO linked lists for the reason you state -- data overruns. With a circular queue you have one of two choices to make: either overwrite existing data or discard new data until some function removes data from the queue. The programs I wrote discarded the data because overwriting existing data usually renders the contents of the entire queue useless. You need to make your circular queue large enough to handle most situations which largly depends upon how frequently data is removed from the queue. You need four pointers, not just two. Head & tail for incoming data and head & tail for outgoing data. Maintaining these four pointers is actually as much if not more overhead then a simple linked list with just a next pointer.
|
|
|
|
|
The basic circular buffer is as you describe in point 5. Maintain two numbers, Read and Write which correspond to the read and write locations within the buffer. You can then use array notation rather than pointers which makes the arithmetic more intuitive.
Let's use recording audio as an example. The soundcard driver gives you regular buffers of data. Simply copy this into your circular buffer at the write position. To make wrapping arithmetic easy (and also ensuring only one memcpy is needed per iteration), make the size of your circular buffer a multiple of the size of the buffers the soundcard provides. For example, if the soundcard gives you 1024 sample buffers, make the circular buffer 16384 samples long.
Decide what rate you want to read data from the circular buffer e.g. in 8192 blocks. Then when you write to the circular buffer firstly update the write location and then check to see if the difference between read and write is >= 8192 (easy way to do this is to add the size of the circular buffer to each location and then take the difference). If it is, then signal your read thread to read the fresh data (and update your read pointer). This is easier than getting your read thread to continuosly poll thus leaving it more time to finish the formatting. Everytime you change the read or write values, make sure you use modulo arithmetic:
Write+=1024;
Write%=16384;
Read+=8192;
Read%=16384;
Hopefully, you shouldn't have problems with overrun since you're forcing a read when data is available. Experiment with buffer sizes to find the most efficient way. With audio, it's good to have small buffers since you get low latency, in your case it may not be necessary; bigger buffers put less strain on the CPU.
Hope this is useful.
|
|
|
|
|
Thanks, guys for the suggestions. I think I have it done now. I still need to test it with a max load of data. I kept my buffers kind of small because of the application. I wanted to timestamp each 8, 14, or 32 byte message with a unique timestamp in msecs. However, legacy software only supports resolution to 10ths of a second.
Consequently, I used a small receive buffer of 128 bytes and a circular buffer of 1024 bytes. Though, I won't be able to maintain the millisecond accuracy, it should be fine for 10ths of a second.
I wrote it so that the read thread calls SetEvent() in which the process thread waits infinitely for. So, it doesn't poll and only gets used if there is data to process.
I found a pretty good example online of a C++ class that implemented a circular queue and I converted it to C. The thing I like about this one is that the front or head is always one position less then where the data actually begins making it easier to detect when the queue is full. Of course, that means one element in the queue is not used or 1023 of 1024 elements are used.
And as one of you wrote, I decided to discard any data if the processing thread couldn't keep up.
I'm still experimenting around but as its set up now the read thread is at a priority of 15 while the process thread is set to 15 when WaitingForMultipleObjects() but 17 when it gets control. Do you guys have any advice on this or does that sound normal?
Thanks again.
|
|
|
|
|
Hi. I am using the windows XP-style controls (commctl32 version 6). In this, the tab control's "client area" is colored differently from the background, and is not a single color. So, when I put a control on top, such as the label (static) control, or a radio button, the dialog background fills the area of the control, making it look rectangular and ugly. Is there any way to make the text of my controls transparent rather than opaque, so that I can avoid this problem?
Thank you.
- Andy Oxfeld (andy@serialgaming.com)
|
|
|
|
|
I need to create "Help Topics" for each of my WinCE application programs that run on PocketPC 2002 using eVC++ 3.0 compiler. On desktop programs use WinHelp.exe, but that program does not exist on the PPC device. Does anyone know how to do this?
|
|
|
|
|
|
Can someone show me where I can find an example to write a program that will have multi language gui. For example user will select the language that he wants and gui will be in that language
Thank you
Orcun Colak
|
|
|
|
|
I suppose you'd use multiple resource-bearing files,
one for each language, and then use AfxSetResourceHandle
to specify which to use. Then make sure to code your
project with no inlined strings-- everything from the
resources.
Here's some google results:
TN057, Q147149, over at Microsoft
http://www.codeguru.com/misc/MultiLang.shtml
http://www.eanet.cz/~lvanek/develop/windows/international/international.htm
I love search engines.
|
|
|
|
|
I'm having a problem with MessageBox(). I am creating a thread to interact with a device driver and if the driver is not loaded/started, I'm trying to display a message to the user. All that happens is that the message box pops up for a second.
The return is 1 (IDOK) and GetLastError is 0 (I called SetLastError(0) before MessageBox).
I'm calling:
::MessageBox (NULL, (LPCTSTR)lpMsgBuf, "Error", MB_OK | MB_ICONINFORMATION);
Thanks for the help,
David
|
|
|
|
|
|
Anyone knows how to deal with ghost windows in XP? How to get rid of the ghost windows in windows XP system with Platform SDK? Thanks.
Windows XP: If a top-level window stops responding to messages for more than several seconds, the system considers the window to be hung and replaces it with a ghost window that has the same Z order, location, size, and visual attributes. This allows the user to move it, resize it, or even close the application. However, these are the only actions available because the application is actually hung. When in the debugger mode, the system does not generate a ghost window.
reference from MSDN.
mIchAel Liu
|
|
|
|
|
Until you learn to write a subject line that is
1 - not an attempt at giving me/us an ORDER and
2 - learn to not fill it with completely annoying characters;
I have but one advice for you: Have a nice day, go play on the highway.
|
|
|
|
|
Did you try FindWindow?
Apparently, no one knows the answer since you've posted this at least 3 times already. Look in newsgroups.
Jason Henderson quasi-homepage articles "Like it or not, I'm right!"
|
|
|
|
|
why not fix the hang? I happen to like the ability to close programs that are misbehaving!
|
|
|
|
|
Hi. I am trying to create a configuration dialog for an application I am writing. It is (or at least will be) fairly complex, so I cannot fit all the configuration options in one dialog. So, I made the configuration dialog have a list box on the left side of the window, which lists different "sections" of the application. Depending on which section you have selected in the list box, the options on the right side of the dialog change.
One way I could have done this would have been to put all the controls for all the sections in the same dialog, and use ShowWindow() to show some and hide others depending on what is selected in the list box. I've done this before, and it's a big hassle. So, this time, I thought I would put the controls for each section into their own dialogs. I could then would only have to show and hide the dialogs. The dialogs would be child windows of the main configuration dialog.
To test this idea, I made the configuration dialog, which only has the list box, and "Ok" and "Cancel" buttons. The list box does nothing right now. In response to WM_INITDIALOG, it uses CreateDialog() to make the child dialog (and there's only 1 right now). I made a test child dialog which only consists of a few buttons, which do nothing. However, I am getting a weird issue when you click the buttons... after clicking them, they get thick, like a default button does, and stay that way.
To make it easier to understand what I'm saying, I made a little webpage with pictures demonstrating what happens when you click the buttons:
http://serialgaming.com:8080/nnirc/
I also tried deleting the manifest and using regular Windows95 buttons, and the same problem occurs.
I have spent many, many hours trying to get this working. I've looked throughout the web (including things on this website), but the only programs I could find which did something similar to mine were written in MFC (I'm not using MFC.)
Here's the code I'm using to create the dialogs:
To create the main, modal configuration dialog:
DialogBox(hInst, MAKEINTRESOURCE(IDD_CONFIGURE), hWnd, ConfigureDlgProc);
To create the child, modeless dialog (this is in WM_INITDIALOG of ConfigureDlgProc):
hDlg = CreateDialog((HINSTANCE)hInst, MAKEINTRESOURCE(IDD_TEST), hWnd, TestDlgProc);
ShowWindow(hDlg, SW_SHOW);
Here is the child modeless dialog's window procedure:
BOOL CALLBACK TestDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_INITDIALOG:
return true;
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDOK:
EndDialog(hWnd, IDOK);
break;
case IDCANCEL:
EndDialog(hWnd, IDCANCEL);
break;
}
break;
}
return false;
}
If you have any idea what's wrong, I'd really appreciate it. This has really baffled me more than any other problem I've ever had programming. Or, alternatively, if you have non-MFC source for a program that does something similar, I'd really appreciate it if you can show it to me.
Thank you for the help.
- Andy Oxfeld (andy@serialgaming.com)
|
|
|
|
|
I have been trying to create a reportview list control in MFC using the control toolbox and placing the list control on a dialog form, with the inbsertcolumn type function with the index parameter as zero. But I get two columns! One with my title specified, and one with no title. I only want one column to show up in my report view style list control. I hope its possible.....
|
|
|
|
|
Have you tried to just set the text for the first column? IIRC you always get one column, and if you add another column it would be obvious you see what you see.
Just an idea.
|
|
|
|
|
Heres what I'm using to set the column header:
m_list1.InsertColumn(0,"dir",LVCFMT_LEFT,70);
and to insert:
nItem = m_list1.InsertItem(0,str);
So how to set the column header and yet have only 1 column? If you put index as -1, it doesnt show up at all...
If you dont set the column header with insertcolumn, you cant populate with insertitem....nothing shows up in the box!
Thanks!
|
|
|
|
|
The second one is not a column, it's just the space not used by the first column. To correct, just resize the first column to fill all available space:
m_list1.SetColumnWidth(0, LVSCW_AUTOSIZE_USEHEADER);
Of course, if you resize your list, you'll then need to alter the size of the column also.
--------
Have you hugged your monitor today? --Shog9 --
|
|
|
|
|