Click here to Skip to main content
15,888,527 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Cross referencing resource ID between source code and resource file ? Pin
David Crow26-Oct-10 4:27
David Crow26-Oct-10 4:27 
AnswerRe: Cross referencing resource ID between source code and resource file ? Pin
Sauro Viti26-Oct-10 4:45
professionalSauro Viti26-Oct-10 4:45 
QuestionC++ parser Pin
Andrea Di Domenico26-Oct-10 3:44
Andrea Di Domenico26-Oct-10 3:44 
AnswerRe: C++ parser Pin
Cedric Moonen26-Oct-10 4:45
Cedric Moonen26-Oct-10 4:45 
GeneralRe: C++ parser Pin
Andrea Di Domenico26-Oct-10 5:27
Andrea Di Domenico26-Oct-10 5:27 
GeneralRe: C++ parser Pin
Cedric Moonen26-Oct-10 7:25
Cedric Moonen26-Oct-10 7:25 
AnswerRe: C++ parser Pin
CPallini26-Oct-10 5:58
mveCPallini26-Oct-10 5:58 
AnswerRe: C++ parser [modified] Pin
Rick York26-Oct-10 8:14
mveRick York26-Oct-10 8:14 
I am not sure how experienced you are in C++ but one thing you will find is that the address operator (&) does not work with bits of a byte. This will be a very important factor since you are configuring which bits to peel apart.

One thing I have done to help with this is I made functions to unpack the bits of a byte into an array of bytes and to also do the converse - pack the LSB of an array of bytes into one byte. Here is what the unpacker looks like :


void BitUnpack( uchar byteArray[], uchar bits )
{
    for( uint n = 0; n < 8; ++n )
    {
        uchar mask = 1 << n;
        byteArray[n] = ( bits & mask ) ? 1 : 0;
    }
}


This will give you an array of bytes where each one corresponds to the value of the bit at that location. This means that byteArray[2] will be 1 if the 3rd bit is set and it will be 0 if not. If you unpack all of the bits of your message into array of bytes it will be easy to then repack, say, bits 3-7 into one value and so on.

Note that the function above unpacks just one byte. If you call this repeatedly you can unpack all of the bytes you receive into arrays for processing later. BTW - you may want to tweak the packer function to have it pack arbitrary numbers of bits to make things easier for you later. Here's the packer I use :

void BitPack( uchar byteValue, uchar byteArray[] )
{
    for( uint n = 0; n < 8; ++n )
    {
        if( byteArray[n] )
        {
            uchar mask = 1 << n;
            byteValue |= mask;
        }
    }
}


If you always work exclusively with 16-bit values then change the uchars to ushorts and the 8s to 16s and you should be ready to go. I should mention that I define the uchar, ushort, uint, and ulong types for myself but you don't have to use those since VC++ already defines the capitalized versions of these types.

What this all comes down to is sorting out the bits and then reassembling them later. I hope these functions give you some ideas on how to approach this.

modified on Tuesday, October 26, 2010 6:13 PM

JokeRe: C++ parser Pin
Alain Rist26-Oct-10 10:48
Alain Rist26-Oct-10 10:48 
GeneralRe: C++ parser Pin
Rick York27-Oct-10 10:37
mveRick York27-Oct-10 10:37 
GeneralRe: C++ parser Pin
Alain Rist27-Oct-10 10:59
Alain Rist27-Oct-10 10:59 
GeneralRe: C++ parser Pin
Andrea Di Domenico2-Nov-10 3:47
Andrea Di Domenico2-Nov-10 3:47 
AnswerRe: C++ parser Pin
Alain Rist26-Oct-10 10:44
Alain Rist26-Oct-10 10:44 
QuestionHow to update records on live(remote) database from local machine ... Pin
shiv@nand25-Oct-10 23:58
shiv@nand25-Oct-10 23:58 
QuestionRe: How to update records on live(remote) database from local machine ... Pin
David Crow26-Oct-10 3:42
David Crow26-Oct-10 3:42 
QuestionAbout dialog bar that supports a drop-down for extra controls in it Pin
Nishad S25-Oct-10 19:46
Nishad S25-Oct-10 19:46 
AnswerRe: About dialog bar that supports a drop-down for extra controls in it Pin
Niklas L25-Oct-10 21:45
Niklas L25-Oct-10 21:45 
GeneralRe: About dialog bar that supports a drop-down for extra controls in it Pin
Nishad S25-Oct-10 22:06
Nishad S25-Oct-10 22:06 
QuestionCrash Pin
T.RATHA KRISHNAN25-Oct-10 19:08
T.RATHA KRISHNAN25-Oct-10 19:08 
AnswerRe: Crash Pin
Cedric Moonen25-Oct-10 20:22
Cedric Moonen25-Oct-10 20:22 
AnswerRe: Crash Pin
Niklas L25-Oct-10 21:11
Niklas L25-Oct-10 21:11 
AnswerRe: Crash Pin
Stephen Hewitt25-Oct-10 21:11
Stephen Hewitt25-Oct-10 21:11 
AnswerRe: Crash Pin
Sivaraman Dhamodharan25-Oct-10 22:43
Sivaraman Dhamodharan25-Oct-10 22:43 
Questionhello how to make a injector that reinjects everytime the dll if specified process reloads and changes hes pid Pin
nah133725-Oct-10 7:57
nah133725-Oct-10 7:57 
AnswerRe: hello how to make a injector that reinjects everytime the dll if specified process reloads and changes hes pid Pin
«_Superman_»25-Oct-10 8:10
professional«_Superman_»25-Oct-10 8:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.