|
Then how do you want to create the struct???
Dream bigger... Do bigger...Expect smaller
aji
|
|
|
|
|
struct TestStr {
CString m_str;
};
TestStr varTS;
varTS.m_str = _T("Another way");
TestStr* pTS = &varTS;
pTS->m_str = _T("Hello");
|
|
|
|
|
toxcct wrote: TestStr* pTS;pTS->m_str = _T("Hello");
this time to what pTS is points to????
Dream bigger... Do bigger...Expect smaller
aji
|
|
|
|
|
my mistake. fixed it. see the previous post.
|
|
|
|
|
Dream bigger... Do bigger...Expect smaller
aji
|
|
|
|
|
can you please show us the code around where it crashed ?
i see no pb in the line you shown, but maybe px is pointing to nowhere (NULL ?)...
|
|
|
|
|
USER * pUser = new USER;
if (NULL == pUser)
{
return NULL;
}
ZeroMemory(pUser, sizeof(USER));
pUser->pMember = pMember;
hr = pMember->GetName(&bstr);
if (FAILED(hr))
{
AddLog("Problem with GetName");
}
else
{
name = BSTRtoStr(bstr);// THIS IS MY FUNCTION
//pUser->strName.Insert(0,name); -----******* HERE WHERE IT IS CRASHED
SysFreeString(bstr);
m_ListMembers.InsertString(-1,name);
}
KIRAN PINJARLA
|
|
|
|
|
|
typedef struct USER
{
INmMember *pMember; //INmMember is a componant Interface
CString name;
}USER;
KIRAN PINJARLA
|
|
|
|
|
why do you use CString::Insert() instead of CString::Operator = ???moreover, how is declared name ??
|
|
|
|
|
Actually i tried all assignments of CString and insert was one of it.
I tried name =..., name.Format("%s",...
But it doesnt work.
KIRAN PINJARLA
|
|
|
|
|
it's not what i'm asking. how is declared name ?
1. CString name;
2. char* name;
3. char[] name;
4. other...
|
|
|
|
|
its declared as
CString name;
KIRAN PINJARLA
|
|
|
|
|
then, where you wrote
pUser->strName.Insert(0,name); -----******* HERE WHERE IT IS CRASHED
what happens with the following code if you dirrecly affect strName ?? :
ASSERT(pUser != NULL);
pUser->strName = _T("hello");
|
|
|
|
|
The first thing i did was that. It failed there, then i tried differenct ways.
KIRAN PINJARLA
|
|
|
|
|
kiran.pinjarla wrote: It failed there
well, i cannot help you much ; i'm pretty sure you don't show us all the code...
|
|
|
|
|
Its going to afx.inl and showing error at
// CString
_AFX_INLINE CStringData* CString::GetData() const
{ ASSERT(m_pchData != NULL); return ((CStringData*)m_pchData)-1; }
showing m_pchData : NULL;
KIRAN PINJARLA
|
|
|
|
|
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("");
}
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
|
|
|
|
|
kiran.pinjarla wrote: ZeroMemory(pUser, sizeof(USER));
What's this for?
"Money talks. When my money starts to talk, I get a bill to shut it up." - Frank
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Have you tried the following:
#pragma pack(push, 1)<br />
your struct declaration<br />
#pragma pack(pop)
Thanks!
jpyp
|
|
|
|
|
Why dont you just do this???
CString s;
s.Format("%s",::ConvertBSTRToString(BSTR));
ConvertBSTRToString is a standard function that should be available to you.
Chris
|
|
|
|
|
I would like to write my own ICQ client. How can I log on to an ICQ server and process messages?
thanks!
modified 9-Mar-17 17:15pm.
|
|
|
|
|
Hi all,
Is there a way to make a control visible/invisible
at runtime ?
Moreover: may i change the position af a control
at runtime ?
Thanx in advance,
Desmo16.
|
|
|
|
|
Please mention some thing about wat language u r using???
do u mean controls in MFC dialg based application???
Dream bigger... Do bigger...Expect smaller
aji
|
|
|
|
|
GetDlgItem(IDC_MY_CONTROL)->ShowWindow(SW_HIDE);<br />
GetDlgItem(IDC_MY_CONTROL)->ShowWindow(SW_SHOW);
|
|
|
|