|
It depends on how you are assigning. Check that the two aren't using the same memory address.
Gerry.
|
|
|
|
|
But there is something I still don't understand about C++: How can both strings use the same memory address if I'm not using any pointer on them?
The exact situation is that I've a class with a public member variable of type string (_bstr_t) and a method for that class where I receive a _bstr_t parameter (not a pointer).
If I call this method without the parameter everything goes right, but if I call it with the parameter, the public member variable gets its value changed with the parameter's one.
Thanks for answering,
|
|
|
|
|
It doesn't happen always and I'd really like if somebody could help me with that.
Post your code. How can you expect anybody to answer your question without source?
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
O.K here's the code
First I've a class with a public member variable:
BSTR stringA;
then from a function I write:
MyClass *ptrMyClass;
MyClass->stringA = _bstr_t("SomethingA");
_bstr_t stringB;
stringB = "SomethingB";
After that, MyClass->stringA contains "SomethingB" although I've noticed that it only happens if SomethingB.length>128
Please, tell me what I'm doing wrong (and most important why)
Thanks for everything,
|
|
|
|
|
MyClass *ptrMyClass;
MyClass->stringA = _bstr_t("SomethingA");
You're using uninitialized variable ptrMyClass. You know how pointers work, don't you?
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
BSTR is defined as wchar_t * and thus is really a pointer. You should also uses _bstr_t type for your class member as that class is a wrapper for BSTR and will handle copy and similar things properly.
The reason why the string would be reused is that the pointer (stringA member) is initialized (incorrectly) from an implicit conversion operator of class _bstr_t. Since _bstr_t("SomethingA") create a temporary object which will last only for the expression, the memory allocated by the (temporary) object will freed before the next instruction and will be available for subsequent allocation.
So Windows may reuse the same address for that subsequent allocation and this is why the first string (stringA member) may now have that value. In any case, as mentionned in another answer, stringA member is not properly initilized...
If you want to uses BSTR for the class member, then it should be initilized using SysAllocString and it should then be freed by the class destructor using SysFreeString.
Philippe
|
|
|
|
|
Thanks for everything, at last I've understood it!
|
|
|
|
|
I want take ownership of a file from a process running as administrator, but the administrator dont have any permit in the file.
I can do this from the explorer (file property, security, advanced, owner) but with win32 security API i cant do it. With SetSecurityInfo or SetNamedSecurityInfo the result is error because i dont have permits. If i can do it from windows explorer, why not from security API?
thanks in advance
Mario
|
|
|
|
|
Hi all,
How can i change the title bar in SDI mode ?
My month article: Game programming by DirectX by Lan Mader.
Please visit in: www.geocities.com/hadi_rezaie/index.html
Hadi Rezaie
|
|
|
|
|
|
Hi,
I used of SetWindowText in WM_ACTIVATE and WM_CREATE messages ... but don't work !!!
My month article: Game programming by DirectX by Lan Mader.
Please visit in: www.geocities.com/hadi_rezaie/index.html
Hadi Rezaie
|
|
|
|
|
If SetWindowText doesn't work for you, you'll need to override CFrameWnd::OnUpdateFrameTitle.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
Hi All,
I have Overridden the CwinApp::Run function in my code and I have called
some of the functions which does my desired work.There is no problem with
these functions as they execute properly. But when the control tries come
out of the CwinApp::Run function it enters the MFC code and crashes there.
The main problem is in the File "WinHand.cpp" (Within Visual Studio). In
that file the following function gives the problem.
void CHandleMap::DeleteTemp()
{
if (this == NULL)
return;
POSITION pos = m_temporaryMap.GetStartPosition();
while (pos != NULL)
{
HANDLE h; // just used for asserts
CObject* pTemp;
m_temporaryMap.GetNextAssoc(pos, (LPVOID&)h, (void*&)pTemp);
// zero out the handles
ASSERT(m_nHandles == 1 || m_nHandles == 2);
HANDLE* ph = (HANDLE*)((BYTE*)pTemp + m_nOffset); // after CObject
ASSERT(ph[0] == h || ph[0] == NULL);
ph[0] = NULL;
if (m_nHandles == 2)
{
ASSERT(ph[1] == h || ph[1] == NULL);
ph[1] = NULL;
}
delete pTemp; // virtual destructor does the right thing
}
m_temporaryMap.RemoveAll(); // free up dictionary links etc
}
In the above function there is a line which says ASSERT(ph[0] == h || ph[0]
== NULL);
It is crashing at this particular. I am not able to understand why exactly
it is giving this problem.
Does anyone have any idea about the problem. Any help is hugely appreciated.
TIA
Srinidhi.
|
|
|
|
|
|
Hi,
Thanks for your response. Here I have pasted the code. m_pMagicControl is my main UI class which puts up a complex UI.
int CMAGICOPTApp::Run()
{
// TODO: Add your specialized code here and/or call the base class
if (theApp.m_pMagicControl->Open())
{
theApp.m_pMagicControl->ShowUI(TRUE, theApp.GetMainWnd());
}
return CWinApp::Run();
}
Could you smell something??
TIA
srinidhi
|
|
|
|
|
Could you smell something??
Not exactly. I think you should ensure that it's a 'magic control' that causes the crash. What happens when you comment out the ShowUI call?
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
HI,
Thanks for your interest, I traced the problem for sometime. So this is the result I got from it.
Now, I dont override CWinApp::Run(). I moved all the UI initialization to InitInstance (). Now, the application gets initialized properly, but it crashes inside CMenu::DeleteTempMap().
Do you why this happend?
TIA
Regards
Srinidhi
|
|
|
|
|
hi all,
can anyone tell any command should be used for setting sampling rate for recording?
regards,
jim
|
|
|
|
|
I would like to know if someone could answer me to simple problem: We suppose that we create a class MyClass where there are methods(method1(), method2()...) where one have to use another method of MyClass. For example, suppose that method1 need of method2 in its implementation, how could i do that?
thanks in advance
gerald
|
|
|
|
|
I don't understand ? You want to call method1() from inside method2() ? What's the problem ? Just do it.
If you mean from another instance of the class, make the method static and you'll only have one instance of the method across all classes.
Christian
#include "std_disclaimer.h"
The careful application of terror is also a form of communication.
Eagles may soar, but weasels don't get sucked into jet engines.
|
|
|
|
|
Not sure what you are after, perhaps you are talking about 2 objects, & passing one object into the other & calling a method.
Please Expand.
Gerry.
|
|
|
|
|
Y'know, if you answered the guy who asked the question instead of me, he'd get an email alert that you were offering to help him. That would probably be a good thing.
Christian
#include "std_disclaimer.h"
The careful application of terror is also a form of communication.
Eagles may soar, but weasels don't get sucked into jet engines.
|
|
|
|
|
Sorry about that, clicked on the wrong button.
Gerry.
|
|
|
|
|
So could i do that:
double MyClass::method1()
{....}
double MyClass::method2()
{.
.
.
double m=method1();
.
}
gerald
|
|
|
|
|
Yes, you can do that....You need to decide if the methods are public or private!
Gerry.
|
|
|
|