|
Axonn Echysttas wrote: This still returns garbage data : ( ... what do you make of: "???r" instead of "Arial". And it's sure that it's a BSTR there. For example, my function works but doesn't process the BSTR correctly. It would be easier for me to fix my function ... if only I knew what's wrong : D.
Watch memory for this variable to see if the contents is in the variable as you expect it to be.
|
|
|
|
|
Your functions are wrong. Note that a bstr is not required to be null terminated. If you want to get the size of a BSTR, use for example wcslen. To convert between BSTR and C-style strings, use
W2A, OLE2A macros from <AtlBase.h>. Also see CComBSTR class.
--
=====
Arman
|
|
|
|
|
I replaced with wcslen and still same problem. I would prefer to understand how to convert it corectly, manually. That way I don't have to depend on more links and stuff that can break from one windows release to the other : ).
|
|
|
|
|
|
|
Arman Z. Sahakyan wrote: Note that a bstr is not required to be null terminated.
Actually BSTR is terminated by double byte NULL. \0\0
Best Wishes,
-David Delaune
|
|
|
|
|
Hi,
Try using:
<br />
template<class T> BSTR ConvertToBSTR(T a_Str) <br />
{<br />
return(_bstr_t(a_Str).copy());<br />
}<br />
It's the same function I posted in your article two years ago.
Best Wishes,
-Randor (David Delaune)
|
|
|
|
|
Hhahahaah, Hi : D. That should be a lesson to me huh? To better remember stuff.
Hm, however, this is to return a BSTR, I need the other way around. A Char from a BSTR. : D.
|
|
|
|
|
Hi again,
The _bstr_t has a built-in char* operator. So this means you can just do something like this:
<br />
BSTR test;<br />
char buffer[SOME_LENTH];<br />
_bstr_t bstr(test,true);<br />
strcpy(buffer,(char*)bstr);<br />
The above code does not check buffer length. A simple new/delete using the BSTR length should take care of that.
Best Wishes,
Randor (David Delaune)
|
|
|
|
|
What's very interesting is that I managed to solve everything just like this:
LPCSTR a = (LPCSTR)myBSTR;
MessageBox(0, a, 0, 0); //-> it works, if you can believe it!!! Probably because I send only non-Unicode stuff from VB. Anyway, this is how it's gonna stay for a while and I don't intend to ever switch this program to Unicode. Works just fine like it is.
|
|
|
|
|
When I display the dialog created by CPropertySheet::DoModal, some other window in background is coming between the proprty sheet dialog and application. After clicking "OK" or "Cancel" of dialog the application is getting the focus. But Can I avoid other window coming between main window and dialog?
Best Regards,
Suman
|
|
|
|
|
Can you tell, how third window is associated with this application ?
Prasad
MS MVP - VC++
|
|
|
|
|
The third window may be the windows explorer or any application.
Before displaying property sheet, if there is any changes in GUI data,
I am updating data with progress dialog created by thread. After the progress finish,
I am calling DestroyWindow()of progress dialog and then displaying property sheet.
The third window is coming between application and property sheet after the DestroyWindow() of dialog.
Best Regards,
Suman
|
|
|
|
|
I work with Visual C++ (at the moment in Visual Studio2005). I have a resizable dialog bar - from a class I derived from CDialog bar to be resiable. When i am resizing (reducing) the main window the dialog bar is also resizing but after a certain point dialog bar disappears, And it visible only after resizing the (increasing) the main window. What i want is that after a certain point user should not be able to resize the window any more. How do i do that ?
Sandip
|
|
|
|
|
g_sandipan wrote: What i want is that after a certain point user should not be able to resize the window any more. How do i do that ?
Override afx_msg void OnGetMinMaxInfo( MINMAXINFO* lpMMI ) by handling WM_GETMINMAXINFO and fill out lpMMI->ptMinTrackSize with minimum height and width.
|
|
|
|
|
Thanks Nibu. Its Working fine
Sandip
|
|
|
|
|
Excuse me if I post in the wrong place but I'm having a very wierd problem.
I have an application written with MFC. Basically, it has around 10 worker threads doing smth continuously and post message to CMainFrame when done. The MainFrame will process these messages and update some list control on GUI. Simple, isnt' it?
Originally, I test and deploy my application on a Windows XP SP2 machine with CPU Celeron 2,4GHz. It runs well although it consumes 40-50% CPU all the time.
Now, I have a server with CPU Xeon 3GHz, 1GB RAM, SCSI hard disk with RAID 1 (seems to be an overkill hah). On this server, my application only consumes 5% CPU but it runs LIKE HELL. It takes ages for me to access menu items and do other things on the GUI. In other word, the GUI seems to be frozen regularly. I don't know what's going on !!!
I guess that because windows server 2003 has some mechanism to schedule and distribute CPU between applications. I have tried to config Processor scheduling & memory usage to best performance for program, it helps improves a bit, but still far from what's shown on the old Celeron computer !!! Setting process priority into "real time" in task manager also doesn't help.
I'm clueless now, any one please help me
|
|
|
|
|
You really need to look at your implementation.
I don't know what your threads are doing but you need to make sure the UI thread gets some time
to do stuff. If you're posting too many messages to the UI thread from the worker threads
then the UI thread can't handle user input/output tasks as effectively.
Changing hardware platforms really can expose these problems
Instead of using the UI message queue, you may want to look into queing messages yourself (in a
FIFO list, for example) and handling them during idle times on the UI thread.
Mark
"Go that way, really fast. If something gets in your way, turn."
|
|
|
|
|
thanks,
I have checked by installing windows server 2003 on my old Celeron computer and found that the problem was not because of the OS (windows 2003 or XP) but because of changing hardware platform.
I shall checked my implementation as your suggestion, thanks for that. But I wonder if there is a way to optimize code compiling for an Intel Xeon server (32 bit). There is an option "Target machine" in project properties but that seems to be not working since changing it cause my project not compilable.
|
|
|
|
|
Optimizing for specific hardware is way out of my league.
From what I've read, it's best to let the OS handle it unless one really know's what (s)he's
doing.
Most often, multithread problems are in the implementation.
Mark
"Go that way, really fast. If something gets in your way, turn."
|
|
|
|
|
For example:
<br />
<br />
BYTE b[16];<br />
BYTE b2[32];<br />
BYTE b3[64];<br />
<br />
vector<???> v;
<br />
v.push_back(?);<br />
v.push_back(?);<br />
v.push_back(?);<br />
If I declaration like this:
<br />
BYTE b[16];<br />
<br />
vector<BYTE*> v;<br />
v.push_back(b);<br />
The item what stored in vector is the point to b, but not the data;
|
|
|
|
|
You probably want to store BYTE *, which can then point to arrays of various sizes. Or, you want a vector of vectors of bytes, which is probably harder to work with.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Perhaps the Boost's Any[^] library is what you're after.
Steve
|
|
|
|
|
|
vector<vector<BYTE> >?
Angle brackets get chopped off when not enclosed in pre tags.
[edit]Even weirder things happen with nested <>[/edit]
- S
50 cups of coffee and you know it's on!
|
|
|
|