Click here to Skip to main content
15,900,258 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Unable to send AT commands to the COM3 port. plz help. Pin
AprNgp29-Aug-08 9:28
AprNgp29-Aug-08 9:28 
GeneralRe: Unable to send AT commands to the COM3 port. plz help. Pin
AprNgp31-Aug-08 8:54
AprNgp31-Aug-08 8:54 
GeneralRe: Unable to send AT commands to the COM3 port. plz help. Pin
Vaclav_29-Aug-08 8:50
Vaclav_29-Aug-08 8:50 
GeneralRe: Unable to send AT commands to the COM3 port. plz help. Pin
AprNgp29-Aug-08 8:56
AprNgp29-Aug-08 8:56 
GeneralRe: Unable to send AT commands to the COM3 port. plz help. Pin
AprNgp29-Aug-08 9:06
AprNgp29-Aug-08 9:06 
QuestionCString as variable arguments Pin
Royce Fickling29-Aug-08 5:31
Royce Fickling29-Aug-08 5:31 
QuestionRe: CString as variable arguments Pin
David Crow29-Aug-08 7:42
David Crow29-Aug-08 7:42 
AnswerRe: CString as variable arguments [modified] Pin
Mark Salsbery29-Aug-08 7:47
Mark Salsbery29-Aug-08 7:47 
Interesting.

I looked at this for a while. The problem is the "strValue"
argument. The offset of the strValue parameter is used to calculate
the offset of the start of the variable-length parameter list.
If you don't pass it by reference the function works fine.

I can't figure out why the reference doesn't work - the sizeof a reference
is the same as the sizeof a CString (4 bytes on my 32-bit build), so I would
expect the same result.
I guess references are passed on the stack differently.

I don't think this old C feature was meant to deal with C++ references anyway...

Regardless, passing strValue by value instead of by reference fixes it:
void COdb::WriteAttribute( CStdioFile& fileOutput, 
			        const CString& strTagName,
			        const CString& strAttribute, 
			        const CString strValue, ... )
...

If anyone wants to analyze this further, here's the macro definitions:
#define _ADDRESSOF(v)   ( &reinterpret_cast<const char &>(v) )
#define _INTSIZEOF(n)   ( (sizeof(n) + sizeof(int) - 1) & ~(sizeof(int) - 1) )

#define _crt_va_start(ap,v)  ( ap = (va_list)_ADDRESSOF(v) + _INTSIZEOF(v) )
#define _crt_va_arg(ap,t)    ( *(t *)((ap += _INTSIZEOF(t)) - _INTSIZEOF(t)) )
#define _crt_va_end(ap)      ( ap = (va_list)0 )


*edit* Now that the caffeine has kicked in, I realize taking the address<br />
of a reference gives you the address of the object referenced, not the<br />
address of the reference.  Yeah - those macros weren't meant to work<br />
with references
Smile | :)

Mark

Mark Salsbery
Microsoft MVP - Visual C++

Java | [Coffee]

modified on Friday, August 29, 2008 2:09 PM

GeneralRe: CString as variable arguments Pin
Royce Fickling29-Aug-08 8:56
Royce Fickling29-Aug-08 8:56 
GeneralRe: CString as variable arguments Pin
Mark Salsbery29-Aug-08 9:06
Mark Salsbery29-Aug-08 9:06 
QuestionNumber of words and characters of a string. Pin
CodingLover29-Aug-08 4:37
CodingLover29-Aug-08 4:37 
GeneralRe: Number of words and characters of a string. Pin
led mike29-Aug-08 4:39
led mike29-Aug-08 4:39 
NewsRe: Number of words and characters of a string. Pin
CodingLover29-Aug-08 4:40
CodingLover29-Aug-08 4:40 
QuestionRe: Number of words and characters of a string. Pin
CodingLover29-Aug-08 6:20
CodingLover29-Aug-08 6:20 
AnswerRe: Number of words and characters of a string. Pin
led mike29-Aug-08 6:52
led mike29-Aug-08 6:52 
AnswerRe: Number of words and characters of a string. Pin
Nemanja Trifunovic29-Aug-08 9:23
Nemanja Trifunovic29-Aug-08 9:23 
Questionhow to extract frames from video with .dat format..?? Pin
suresh zende29-Aug-08 4:35
suresh zende29-Aug-08 4:35 
AnswerRe: how to extract frames from video with .dat format..?? Pin
Mark Salsbery29-Aug-08 8:36
Mark Salsbery29-Aug-08 8:36 
GeneralRe: how to extract frames from video with .dat format..?? Pin
suresh zende30-Aug-08 4:12
suresh zende30-Aug-08 4:12 
GeneralRe: how to extract frames from video with .dat format..?? Pin
Mark Salsbery30-Aug-08 5:49
Mark Salsbery30-Aug-08 5:49 
GeneralRe: how to extract frames from video with .dat format..?(we hv to take snapshots) Pin
suresh zende30-Aug-08 6:37
suresh zende30-Aug-08 6:37 
GeneralRe: how to extract frames from video with .dat format..?(we hv to take snapshots) Pin
Mark Salsbery30-Aug-08 7:09
Mark Salsbery30-Aug-08 7:09 
QuestionCreate function is not working in release mode but working in debug mode Pin
lavate malllik29-Aug-08 3:01
lavate malllik29-Aug-08 3:01 
AnswerRe: Create function is not working in release mode but working in debug mode Pin
Jijo.Raj29-Aug-08 3:21
Jijo.Raj29-Aug-08 3:21 
AnswerRe: Create function is not working in release mode but working in debug mode Pin
Nibu babu thomas29-Aug-08 3:21
Nibu babu thomas29-Aug-08 3:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.