|
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!
|
|
|
|
|
how to obtain messages that have been posted/sent into a control?
SPY++ only shows messages that the control has sent out, not messages that it receives
help file from spy++
[QUOTE]
P The message was posted to the queue with the PostMessage function. No information is available concerning the ultimate disposition of the message.
S The message was sent with the SendMessage function. This means that the sender doesn’t regain control until the receiver processes and returns the message. The receiver can, therefore, pass a return value back to the sender.
s The message was sent, but security prevents access to the return value.
R Each ‘S’ line has a corresponding ‘R’ (return) line that lists the message return value. Sometimes message calls are nested, which means that one message handler sends another message. [/QUOTE]
|
|
|
|
|
Assuming that you have the source for the control, you can override the DefWindowProc() function and insert whatever message traps you want.
|
|
|
|
|
awah wrote: SPY++ only shows messages that the control has sent out, not messages that it receives
Incorrect. Spy++ shows the messages sent to a control. The 2nd value in the spy display is the window handle of the RECEIVING window. What you can't tell is where the message originated.
Judy
|
|
|
|
|
Dear all
how to do colour image quantization using VC++? who has code snippet? thanks a lot.
zhiyuan li
Li Zhiyuan
27/06/2007
|
|
|
|
|
|
while(getline(passage,nextword,'\n'))
{
int status = 0;
transform(nextword.begin(), nextword.end(), nextword.begin(), (int(*)(int))std::toupper);
int x=nextword.find(test1);
int y=nextword.find(test2);
int z=nextword.find(test3);
if(x!=std::string::npos)
{
status = 1;
}
if(y!=std::string::npos|| z!=std::string::npos)
{
status = 2;
}
string nextword;
ostringstream os(nextword);
string readInWord;
while (os>>readInWord)
{
if (status==0)
++wordCount[readInWord];
else if (status==1)
{
++wordCount[readInWord];
++single[readInWord];
}
else if (status==2)
{
++wordCount[readInWord];
++single[readInWord];
++compound[readInWord];
}
}
}
I am trying hard to get this code to work but seems to be something wrong. I am testing for 3 things and if present I am trying to update certain maps accordingly. I am getting some sort of error on the ostringstream os(nextword) not sure what this is or what it does. Someone put it in my code saying this would fix my problem but I have yet to figure it out.
|
|
|
|
|
andyspartyshop wrote: not sure what this is or what it does
Then why are you using it ? If you search this site for ostringstream, I have an article on it.
You're initialising a stringstream with a string which has not been initialised ( although it will initialise to "" ). What's the point of that ?
The code is pretty messy. At a minimum, change the if/else to a switch block and give x/y/z more meaningful names.
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 )
|
|
|
|
|
Hi All,
Can any one tell me how to convert LPRSTR data type to string date type in VC++. I am doing in the following way.
LPTSTR testLpt; // this I am getting from some method
string testStr = string(testLpt);
I am getting type cast error.
Can any tell me how to do this?
Thanks in advance.
Regards,
JK
|
|
|
|