|
Ahmmm, then this is the point. It was coded at the end of the 90ies. In plain C.
in that programm the datas are sent with
DWORD GetArrayLong( const CByteArray& array, int nOffset )
{
DWORD dwValue = 0;
for( int nIndex = 0; nIndex < sizeof(DWORD); nIndex++ )
dwValue |= ((DWORD) array[nOffset + nIndex] << (nIndex * 8));
return dwValue;
}
But in my programm I send it BYTE per BYTE with
for (i = 0; i < dataSet.GetCount (); i ++)
{
for (j = 0; j < dataSet[nOut].attSet.GetCount(); j ++)
{ byteTemp = dataSet[i].attSet[j].point.x;
pDataBuf = &byteTemp;
file->Write (pDataBuf, sizeof (BYTE));
}
dwActualPos = file->SeekToEnd ();
}
I know that is not elegant but works
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
|
|
|
|
|
AS long as you restrict yourself to 32bit x86 programming, an unsigned long , DWORD and 4 BYTES can all be equivalent. In 'modern' C++ you might use
static const unsigned long PC_MAGIC = 0x23958670;
within a class definition and sizeof(unsigned long); to give you the number of bytes this actually takes up. These days it's wise to consider both 32 and 64 bit scenarios and perhaps even the mysteries of 'byte ordering' and 'endianness', depending on how portable you want your code to be. What fun
Nothing is exactly what it seems but everything with seems can be unpicked.
|
|
|
|
|
I know that your answer is a good answer and you are saying something important, but... I don't understand you right (non english speaker).
The fact is that the programm should work only in the laptops of my firm (all new mashines) and some client computers that buy the application to have the online monitor.
And the only computer that can be a problem for me, is the old project with old C version of these programm because is still working with win95. But my boss wanted it with VC++ 6.0 in order to work with XP for the possible new applications/projects. I know that I have still to find a good programming style and make a lot of changes to have no portability problems. But with short deadlines, the most important thing for my boss is to know that it works with our equipes.
I will rewrite the code in the future to make it international, portable, and some changes I think would be better but my actual boss doesn't want them.
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
|
|
|
|
|
Sorry for the sophomoric nature of this question... I've looked thru an old Stroustrup book, and Googled it and didn't find an answer.
I have a class with three data members. When used in a bare context (no operators surrounding it), I would like the class variable to return the first data member. I can't use the default copy constructor because that is already used for other purposes.
struct myclass{
char *str;
size_t len;
size_t ofst;
};
myclass a1;
char strng[50];
strncpy( strng, a1, 50 );
If str could be made the "default" member, the above line would work. Is this possible?
David
|
|
|
|
|
DQNOK wrote: strncpy( strng, a1, 50 ); //error. should have been
//strncpy(strng, a1.str, 50);
This might work if you had a const char* operator (strncpy() 's second argument type) in your struct .
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Not generically no. What you can do is write a custom cast operator so that when the Compiler attempts to cast your myclass to a char* to match the parameters of strncpy str is used. Something like:-
<br />
<br />
operator char*()<br />
{<br />
return str;<br />
}<br />
<br />
defined within the struct. This is probably not considered 'good' code but as you asked.
Nothing is exactly what it seems but everything with seems can be unpicked.
|
|
|
|
|
I think you nailed it.
In my original post I had started to ask if it was good form, but decided to wait to see if it was even possible. Another poster has directed me to a later Stroustrup book. I'll take a look to see what Mr. Stroustrup says.
Thanks a lot.
David
|
|
|
|
|
Oops; it's a Scott Meyers book, not a Stroustrup book...
|
|
|
|
|
|
Thanks. I had forgotten about user defined type conversions (C++, Stroustrup, 7.3.2)
I don't have the Effective C++ book on hand, and the link doesn't divulge Scott's secrets. Stroustrup discusses some of the issues. Maybe that's enough...
David
|
|
|
|
|
IMHO Meyers work is a "must read".
|
|
|
|
|
I just now ordered it thru Amazon.
|
|
|
|
|
led mike wrote: IMHO Meyers work is a "must read".
Definitely!
Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal. George Orwell, "Keep the Aspidistra Flying", Opening words
|
|
|
|
|
i have made a infrared reciver for computer as part of my project
currently i am using pre build software for testing nd controling but
i need to build a software to contol its functionality and that to in VC++
my Ir device is connected to computer via DB9 female connector and
all i know is that i have to do port programing for controlling it
but i dont know a single command of port programming and VC++ i know C++
plz provide any site any book and help plz
|
|
|
|
|
|
Hi all,
I wrote an editor type program, that uses a dialog box as its main window. I would like the program to return immediately, but the dialog box to remain active. I have tried to use "Create" and "ShowWindow" in the "InitInstance" which works fine, except that the dialog box is immediately destroyed when the program terminates.
How can I achieve this?
Thanks in advance
William
PS
I have already tried "SetParent (NULL)" to change the parent of the dialog to the desktop, but this did not have any effect at all.
W
|
|
|
|
|
Try calling another time your own programm in a second instance (with a m_bAlreadyOpened variable to make a sleep or avoid the return) before returning on the first one.
But what happens to you is totally logical. If the programm ends, the windows disappear. If not, any message called from the dialog would end in an error because there is nothing to answer him, or assertions or something like that.
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
|
|
|
|
|
Consider to write 2 programs or why do you need to habe the dialog if your program terminates?
Greetings from Germany
|
|
|
|
|
William Engberts wrote: I wrote an editor type program, that uses a dialog box as its main window. I would like the program to return immediately, but the dialog box to remain active.
This makes no sense, as the program and the dialog box are one in the same. If one goes away, so does the other.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
True. However, I am looking for something like a normal editor: If I call for example notepad from a command box, I get the editor, but the command box is immediately available again (I immediately get the cursor back), even when the editor is still running. If I use my current program, I can only get my cursor back again in my command box by terminating the program. Therefore I intended to detach the dialog box from the program itself, which woudl enable me to terminate the program and keep the dialog box running. If this is not possible; does anyone have another solution?
Thanks in advance
William
|
|
|
|
|
You need two executables: one to do the launching (using CreateProcess() ), and the other to be launched.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
As David said, you need to use two exe's. In your example you call notepad.exe from the command box, which is cmd.exe. Internaly cmd.exe calls CreateProcess with the path to notepad.exe.
Another method you could try is not close your main window, but simply hide it.
Waldermort
|
|
|
|
|
Hi,
what is different between const char * and const char const *.
|
|
|
|
|
I would like to think the best answer to this question lies in actually coding something up and experimenting with the two to see what can and cannot be done. Has this form of research died off?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
DavidCrow wrote: Has this form of research died off?
Apparently, we're the last generation to know how to do this...
|
|
|
|