tags:

views:

195

answers:

3

Hello!

Need to log the content of buf using the LogMethod() below the problem is that LogMethos only accepts a "Const CString&"

char buf[1024];
strcpy(buf, cErrorMsg);

// need to pass to LogMethod "buf" how do i do that?
log.LogMethod(const CString &); 

Thans Rev

Reversed

A: 
CString cs;
cs = buf;

log.LogMethod(cs)
sdornan
no error.....just doesnt log
Reversed
+1  A: 

If you're talking about MFC CString, as far as I can tell, it should have a non-explicit constructor taking TCHAR const *. In other words, the following should work.

log.LogMethod(buf); 

If it doesn't, please post the error message.

avakar
no error.....just doesnt log
Reversed
+1  A: 
log.LogMethod(CString(buf));

This will avoid the problem where the compiler won't automatically create the CString object using the appropriate constructor since the argument is a reference (It would have if the argument was a "plain" CString).

Ruddy
avakar
Ruddy
I very much doubt that Microsoft would change the explicitness between versions, as it would break a lot of existing code. Besides, documentation (http://msdn.microsoft.com/en-us/library/cws1zdt8%28VS.80%29.aspx) clearly shows the constructor is not explicit. Are you sure you didn't try compiling as Unicode while still passing `char const *` as a parameter (which indeed would trigger the explicit non-TCHAR constructor)?
avakar
@avakar - I stand corrected. I had accepted the defaults for the project, it was making "const char*" unicode, and when changed to non-unicode it worked as you describe (compiling without error).
Ruddy