|
You don't need any tool, just use NAPI
|
|
|
|
|
If an API is not a tool, then please tell us what it is?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"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
|
|
|
|
|
I am learning to use VS2005 to create a VC++ MFC project to read from the serial port using the 'ReadFile' function. in particular I am having problems getting the code to compile 'ReadFile' parameter 4:
h-file
...
DWORD ActualBytesRead
DWORD * pActualBytesRead
...
cpp-file
attempt 1:
pActualBytesRead = &ActualBytesRead
ReadFileStatus = ReadFile(SerialPortHandle, &ReceiverBuffer, NumberOfBytes2Read, pActualBytesRead, NULL)
-compiles, but parameter 4 ends up with 0xbaadF00d at the time of the 'ReadFile' call?
attempt 2:
ReadFileStatus = ReadFile(SerialPortHandle, &ReceiverBuffer, NumberOfBytes2Read, &ActualBytesRead, NULL)
-compiles (passing by reference?)
attempt 3:
pActualBytesRead = &ActualBytesRead
ReadFileStatus = ReadFile(SerialPortHandle, &ReceiverBuffer, NumberOfBytes2Read, *pActualBytesRead, NULL)
-won't compile?
OK, so I have a version of code that compiles but I don't really understand why attempt 1 & 3 fail?
modified on Tuesday, September 8, 2009 11:06 AM
|
|
|
|
|
1 and 3 fails because you're passing a DWORD** instead of DWORD* .
The following should compile.
DWORD ActualBytesRead = 0;
BYTES ReceiverBuffer[1024];
DWORD NumberOfBytes2Read = 1024;
ReadFileStatus = ReadFile(SerialPortHandle, ReceiverBuffer, NumberOfBytes2Read, &ActualBytesRead, NULL);
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
«_Superman_» wrote: 1 and 3 fails because you're passing a DWORD** instead of DWORD*.
Actually, in the first case he is passing a DWORD* (so this should compile) and in the third case he is passing a DWORD.
|
|
|
|
|
GC104 wrote: ReadFileStatus = ReadFile(SerialPortHandle, &ReceiverBuffer, NumberOfBytes2Read, pActualBytesRead, NULL)
-won't compile, even though I am passing a pointer to a 'DWORD'?
This compiles for me.
GC104 wrote: ReadFileStatus = ReadFile(SerialPortHandle, &ReceiverBuffer, NumberOfBytes2Read, *pActualBytesRead, NULL)
-won't compile?
Because argument 4 is the contents, or value, of pActualBytesRead .
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"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
|
|
|
|
|
Since posting the original message, I would expect attempt 1 to compile. Is this likely to be a quirk in the VS2005 VC++ compiler? Many thanks for thoughts.
Geoff
|
|
|
|
|
Without seeing the actual error message, I've no idea.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"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
|
|
|
|
|
Sorry, I made a typo whilst trying 'attempt 1'. Yolu're right it does compile, the problem is that pActualBytesRead gets loaded with 0xbaadf00d prior to the 'ReadFile' call.
Thanks for help
|
|
|
|
|
Hi,
I try to get the current position of pointer in the stream (IStream interface) with the method Seek (IStream::Seek Method) but i can't succeed to do this.
So can someone help me how to do this OR if there is an other method to get the current position from this stream?
thank you
|
|
|
|
|
Ummm - try this:
ULARGE_INTEGER currPos;
LARGE_INTEGER offset;
offset.QuadPart = 0;
istreamInterfacePointer->Seek(offset, STREAM_SEEK_CUR, &currPos);
Zero offset from the current position will be the current position...
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Thank you , it work
can you please help me again and tell me how can use Seek to get the size of the current stream ?
thanks
|
|
|
|
|
ULARGE_INTEGER currPos;
LARGE_INTEGER offset;
offset.QuadPart = 0;
istreamInterfacePointer->Seek(offset, STREAM_SEEK_END, &currPos);
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Hi to All,
I need help in understanding the difference between copy constructor and assignment operator, and when do we use them exactly,...and with contrast of shallow and deep copy too.
I tried to understand from internet, but still I didn't get a clear picture of it.
Could someone please put some light for the same.
Thanks in advance.
-----------------------------
I am a beginner
|
|
|
|
|
MyClass a;
MyClass b(a);
MyClass c = b;
MyClass d;
d = c;
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
thanks,
But when do we overload each of them?...I mean when do we use copy constructor and when assignment operator
-----------------------------
I am a beginner
|
|
|
|
|
hrishiS wrote: I mean when do we use copy constructor and when assignment operator
In the vast majority of cases, you have to do both of them. I never encountered a case in which the copy constructor would do something different than the assignment operator.
In general, you need to provide them if you have to provide a smarter "copy" mechanism (for instance your class contains a pointer which should be recreated instead of simply assigning the same address).
|
|
|
|
|
thanks a lot,
Could you please elaborate little more on the point.
Cedric Moonen wrote: smarter "copy" mechanism (for instance your class contains a pointer which should be recreated instead of simply assigning the same address).
May be if you dont mind one example...
Regards
-----------------------------
I am a beginner
|
|
|
|
|
If you didn't supply a copy constructor and assignment operator, the compiler provides a default for them. These default methods simply copy the "memory area" of one object to the other. So, if your object contains a pointer, the address of the pointer will be copied. Which means that you will end up with two instances of the class, each of them having a pointer pointing to the same address. In most of the case, you don't want such a scenario because then if one instance deletes the pointer, the other one can't access it anymore (the memory to which it points has been freed).
What you want to typically do in such scenario is create another pointer and copy the pointed data. This way, the two instances contain a different pointer and each of them can safely delete it.
This was of course just an example when it makes sense to provide a copy constructor and assignment operator, but you could replace the pointer stuff by something different (for instance a resource).
Typical classes in which you want to provide a copy constructor and assignment operator are string management classes (std::string, CString, ...) because they internally create a buffer to store the data. Take the following example:
string var1 = "test";
string var2 = var1;
var2.replace(....);
In such a scenario, you absolutely don't want that the internal buffer of var1 gets modified. So, when you copy the string, you have to recreate another independent buffer.
Hope this helps.
|
|
|
|
|
Here[^] is a good article which takes assignment operators in detail. Its worth reading.
|
|
|
|
|
thanks you for your reply.I will go through it
-----------------------------
I am a beginner
|
|
|
|
|
Wow, that's the best article I've seen on C++ copy constructors and assignment operators. Thanks!
|
|
|
|
|
Its very similar to initialization and assignment.
int i = 10; is initialization.
This is where copy constructor works in case of classes.
int i;<br />
i = 10;
This is assignment. This is where assignment operator works in case of classes.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
Ok, I understood that..thanks
But could you please differentiate these with respect to shallow copy and deep copy?...and why we say so?
-----------------------------
I am a beginner
|
|
|
|
|