|
|
Let's presume your BSTR is called bstr .
UINT len = SysStringLen(bstr);
int bytesNeeded = WideCharToMultiByte(CP_ACP, WC_DEFAULTCHAR, (LPCWSTR)bstr, len, 0, 0, 0, 0);
char* buffer = new char [bytesNeeded + 1];
int bytesNeeded = WideCharToMultiByte(CP_ACP, WC_DEFAULTCHAR, (LPCWSTR)bstr, len, buffer, bytesNeeded, 0, 0);
buffer[bytesNeeded] = 0;
That should create a suitably sized character array and translate your BSTR into it.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Thanks a lot ...Article is really good
|
|
|
|
|
Hello Friends
my task is to append icons to menu (ie .ico), it is very easy to add bmp file to menu, but in order to need transparency i have to use icons only not bmps.
There are lots of programs for this in MFC , but i need to do it in Win32 API
using VC++
Any help is greatly appreciated
|
|
|
|
|
Aabid wrote: There are lots of programs for this in MFC , but i need to do it in Win32 API
Knowing that MFC is just a thin wrapper around the Win32 API, you should be able to look at the MFC code to tell what MFC is doing, and pick out the relevant parts.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Hi david can u guide me how to convert this function to Win32 API,
ie how can i handle this function as message
void CMainFrame::OnInitMenu(CMenu* pMenu)
{
#if _MFC_VER < 0x0800
#undef __FUNCTION__
#define __FUNCTION__ "OnInitMenu()"
#endif // _MFC_VER < 0x0800
AfxTrace(_T(__FUNCTION__) _T(": %#0x\n"), pMenu->GetSafeHmenu());
MENUITEMINFO minfo;
minfo.cbSize = sizeof(minfo);
for (UINT pos=0; pos<pMenu->GetMenuItemCount(); pos++)
{
minfo.fMask = MIIM_FTYPE | MIIM_ID;
pMenu->GetMenuItemInfo(pos, &minfo, TRUE);
HICON hIcon = GetIconForItem(minfo.wID);
if (hIcon && !(minfo.fType & MFT_OWNERDRAW))
{
AfxTrace(_T("replace for id=%#0x\n"), minfo.wID);
minfo.fMask = MIIM_FTYPE | MIIM_BITMAP;
minfo.hbmpItem = HBMMENU_CALLBACK;
minfo.fType = MFT_STRING;
::SetMenuItemInfo(pMenu->GetSafeHmenu(), pos, TRUE, &minfo);
}
else
AfxTrace(_T("keep for id=%#0x\n"), minfo.wID);
// ::DestroyIcon(hIcon); // we use LR_SHARED instead
}
}
We Have To Conert it into case WM_INITMENU:
|
|
|
|
|
See here. Googling for such will also turn up dozens of examples.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Hi all,
I have a thread in my application.
When the thread is running its eating up the CPU.
My thread code is like:
ThreadProcess(LPVOID)
{
while(TRUE)
{
if(flag==true)
{
ExecFunc();
}
}
}
If the flag is set then it will execute the function.This flag is set in other function.
So I want to keep this thread idle until the flag is set.
How can I do it.Please help me.
Regards,
Sunil Kumar
|
|
|
|
|
|
Don't use a boolean but use an event instead (and use the WaitForSingleObject[^] function). There's also a good tutorial about threads here[^]
|
|
|
|
|
If you expect the wait time to be relatively long, then use one of those WaitFor... functions. If the wait time would be very low, then a spin loop is an ideal candidate.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
Hi All
i have got article of write data in excel from code project.But it's give one exception error.Error is
An unhandled exception of type 'System.NullReferenceException' occurred in WEDLL.dll
Article link http://69.10.233.10/KB/mcpp/automate_Excel_in_C__.aspx[^]
How to solve that problem.
Plz help me.
|
|
|
|
|
|
Hi all,
I want to get process ID for my dialog based application, when i close my process..
How can i get it...
Thanks in advance
To accomplish great things, we must not only act, but also dream;
not only plan, but also believe.
|
|
|
|
|
|
Hi friends,
I have a tree control in MFC, if I use the check box option, then even the root item
gets the check box.
I want to have a tree control with check boxes in the child but not at the root.
thanks
Raanojay
|
|
|
|
|
i will send you the source codes. MSN: zhu_lin4103@126.com
it's my pleasure to make friend with you.
|
|
|
|
|
Thanks a lot, friend
where do I find the source codes ?
|
|
|
|
|
tell me your msn or your email, i will send to you
it's my pleasure to make friend with you.
|
|
|
|
|
Hi
i have two columns in the CListCtrl. i want to display the immage only for the subitems and not for the first column. The CListCtrl has set the extended style property of LVS_EX_SUBITEMIMAGES.
when i am trying to load the icons for the subitems it also displayes the first column. how to avoid displaying the icon in the first column?. is there any restrictions or precondition required?
Thanks in Advance
Gokul
|
|
|
|
|
|
Hi
I'm new to multi-threading.
I have 2 classes CClass1 and CClass2.
CClass2 creates a new thread. CClass1 needs to trigger a function in this new thread. So I'm thinking of doing
void CClass1::MyCode1()<br />
{<br />
PostThreadMessage(Class2ThreadID, MY_MESSAGE, wParam, lParam);<br />
}
and catch this in CClass2 using
BEGIN_MSG_MAP(CClass2)<br />
MESSAGE_HANDLER(MY_MESSAGE, MyCode2)<br />
END_MSG_MAP()
But how do I make sure MyCode2 runs in this thread that I will create in CClass2 as it gets instantiated?
void CClass2::InitThread()<br />
{<br />
HANDLE myThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) MyCode2, NULL, 0, &Class2ThreadID);<br />
}
Also, I don't want MyCode2 to run until the message is received, but with this, it looks like CreateThread is going to want to run MyCode2 as soon as it creates the thread.
I'm confused.
Please help!
|
|
|
|
|
PaulowniaK wrote: But how do I make sure MyCode2 runs in this thread that I will create in CClass2 as it gets instantiated?
Do you mean you want to ensure that the thread has started ?
If so, you could use GetExitCodeThread[^] on the handle to check if the exit code is STILL_ACTIVE .
Or you could have the CClass2 constructor wait on a manual reset event after creating the thread.
The thread can set the event when it starts running.
PaulowniaK wrote: Also, I don't want MyCode2 to run until the message is received
You don't want to run the thread until the message is received, but the message can be sent only when the thread is running. Is there a chicken and egg problem here?
Well, you could again use events here.
Create an event using CreateEvent[^] and pass the event handle to the thread.
The thread will wait for the event to be signaled as soon as it is started.
The rest of the stuff in the thread will execute only after the event has been signaled from your main class.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
<quote>Do you mean you want to ensure that the thread has started ?
Not quite. I was wondering how to "attach" MyCode2 to the new thread. If I just wrote a code for MyCode2 and just called it, it would run in the default thread and the not the one I created anew, right?
I've done:
<br />
void CClass2::InitThread()<br />
{<br />
CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) MyRoutine, NULL, 0, &hThread); <br />
}<br />
<br />
void CClass2::MyRoutine()<br />
{<br />
MSG msg;<br />
for(;;)<br />
{<br />
if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))<br />
{<br />
DoWork();<br />
}<br />
}<br />
}<br />
While CClass1 does PostThreadMessage.
It seems to work, but it is a scary thought that MyRoutine is running continuously looking for messages...
Maybe I need to read up about Events... hmmm...
Thanks for the help.
|
|
|
|
|
PaulowniaK wrote: Not quite. I was wondering how to "attach" MyCode2 to the new thread. If I just wrote a code for MyCode2 and just called it, it would run in the default thread and the not the one I created anew, right?
I've done:
void CClass2::InitThread()
{
CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) MyRoutine, NULL, 0, &hThread);
}
In the above code snippet MyRoutine will be started in a new thread. That is what CreateThread does for you.
PaulowniaK wrote: It seems to work, but it is a scary thought that MyRoutine is running continuously looking for messages...
Use GetMessage instead of PeekMessage so that it does not loop continuously.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|