Jump to content
  • Advertisement
Sign in to follow this  
gretty

Creating my own LPARAM: 32 bits of data

This topic is 2554 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello

I want to create my own LPARAM to pass to the win32 function GetKeyNameText(), (the first parameter takes a LPARAM var).

This may seem like doing things the hard way, but its a work around for not having specific amounts of information & also working at the bit level is REALLY confusing to me which is why I want to familiarise myself with this.

So what I want to put in my LPARAM var is:
- set the 16-23 bits to the keyboard Scan code: I've got the scan code I just dont know how I would combine it into a 32bit variable?
- set the 24th bit to the extended-key flag (I have no idea how to get this yet alone how to combine it into a 32 bit variable)
- set the 25th bit to the dont care bit to I do care - so would I set this bit to 1?

So I understand the way binary & bits work...I think, its amazing I understand higher lvl concepts like polymorphism but not lower lvl computer hardware stuff :P

So I have a 32 bit(or byte?) variable, does that mean I have 32 0's & 1's: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
OR
I have a variable like this XXXXXX, eg 100011 where the last number is 2^0(so 1), then 2^1(2), then 2^2(4), .... then finally 2^5(32).

So to create my LPARAM would I do this:


DWORD scanCode = 0x??; // a DWORD is a 32bit var, but the scan code is only 7 bits long?
bit extFlag = 1; // now is there a bit variable? How can I find out the extended-key flag also?
bit careBit = 1;

//Now to combine it all would I do this?
DWORD myLParam = scanCode & extFlag & careBit;
// OR
LPARAM myLParam = scanCode & extFlag & careBit;

Share this post


Link to post
Share on other sites
Advertisement
You can either do this with bitfields in a dummy structure (more clear) or binary masking (slightly less clear but just as effective). I'd recommend bitfields to start off with as your grasp of binary operations is a bit shaky (e.g. the & operator doesn't do what you think it does).

Share this post


Link to post
Share on other sites
As a quick example for bitfields


struct MyBitStuffedThingy
{
unsigned int a : 16;
unsigned int b : 8;
unsigned int c : 4;
};

Share this post


Link to post
Share on other sites
Thanks for the code example :)

Would that structure be able to be converted to a LPARAM? I dont think its possible but you never know.

I cant do something like this can I:

MyBitStuffedThingy b;
GetKeyNameText( (LPARAM)b, ...);

Share this post


Link to post
Share on other sites
The missing piece is unions:

union MyBitFields
{
struct Bits
{
unsigned Alpha : 16;
unsigned Beta : 8;
unsigned Gamma : 4;
unsigned IForgetMyGreek : 4;
};
unsigned ThirtyTwoBits;
};

MyBitFields value;
value.Alpha = 0xffff;
value.Beta = 0xaa;
value.Gamma = 1;
value.IForgetMyGreek = 0;
SomeAPI(value.ThirtyTwoBits);

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!