mfc >> CString =

by Ken-> » Sun, 30 Nov 2003 02:43:54 GMT

I have traced one of my problems to running my dll in release
mode and the exe in debug mode and calling a function in
the exe from the dll that copies (I thought) a CString into an
array of CStrings in the exe. The problem occors when the exe releases the
dll and later deletes the array. The CString data is not really copied as I
thought but only the pointer to the original CString is saved in the new one
and so the heap
pointer is wrong when it is time to delete the second CString.
So, how do I prevent this problem?
Thanks,
Ken




mfc >> CString =

by David Lowndes » Mon, 01 Dec 2003 02:13:09 GMT


>I have traced one of my problems to running my dll in release

Ken,

You've already said that you traced the problem to mixing a
release/debug EXE/DLL. The only solution is not to mix them.

The problem arises because the release and debug memory managers are
different - the debug one has additional allocation/code to help
detect memory leaks.

Dave
--
MVP VC++ FAQ: http://www.mvps.org/vcfaq



mfc >> CString =

by Ken-> » Mon, 01 Dec 2003 22:13:09 GMT

Does this mean that I cannot finish up my dll and then develop
and debug the rest of the code using my released dll?
Surely that can't be, because we are nearly always
including M$ dlls in our code and the those are almost
certainly compiled in release mode.
Ken



the
as I
one




CString =

by Ken-> » Tue, 02 Dec 2003 02:24:34 GMT

Here is how I got around this problem.
In the exe I call GetBuffer for the CString passed in as a
parameter from the dll and then add the resulting char* to the
array so that the exe makes a new CString in its own heap and
copies the data instead of just a pointer to it.
Now on to other problems.
Thanks
Ken







Similar Threads

1. CString.FormatMessage and CString.Format difference

2. CString link error in VC7 with MFC extersion dll which export functions using CString as parameter

3. CString.FormatMessage and CString.Format difference

4. 'CMap' of 'CString' to 'CString'

Hello!

I'm trying to create a dictionary with both key and value of type
'CString'. I declare the object of 'CMap' so it is as closer to
std::map, as possible:

CMap<CString, const CString&, CString, const CString&> m_appLangs;

and semantically it's like this:

std::map<std::string, std::string> m_appLangs;

But it seems 'CMap' is not realized as an RB-tree, I guess it must be
realized through hash table. The problem is when I make the above
declaration, my source file refuse to compile. Here is the simplified
error message:

cannot convert from 'const CString' to 'DWORD_PTR'
see reference to function template instantiation 'UINT
HashKey<ARG_KEY>(ARG_KEY)' being compiled with
[ARG_KEY=const CString &]

Here is the code of 'HashKey' function from "afxtempl.h":

template<class ARG_KEY>
AFX_INLINE UINT AFXAPI HashKey(ARG_KEY key)
{
	// default identity hash - works for most primitive values
	return (DWORD)(((DWORD_PTR)key)>>4);
}

And what does it mean? Can't I create a map of string to string just
because there is no conversion from 'CString' to 'DWORD_PTR'? I think/
hope I'm wrong. Would you please show me my mistake?

Thanks in advance
Martin

5. CString hex value to CString decimal value

6. Unable to convert from ATL::CString to vector<CString>::iterator

Hi Guys,

I am going through the lengthy process of upgrading from a VS6 project to 
VS2005.
The only issue I am left with is that I cannot work how to convert from a 
CString as part of an array to a vector iterator.

The code is as follows

vector<CString>::iterator ii = 
vector<CString>&(m_vsOverallAgentRetrievalQueueNames[i]);

and the error message is as follows

error C2440: 'initializing' : cannot convert from 
'ATL::CStringT<BaseType,StringTraits> *' to 
'std::_Vector_iterator<_Ty,_Alloc>'

Can anyone help at all?

Regards

Tony 

7. Array of CString s vs. CString Array

8. Locales and CString::MakeUpper() and CString::CollateNoCase()

I recently discovered that when running my Unicode application on an 
English XP system with my locales all set to English (US), the 
CString::MakeUpper() function did not convert a Russian text string from 
mixed case (  ) to uppercase (  ). The 
function that does the actual conversion is _wcsupr_s(). After some 
digging, I eventually discovered that the conversion is dependent on the 
locale set using the CRT setLocale() function. When I set the locale 
using setLocale(LC_ALL, ".1251"), the CString::MakeUpper() function 
worked as expected.

This seems wrong to me. If I have Unicode text in many different 
languages, I cannot know which code page to set to make the MakeUpper() 
function work. One reason for switching to Unicode is that we don't want 
to worry about code pages.

The CString::CollateNoCase() works similarly. If I call this function 
with the two Russian text strings listed above, the return is non-zero 
unless I first set the locale to use code page 1251.

Why does CStringW::MakeUpper() use the locale dependent _wcsupr_s() 
function rather than the CharUpperBuff() function, which works 
correctly? At this point, it looks like my only option is to find all 
places where we use CollateNoCase(), MakeUpper(), and MakeLower() and 
replace them with our own functions to do these tasks. Am I missing 
something? Does anyone have an idea for a better solution?