Groups | Blog | Home
all groups > visual studio .net general > march 2004 >

visual studio .net general : CString in VC++.Net


Naama
3/7/2004 1:16:06 AM
I’m migrating our VC++ 6 code to VC++ .Net, and I’m experiencing some problems related to CString in the process.
For example, I have a class derived from CObject (and two other abstract classes).
This class has a few CString data members.
When I look at their value in the debugger, I always see ‘bad ptr’ no matter what kind of initialization I perform on them.
Any ideas why it happens ?

Thanks.
Naama
3/7/2004 10:51:06 PM
Hi

Thanks for your quick response
I declared the members as CString instances (not pointers)
I initialize them in the class constructor in various ways, the result is always the same – ‘bat ptrâ€

For example

// NGCMN_EXPORTS is defined in the project scope
#ifdef NGCMN_EXPORTS
#define NGCMN_API __declspec(dllexport
#els
#define NGCMN_API __declspec(dllimport

class NGCMN_API CUserId : public IUserId, public CObjec

public
CUserId()
virtual ~CUserId()

private
CString m_sDomainName
}

CUserId:: CUserId() :
m_sDomainName(_T(“”)) // I try to initialize it in the initialization lis

CString sInit(_T(“a”)); // I create a local (valid) CString variabl
m_sDomainName = sInit; // I try to assign the value of the local variable to the member

// after all these actions, m_sDomainName is still ‘bad ptrâ€


I don’t think the answer is in the code, though. Maybe there is something in the project settings
This code is inside an MFC extension dll, called by an MFC application
Any ideas

Thanks again

timhuang NO[at]SPAM online.microsoft.com
3/8/2004 5:24:48 AM
Hi,

Thanks for your post. I reviewed your description carefully, and think more
information is needed before moving forward:

Did you declare member variables as pointers to CString? If so, please make
sure you create the new instances of CString.

When did you initialize the CString, the contrustor of the class?

Could you post some code snippet demonstrating the problem you are seeing?
I will be glad to check it on my side.

I look forward to hearing from you.

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
v-garych NO[at]SPAM online.microsoft.com
3/9/2004 3:09:08 AM
Hi Naama,

Thanks for your response!

[quoted text, click to view]
in the project settings ?

The "bad ptr" issue could be caused by the project's misalignment compile
option, you can find a detail discussion on this problem at:
http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&threadm=wHEt9.38
75%24vq2.310324%40news1.east.cox.net&rnum=1&prev=/groups%3Fsourceid%3Dnavcli
ent%26ie%3DUTF-8%26oe%3DUTF-8%26q%3D%2522bad%2Bptr%2522%2BCString

However, if it doesn't hit your problem, would you please to upload a small
self-alone VC6 project(zipped) to the group if it not inconvenience(reply
this message and attach it)?


Thanks!

Best regards,

Gary Chang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
Naama
3/9/2004 3:26:06 AM
Thanks
That really solved the problem

We had one file wit
#pragma pack (push, 1
â€
#pragam pack (pop, 1

I changed it t
#pragma pack (pop

and the problem is gone

Thank you very much
I never would’ve picked it up myself

AddThis Social Bookmark Button