|
Why don't you post your question we could all learn from the answer if it was answered.
P.S
Posted before I log in.
It is Illogical to define an inventor by his invention
|
|
|
|
|
I am not sure how to code the connect, bind and recieve. I have found nothing useful. I am trying to connect and only recieve data. I will not be sending any data. The program I am currently modifying was set up using TCP/IP. Please if anyone can assist me, please email me! Thanks!
trishv
|
|
|
|
|
www.MintMail.com/?m=640901
|
|
|
|
|
Unless you'd LIKE to sign up for a SPAM list that gives you 5 cents per email they send you, which probably comes in banana dollars. Speaking of which, is there anyone online who hasn't seen that annoying 'shock the monkey' banner ad ?
Christian
#include "std_disclaimer.h"
People who love sausage and respect the law should never watch either one being made.
The things that come to those who wait are usually the things left by those who got there first.
|
|
|
|
|
I have the following data
DWORD data, mask, pre_result, result;
int nShift;
data = 0xF4; // 11110100
mask = 0x04; // 00000100
pre_result = data | mask; // = 00000100
switch (mask)
{
case 0x01: nShift=0; break; // mask = 00000001
case 0x02: nShift=1; break; // mask = 00000010
case 0x04: nShift=2; break; // mask = 00000100
// other cases
}
result = pre_result >> nShift; // result = 1
is there a method to dynamically shift the bits of pre_result to obtain the bit value for result without using case statements?
pls help.
|
|
|
|
|
Given the values displayed for mask in the switch,
m = mask >> 1;
pre_result >> m;
should provide the same result.
BTW, the result of pre_result = data | mask is display incorrectly. It should be 11110100.
The value shown 00000100 would be the result of data & mask.
|
|
|
|
|
pre_result >> m
should be
pre_result >>= m
|
|
|
|
|
First of all, a small correction:
11110101 | 00000100 = 11110101
11110101 & 00000100 = 00000100
What are you trying to do? Do you want to check whether a specific bit is on?
Here's some quick information on bitwise operators:
OR (|) :
0 | 0 = 0,
1 | 0 = 1,
1 | 0 = 1,
1 | 1 = 1
AND (&) :
0 & 0 = 0,
1 & 0 = 0,
0 & 1 = 0,
1 & 1 = 1
XOR (^) :
0 ^ 0 = 0,
1 ^ 0 = 1,
0 ^ 1 = 1,
1 ^ 1 = 0
Now some examples:
value = 0xF4;
// 76543210
// 11110100
To turn on bit 1 : value |= 2; (value = value | 2; 2 because 2^1 = 2)
To turn on but 4 : value |= 16; (because 2^4 = 16)
To turn off bit 2: value &= ~4; (~4 is an int, all bits on except bit 2)
To check whether bit 5 is on:
if (value & 32) // 2^5 = 32, or 0x20
// it's on
Note that value & 32 does not return 1, but 32.
To get a result of 1 or 0 only, you can:
1) Use the and operator to turn off all other bits
2) Use a right shift (>>) to move bit 5 to 0
Example: (value&32) >> 5; (returns 1 or 0)
Hope this answers your question (and I hope I did't make any ridiculous errors
)
|
|
|
|
|
to check and set certain bits of a data value, that was what i was trying to get. Thanks for reading through my blunder of code, and samples code. That helps a lot.
Just another questions. What if I need to check 2 bits? for eg I want to set bits 1 and 2 to 10. Can I do it in the same way as you described?
mask = 6 // 00000110, for checking bits 1 and 2
value |= mask; // is this correct?
|
|
|
|
|
Hi all,
I am trying to display individual items in a list control in different colors, i am using SDK programming, can anybody help me with logic how it can be done, i tried using NM_CUSTOMDRAW, but i am not able to get the CDDS_ITEMPREPAINT message.
Thanks in advance
|
|
|
|
|
In the first NM_CUSTOMDRAW message, you need to return CDRF_NOTIFYITEMDRAW in order to get messages for each item's prepaint stage.
--Mike--
http://home.inreach.com/mdunn/
#include "buffy_sig"
|
|
|
|
|
How do you prevent a dialog box in an MFC app from closing when the user hits the Enter key?
|
|
|
|
|
Hi David !
Override OnOK() method in your dialog class and leave this method blank.
Best regards,
-----------
Igor Soukhov (Brainbench/Tekmetrics ID:50759)
igor_soukhov@yahoo.com | ICQ:57404554 | http://siv.da.ru
|
|
|
|
|
Override the OnOk() and OnCancel() function of the CDialog class. Another way is to map the WM_CHAR message for the dialog. I hope this helps.
|
|
|
|
|
Hi all.
I want to give telephone number to mscomm object,
So, i must use BSTR string ???
Because, SetOutput() function get VARIANT variable ...
If your reply is YES, please write example about converting char * variable to BSTR variable.
And write example about give data to BSTR variable.
Thanks.
void CTerminalDlg::OnFileConnect()
{
m_comm.SetCommPort(3);
m_comm.SetSettings("9600,N,8,1");
m_comm.SetRThreshold(255); // BITS FOR RECEIVE ...
m_comm.SetPortOpen(TRUE);
m_comm.SetOutput(/* MY QUESTION ... */);
m_comm.SetPortOpen(FALSE);
}
My month article: Game programming by DirectX by Lan Mader.
Please visit in: www.geocities.com/hadi_rezaie/index.html
Hadi Rezaie
|
|
|
|
|
char* str = "hello world";
BSTR bstr = _bstr_t(str);
Cheers!!!!
Carlos Antollini.
|
|
|
|
|
Now, How can i set bstr variable to the VARIANT structure ??? because i must use of VARIANT variable in SetOutput() function ...
Please help me ...
My month article: Game programming by DirectX by Lan Mader.
Please visit in: www.geocities.com/hadi_rezaie/index.html
Hadi Rezaie
|
|
|
|
|
_variant_t vtFld;
vtFld.vt = VT_BSTR;
vtFld.bstrVal = _bstr_t(strValue);
Cheers!!!
Carlos Antollini.
|
|
|
|
|
Thanks alot for your useful example about using variant.
My month article: Game programming by DirectX by Lan Mader.
Please visit in: www.geocities.com/hadi_rezaie/index.html
Hadi Rezaie
|
|
|
|
|
strange the vb sample in MSDN uses Chr$(13)
not Chr$(13) & Chr$(10)
any how CR is presented by '\r' and LF is presented by '\n'
Now I know,
cheers
Alfadhly
It is Illogical to define an inventor by his invention
|
|
|
|
|
I use the following code (which works as well)
COleVariant vSend = sMessage;
m_pMSComm->SetOutput( vSend );
You will have to watch out with the GetInput function though! I noticed there can be a huge memory leak if you use the variants the wrong way. You shouldn't not do it like this:
COleVariant vInput = m_pMSComm->GetInput();
CString sBuffer = vInput.bstrVal;
but like this:
COleVariant vInput.Attach (m_pMSComm->GetInput());
CString sBuffer = vInput.bstrVal;
Structured programming vs. chaotic mind boggling
|
|
|
|
|
Thanks alooooot, i found some good notice in your message.
My month article: Game programming by DirectX by Lan Mader.
Please visit in: www.geocities.com/hadi_rezaie/index.html
Hadi Rezaie
|
|
|
|
|
Do anyone know of any library that can load different file formats like TIFF, JPEG etc. I need that urgent in my appl
|
|
|
|
|
There's a free source code library at http://www.paintlib.de/paintlib/. I've succesfully used it in an MFC/Visual C++ project. Hope this helps.
- Peter H. Helmers
phelmers@rochester.rr.com
|
|
|
|
|
And if you want Targa, we wrote that for paintlib ages ago, but they seem to be slow in version releases nowadays. The mailing list also seems to have died. A shame, because it was very good, it still does a lot of stuff GDI+ does not do natively ( although as I wrote a lot of the filter classes especially ( also not in, if you want 3x3 spatial, gamma, colour, contrast, email me )), although I don't expect it will be too hard to write my own in GDI+.
Christian
#include "std_disclaimer.h"
People who love sausage and respect the law should never watch either one being made.
The things that come to those who wait are usually the things left by those who got there first.
|
|
|
|