|
|
Try this code:
_bstr_t bstr(_T("_bstr_t toCString test"));
CString str;
W2A(bstr, str.GetBuffer(256), 256);
strName.ReleaseBuffer();
Sudhir Kumar
|
|
|
|
|
you code is not consistent. W2A() gets only one parameter, which is the string to cast.
also GetBuffer() is in its good use here (rarely goodly used, to it's important to notice it !) but it's not necessary. prefer using the CString::operator=() instead, and don't use W2A() but T2A() if the source is unicode independent (otherwise, it's your _b_str construction which shouldn't use _T())
|
|
|
|
|
|
Have you even tried:
_bstr_t b("This is very hard.");
CString c1 = (LPCTSTR) b;
CString c2 = static_cast<LPCTSTR>(b);
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Hey man, no C -style cast plz!
(coz 2 simple, plz plz urgent!)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
You can call copy() function of bstr to convert to CString.
eg:-
_bstr_t strTemp = "hi";
CString csTemp = strTemp.copy();
This will work fine.
akt
|
|
|
|
|
Akt_4_U wrote: _bstr_t strTemp = "hi";
CString csTemp = strTemp.copy();
hai, thats a nice bit of coding, but there is small performance issue, let me explain you, _bstr__t::copy will make a copy of underlining BSTR variable and pass it to csTemp, who again make copy of same and destroyed newly created BSTR variable. thought for small string the performance issue would be less, but for big string, this could present problem
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You/codeProject$$>
|
|
|
|
|
_bstr_t bstrStart(bstr); <br />
<br />
CString s;<br />
<br />
s.Format(_T("%s"), (LPCTSTR)bstrStart);<br />
<br />
AfxMessageBox(s);
Try this. Hope this will work for u.
The secret of life is not enjoyment
but education through experience.
- Swami Vivekananda.
|
|
|
|
|
Thanks.. I'm using this:
bstr_t bstrStart(bstr);
CString s;
s = static_cast<LPCTSTR>bstrStart;
|
|
|
|
|
SimplySane wrote: How do I cast(not the C style cast plz) _bstr_t to CString?
_bstr_t have overloaded LPCTSTR parameter, you can directly cast your _bstr_t object to CString. without any problem.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You/codeProject$$>
|
|
|
|
|
Hello Friends,
I have the following lines of code. The CRHPostMessageToParent() calls parent to parent class methods.
AfxMessageBox(_T("Page2::Inside TellPArent"));
this->CRHPostMessageToParent(WM_CHANGED_DS, (int)&deptStock);
this->ShowWindow(SW_HIDE);
this->CRHPostMessageToParent(WM_SHOW_NEXT_VIEW, i);
AfxMessageBox(_T("Page2::Finished TellParent"));
These codes start running untill the previous line code is not completed. I want to ensure, that it should proceed to next line only when the first is completed. The CRHPostMessageToParent() calls PostMessage () to parent & returns void. The parent function OnChanged_DS() returns LRESULT.
In Java, this can be achived by assigning each task in thread and synchronizing it, which makes sure that the process is completed & then only the handle is released.
How do I achive the same in VC++6? I hope I have explained my situation to the best. If yet not, ask me.
Thanks
Terry
|
|
|
|
|
Trupti Mehta wrote: How do I achive the same in VC++6?
You can also use synchronization.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
You can use MFC sync classes like CMutex,CEvent and CSemaPhore.
Sudhir Kumar
|
|
|
|
|
Does your CRHPostMessageToParent call PostMessage or SendMessage? Using SendMessage means that control does not return until the message has been processed which sounds like what you want.
Judy
|
|
|
|
|
JudyL_FL wrote: Does your CRHPostMessageToParent call PostMessage or SendMessage?
Did you miss:
The CRHPostMessageToParent() calls PostMessage ()...
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
DavidCrow wrote: Did you miss
Yes and no . Yes, in that I didn't see the exact API function name and read the function description as "post a message." No, in that the function name implies Post instead of Send. More important was to make sure the OP was aware of the difference between PostMessage and SendMessage - unclear from the original post.
Judy
|
|
|
|
|
It calls the PostMessage(message, WPARAM, LPARAM)
How do I achieve the goal? Can you give some guidance/example to work with CEvent etc classes as mentioned in ealier post.
Thanks
Terry
|
|
|
|
|
I'm not the one who mentioned using CEvent. My suggestion was to call SendMessage instead of PostMessage to make the caller wait until the message was processed.
Judy
|
|
|
|
|
Oh sorry Judy. must have read in some website for solution of the problem.
Anyways, I changed from PostMessage to SendMessage. Was just wondering will it make any differnece in using any of those. I mean, i changed from post to send will that make any other impact on the application other than not returning till the message is posted. Am just curious about it.
Thanks Judy.
Thanks
Terry
|
|
|
|
|
Trupti Mehta wrote: Was just wondering will it make any differnece in using any of those. I mean, i changed from post to send will that make any other impact on the application other than not returning till the message is posted.
Nope, that is the only difference. It can become an issue in multi-threaded programs whether you use Post or Send depending on how your GUI thread and your worker threads synchronize with each other. If you use Send, you need to be (even more) careful about potential deadlocks since Send causes your thread to wait.
Judy
|
|
|
|
|
Hi, I have a dialog box with a pop-up menu and one of the menu entry in there has the 'Checked' property set to true (as default). Now during the execution of my program, I would like to un-check the check mark next to this menu item, but I can't seem to be able to accomplish this, the check-mark seems to be there always. Debugging through the code, it seems to execute the correct statements, but the GUI does not seem to get updated. Any help would be greatly apperciated.
VS2005, C++ (MFC)
Code:
CMenu menuTst;
VERIFY(menuTst.LoadMenu(IDR_MENU_HELP));
CMenu* pPopupTest = menuTst.GetSubMenu(0);
UINT state = pPopupTest->GetMenuState(ID_OPEN_LOGFILE, MF_BYCOMMAND);
ASSERT(state != 0xFFFFFFFF);
if (state & MF_CHECKED)
pPopupTest->CheckMenuItem(ID_OPEN_LOGFILE, MF_UNCHECKED | MF_BYCOMMAND);
else
pPopupTest->CheckMenuItem(ID_OPEN_LOGFILE, MF_CHECKED | MF_BYCOMMAND);
|
|
|
|
|
You are loading menu locally in the function that,s why its not affecting the changes.
make CMenu menuTst; member of class and load (VERIFY(menuTst.LoadMenu(IDR_MENU_HELP));) somewhere like initdialog();
Sudhir Kumar
|
|
|
|
|
Hmm..unfortunately making the CMenu variable member of the class didn't seem to work either. I tried adding an ON_UPDATE_COMMAND_UI function for my menu item to try it in there, with no success!
void CTestDialog::OnUpdateOpenLogfile(CCmdUI *pCmdUI)
{
pCmdUI->SetCheck(0);
}
|
|
|
|
|