|
Admittedly a newbie question about variants.
I'm using MSComm (an activeX object that handles serial port communications)
to communicate with a device that sends three hex bytes.
If I set input mode to binary input
example; m_comm.SetInputMode(1); //set input to binary
I get a very confused variant "oneChar":
COleVariant oneChar;
oneChar = m_comm.GetInput();
The oneChar.vt member shows "???" in the MS visual 6 IDE (it doesn't know
that it was a hex value... doesn't the data need to be propperly "stuffed"
into the variant structure by the device?... i.e. with a value and .vt
member type. What if it doesn't? How do you use MSComm with devices that
just send simple binary data?;P
If I leave input mode in character mode (default), the variant "oneChar"
thinks it's a BSTR. It must default to BSTR (How can I be sure that I'm
getting the correct value?)
|
|
|
|
|
Firstly, type the following into a watch window:
oneChar.vt,x
and look at the output. That should get you a reasonable value. If it doesn't, check that the address of oneChar looks reasonable; if not, your stack's probably been overwritten.
The debugger's automatic view of VARIANTs only understands simple variant types like VT_I4, VT_BSTR, etc. It doesn't understand compound types, such as arrays. You probably have a SAFEARRAY of BYTE in there - this would be VT_ARRAY | VT_UI1 (0x00002011). The VT_ enumerators are defined in wtypes.h.
--
Mike Dimmick
|
|
|
|
|
Thanks Mike, You were right on about it being a SAFEARRAY OF BYTE (00002011)
How do you look at the value of 00002011; safearray and byte are a combined type? In addition, I haven't been able to change the type to integer for some reason (it throws an afxOle exception) and doesn't get to the next instruction in the program.
oneChar.ChangeType(VT_UINT)
Instead, I've set the input mode to text and dereferenced the variant to get an integer... somehow this seems to work... but I'm uncomfortable with it because I don't really understand why. oneChar.vt,x shows 0008, so I understand that the variant contains a BSTR value.
oneChar= m_comm.GetInput();
int b1 = *oneChar.bstrVal;
|
|
|
|
|
Hi All,
I have an MFC dialog App that has several controls in it, including a bunch of Edit boxes.
What I'd like to do is trap the "Enter" key message from each of these edit boxes in order to do some special processing.
How do I do this in an MFC App? I'd like to get the event from that control instead of just trapping a general keyboard message and then having to determine which key was pressed and which control has the focus.
Any suggestions?
Thanks!
Dan
|
|
|
|
|
Maybe you need to handle PreTranslateMessage.
If you subclass the control, have a look at WM_GETDLGCODE.
|
|
|
|
|
CEdit is a CWnd object maybe you can Overide
afx_msg void OnChar( UINT nChar, UINT nRepCnt, UINT nFlags );
|
|
|
|
|
Hi,
I have two identical computers on the network. The VC++ software I wrote can only be running on one of the machines at a time. Is there a way to enumerate or check the exe's running on the other computer.
Thanks
Tim
|
|
|
|
|
I don't think so. If you had a shared location they could both access you could create a file there though which would indicate the program was running.
|
|
|
|
|
There are several solutions. One solution is COM in a local process would connect to the remote process. The remote process would update its status. A simpler solution is socket.
Kuphryn
|
|
|
|
|
Thanks, I was trying to stay away from COM. I'm not that familiar with it. I thought about using a socket but I wasn't sure if windows had something already for this purpose.
Tim
|
|
|
|
|
You could enumerate the processes on the other computer but that would require you have the proper [administrative] rights. It could also be unreliable if someone changed the name of the executable.
See http://www.sysinternals.com/[^] for code on enumerating processes and other things.
I think a simple socket idea is probably the best.
|
|
|
|
|
i have quite a good solution!
use the CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, NULL ) to get a complete list of the running processes on the local machine...
have a look at msdn under CreateToolhelp32Snapshot, you will find a useful code snippet there.
|
|
|
|
|
Hello all,
I thought when I call erase() method on an STL deque, it is supposed to call the corresponding destructor of the object. However, it does not when I do this. Here is some code to illustrate the problem.
std::deque<wave *=""> _wavePool;
std::deque<wave *="">::iterator it;
Wave *wav1 = new Wave("D:\\waves\\v1.wav", true);
Wave *wav2 = new Wave("D:\\waves\\think.wav", true);
_wavePool.push_back(wav1);
_wavePool.push_back(wav2);
it = _wavePool.begin()
Now, if I call...
_wavePool.erase(it);
The wave destructor never gets called. Am I not supposed to put heap pointers in a queue or do I have to do this manually.
Thanks for any help you might give me.
Pankaj
Without struggle, there is no progress
|
|
|
|
|
I think the rule is that anything you create on the heap you have to free yourself. Or you could use a deque of auto_ptr<>. I think the best advice is to grab the boost stl library[^] and use a scoped_array or something along htose lines.
|
|
|
|
|
Erik Juhl wrote:
I think the rule is that anything you create on the heap you have to free yourself.
Yes, anything you create on the heap you delete yourself. You could use some type reference counting pointer for this or call the delete yourself. I do the latter more often.
John
|
|
|
|
|
erase() calls destructor of contained objects, not delete. destructor of a pointer just destroys the pointer variable, not the underlying object. you have to delete allocated objects explicitly.
|
|
|
|
|
Use auto_ptr instead of the pointers directly:
std::deque< auto_ptr<Wave> > _wavePool;
std::deque< auto_ptr<Wave> >::iterator it;
auto_ptr<Wave> wav1(new Wave("D:\\waves\\v1.wav", true));
_wavePool.push_back(wav1);
wav1->Splash();
_wavePool.erase(it);
Regards,
Alvaro
When birds fly in the right formation, they need only exert half the effort. Even in nature, teamwork results in collective laziness. -- despair.com
|
|
|
|
|
Hi:
i have an EditBox and i wanted to change the default style "Left To Right Reading Order" to "Right To Left..." at run-time so i used the
following code:
SetWindowLong(m_hWnd,GWL_EXSTYLE,WS_EX_RIGHT);
successfully,the style of editbox changed,But when i want to swith
between "RTL" To "LTR" ,the above function doesn't work!!! in the other hand i used this code:
SetWindowLong(m_hWnd,GWL_EXSTYLE,WS_EX_LEFT);
But function didn't work.is there another way to achieve this effect?
Please help me.
Regards.
|
|
|
|
|
Try it this way with ModifyStyleEx:
ModifyStyleEx(0, WS_EX_RIGHT);
ModifyStyleEx(WS_EX_RIGHT, 0);
Regards,
Alvaro
When birds fly in the right formation, they need only exert half the effort. Even in nature, teamwork results in collective laziness. -- despair.com
|
|
|
|
|
Can I Set up a Spin ctrl to vary the number in a Edit box from 0.0 to 5.0 in Increments of 0.5 ?
|
|
|
|
|
|
Hi,
Set the Spinboxrange from 0 to 10
(0->0, 1->0.5, 2->1, 3->1.5, etc)
You can use the DialogMethod OnVScroll
The Message is WM_VSCROLL
put this Code in the OnVSrollMethod
void YourClassName::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar){
CString str;
if(pScrollBar==GetDlgItem(IDC_SPIN_..)){ //Insert here you SpinID
str.Format("%.1f",(double)(nPos/2.0));
GetDlgItem(IDC_EDIT_SPINVALUE...)->SetWindowText(str);
}
}
hope this helps
|
|
|
|
|
Hello:
I´m using CWorkQueue ( <ahref="">http://www.codeproject.com/useritems/Work_Queue.asp )in my project. I´m making a new class which is inherited from CWorkBaseItem. So OverWrite the doWork method where I create a socket and send a message. Everything work ok,
but I can see that the WorkQueue doesn´t destroy the terminated threads.
Anybody know how i can free all threas which had terminated????
el hombre arriesga su vida cada vez que elige y eso es lo que lo hace libre
|
|
|
|
|
Hi, do someone know how to get Systeminformations (like Memory Usage, Device Information, CPU, Totalmemory) in Win32 C++ under WindowsXP / Windows 98 / Linux ?
My Ideas:
CPU
With an Highresolutiontimer i can calculate the CPU Speed (MHz) but not the Facturer...
I have found some sources for older cpus, but i can't detect newer ones and neither special attributes like do they use mmx or sse2...
VGA
With OpenGL I can retrieve Informations about the graphic adapter like extentions, current videomode. But I need Informations of video buffers (do they supply quadbuffer for iGlasses?) or video memory (128MB DDR, 93.2 MB free)
Thanks alot for reading this, may be there is anyone who can help me...
Sendel
|
|
|
|
|
You can get most system information you want.
Here's a way of calculating CPU speed. It's not 100% accurate but close enough:
#pragma warning( disable: 4035 )
inline unsigned __int64 GetCycleCount()
{
_asm
{
_emit 0x0F
_emit 0x31
}
}
#pragma warning( default: 4035 )
int GetCPUSpeed()
{
Sleep( 0 );
const unsigned __int64 ui64StartCycle = GetCycleCount();
Sleep( 1000 );
return static_cast<int>( ( GetCycleCount() - ui64StartCycle ) / 1000000 );
}
|
|
|
|