Click here to Skip to main content
15,888,112 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
OS: Windows 7 Pro
IDE: Visual Studio 2015

Dear folks,

I have a strange thing happening when I try to run any application compiled with standard debug settings and linked to the debug version of Apache log4cxx, a logger DLL that I also compiled with its standard debug settings.

When I run the code as below, with
LOG4CXX_INFO(logger0, st.c_str());
then it writes "xyz" to the console, as to be expected.

However, when I run it with
LOG4CXX_INFO(logger0, st);
i.e. the string object being handed to the dll function (by reference), the program crashes. Stepping into the function that is called reveals, that the buffer of the string object () does not point to the same address (0x0037fa58 "xyz") but to (0x0037fa54 "xyz"), i.e. 4 bytes to the left of the original.

Any hint is greatly appreciated - thank you so much.

Cheers
Werner

Calling Code

std::string st = std::string("xyz");
LOG4CXX_INFO(logger0, st);


Code called

CharMessageBuffer& MessageBuffer::operator<<(const std::string& msg) {
   return cbuf.operator<<(msg);
}


What I have tried:

I suspected _ITERATOR_DEBUG_LEVEL and checked, whether it was 2 in both app and dll (true). If I set _ITERATOR_DEBUG_LEVEL=0, surprisingly, the app also links to the dll without complain and the string reference is handed properly to the called function: The code works.
Posted
Updated 19-Sep-16 22:38pm
v4

That is because you are sending the string object, rather than the actual text of the string it contains. You need to follow the exact rules of the function you are calling.
 
Share this answer
 
Comments
WernerP 20-Sep-16 2:23am    
Thank you, Richard. Good suggestion. However, I forgot to show the callee represented by macro LOG4CXX_INFO: It takes a string& argument. The 4 byte shift indicates, that std::string is of a different definition in calling app and dll. This should not be the case, in particular, as both had been compiled with default debug settings. In particular, what I have done now, was to explicitly set _ITERATOR_DEBUG_LEVEL=2 (an often stated reason for a diverging std::string implementation) when compiling the dll.
Trivial error: I renamed both lib and dll to D.lib and D.dll. Of course that will not work, as the lib points to the original name. :-\
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900