Click here to Skip to main content
16,004,919 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Problem assigning string to CString object Pin
Kiran Pinjala31-Jul-06 2:11
Kiran Pinjala31-Jul-06 2:11 
GeneralRe: Problem assigning string to CString object Pin
toxcct31-Jul-06 2:14
toxcct31-Jul-06 2:14 
GeneralRe: Problem assigning string to CString object Pin
Kiran Pinjala31-Jul-06 2:19
Kiran Pinjala31-Jul-06 2:19 
GeneralRe: Problem assigning string to CString object Pin
toxcct31-Jul-06 2:25
toxcct31-Jul-06 2:25 
GeneralRe: Problem assigning string to CString object Pin
Kiran Pinjala31-Jul-06 2:43
Kiran Pinjala31-Jul-06 2:43 
GeneralRe: Problem assigning string to CString object Pin
toxcct31-Jul-06 2:46
toxcct31-Jul-06 2:46 
GeneralRe: Problem assigning string to CString object Pin
Kiran Pinjala31-Jul-06 2:48
Kiran Pinjala31-Jul-06 2:48 
AnswerRe: Problem assigning string to CString object Pin
Zac Howland31-Jul-06 4:12
Zac Howland31-Jul-06 4:12 
You have a few problems here. The biggest one is the cause of the problem you see:

kiran.pinjarla wrote:
ZeroMemory(pUser, sizeof(USER));


Doing this destroys the memory that CString's constructor worked so hard to set up. Your options here are to either make USER into a class and have its constructor do proper initialization, or to make the CString part of the structure into a CString* (and obviously make sure you create it before using it). The first option would be a better choice:

class User
{
	User()
	{
		m_pPtr = NULL;
		m_strData = _T("");
	}

	// other methods for accessing data go here
private:
	MYINTERFACEPTR* m_pPtr;
	CString m_strData;
};


kiran.pinjarla wrote:
name = BSTRtoStr(bstr);// THIS IS MY FUNCTION


This isn't such a big problem, but it is reinventing the wheel. I'm assuming that bstr is some BSTR value that is passed to this function/area of code somehow. That being the case, the type should be changed from BSTR to _bstr_t (which has a constructor and an explicit cast operator to BSTR). Then, to copy that string to your CString object, you would just do the following:

pUser->SetData((const char*)bstr); // SetData being the accessor for your CString member variable

If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week

Zac

QuestionRe: Problem assigning string to CString object Pin
David Crow31-Jul-06 5:03
David Crow31-Jul-06 5:03 
AnswerRe: Problem assigning string to CString object Pin
jpyp31-Jul-06 7:56
jpyp31-Jul-06 7:56 
AnswerRe: Problem assigning string to CString object Pin
Christopher Stratmann31-Jul-06 8:08
Christopher Stratmann31-Jul-06 8:08 
QuestionICQ Pin
Daniel Kanev30-Jul-06 23:29
Daniel Kanev30-Jul-06 23:29 
Questioncontrols visible or not at runtime Pin
Desmo1630-Jul-06 22:50
Desmo1630-Jul-06 22:50 
QuestionRe: controls visible or not at runtime Pin
see me30-Jul-06 23:00
see me30-Jul-06 23:00 
AnswerRe: controls visible or not at runtime Pin
toxcct30-Jul-06 23:01
toxcct30-Jul-06 23:01 
GeneralRe: controls visible or not at runtime Pin
see me30-Jul-06 23:11
see me30-Jul-06 23:11 
GeneralRe: controls visible or not at runtime Pin
toxcct30-Jul-06 23:13
toxcct30-Jul-06 23:13 
GeneralRe: controls visible or not at runtime Pin
see me30-Jul-06 23:23
see me30-Jul-06 23:23 
GeneralRe: controls visible or not at runtime Pin
toxcct30-Jul-06 23:24
toxcct30-Jul-06 23:24 
AnswerRe: controls visible or not at runtime Pin
_AnsHUMAN_ 30-Jul-06 23:04
_AnsHUMAN_ 30-Jul-06 23:04 
AnswerRe: controls visible or not at runtime Pin
Hamid_RT31-Jul-06 1:00
Hamid_RT31-Jul-06 1:00 
Questiontraversing and modifying CPtrlist [modified] Pin
SteamEngine30-Jul-06 22:41
SteamEngine30-Jul-06 22:41 
AnswerRe: traversing and modifying CPtrlist Pin
cje31-Jul-06 4:34
cje31-Jul-06 4:34 
QuestionList of Format Specifiers Pin
QuickDeveloper30-Jul-06 22:17
QuickDeveloper30-Jul-06 22:17 
AnswerRe: List of Format Specifiers Pin
_AnsHUMAN_ 30-Jul-06 22:25
_AnsHUMAN_ 30-Jul-06 22:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.