You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4cxx-user@logging.apache.org by Peter Doornbosch <pe...@gmail.com> on 2008/12/01 13:08:55 UTC

Re: Visual C++ Assertion failed when using LOG4CXX_DECODE_CHAR macro in statically linked MFC project

Hi,

Sorry that I've been out of the loop on this.  The LOG4CXX_DECODE_CHAR and
> similar macros were written for internal use in log4cxx, doesn't mean that
> they shouldn't be usable outside of log4cxx, but the log4cxx API should make
> their use outside of log4cxx rare or unnecessary.


I guess i'm missing something then. I've been looking for a way to convert a
string (whether a CString or a simple C zero-terminated character string, i
don't care) into a LogString. I couldn't find anything relevant though,
except this.
http://www.nabble.com/LogString-conversion-td17147202.html.

If there is a simpler way, please enlighten me.
I only want to replace a hard-coded LogString value like this
         LogString filename(L"log\\myapplication.log");
into something so that i can programmatically determine the log file name.

Regards,
Peter.

Re: Visual C++ Assertion failed when using LOG4CXX_DECODE_CHAR macro in statically linked MFC project

Posted by Peter Doornbosch <pe...@gmail.com>.
Hi Jacob,


2008/12/1 Jacob L. Anawalt <ja...@geckosoftware.com>

> On 2008-12-01 06:01, Peter Doornbosch wrote:
>
>> Got it now. As  the application is defining _ MBCS, LPCTSTR is actually a
>> pointer to a char,
>>
>
> Long Pointer to a Const Tchar STRing.


Yep, and when _MBCS is defined, TCHAR is char.


>
>
>  which i must convert to unicode (using
>> MultiByteToWideChar), as the LogString constructor is expecting unicode,
>> is
>> that right?
>>
>>
> I don't know if that is the cause of your error, it would cause size
> differences when using functions that assume sizeof(character) (eg TCHAR) ==
> sizeof(char) (byte) and confuse character counts with byte sizes.


No no, this is not the error case. I was looking for a way to convert
CString to LogString. I now use MultiByteToWideChar to convert a LPCSTR to a
unicode string. This works fine, in all cases (statically or dynamically
linked).


> Seems strange that it would work or not depending on your use of MFC
> (static or not). That sounds more like a new/free or other memory tracking
> mixup.


Exactly, that was what i thought; that was why i dropped the issue on this
list in the first place.
But this issue (application crashes with assertion error when statically
linked) concerns use of the LOG4CXX_DECODE_CHAR macro, which i first used to
convert CString into LogString. But as Curt discouraged the use of this
macro, i looked for an alternative and ended up with this
MultiByteToWideChar conversion, which seems to work ok. Sorry for the
confusion.

Note that the original issue (macro causes failed assertion) still persists,
but it's not bothering me anymore.

Thanks.

Regards,
Peter

>
>
> --
> Jacob Anawalt
> Gecko Software, Inc.
> janawalt@geckosoftware.com
> 435-752-8026
>

Re: Visual C++ Assertion failed when using LOG4CXX_DECODE_CHAR macro in statically linked MFC project

Posted by "Jacob L. Anawalt" <ja...@geckosoftware.com>.
On 2008-12-01 06:01, Peter Doornbosch wrote:
> Got it now. As  the application is defining _ MBCS, LPCTSTR is actually a
> pointer to a char,

Long Pointer to a Const Tchar STRing.

> which i must convert to unicode (using
> MultiByteToWideChar), as the LogString constructor is expecting unicode, is
> that right?
> 

I don't know if that is the cause of your error, it would cause size differences 
when using functions that assume sizeof(character) (eg TCHAR) == sizeof(char) 
(byte) and confuse character counts with byte sizes. Seems strange that it would 
work or not depending on your use of MFC (static or not). That sounds more like 
a new/free or other memory tracking mixup.

-- 
Jacob Anawalt
Gecko Software, Inc.
janawalt@geckosoftware.com
435-752-8026

Re: Visual C++ Assertion failed when using LOG4CXX_DECODE_CHAR macro in statically linked MFC project

Posted by Peter Doornbosch <pe...@gmail.com>.
>
> I guess i'm missing something then. I've been looking for a way to convert
> a string (whether a CString or a simple C zero-terminated character string,
> i don't care) into a LogString.
>

Got it now. As  the application is defining _ MBCS, LPCTSTR is actually a
pointer to a char, which i must convert to unicode (using
MultiByteToWideChar), as the LogString constructor is expecting unicode, is
that right?

Thanks,
Peter