Re: using lParam if it's a pointer

  • From: "Will Pearson" <will@xxxxxxxxxxxxx>
  • To: <programmingblind@xxxxxxxxxxxxx>
  • Date: Wed, 12 Dec 2007 11:04:37 -0000

Hi Tyler,

Yes, the first member declared is usually the first member in memory.  Memory 
layout can depend on the compiler and compiler options used, and so it is 
probably worth checking your compiler's documentation to be sure.

The size of structs are fixed though, and their size depends on their 
declaration in the header file in which they are declared.  So, you can usually 
get away with creating a struct of the type you need without looking at the 
size member.  There are some exceptions to this, such as when you may be 
dealing with multiple structs and you are unsure which you will need in a given 
situation and you need to then dynamically allocate them based on their size, 
but these situations aren't encountered that often.

Will
  ----- Original Message ----- 
  From: Littlefield, Tyler 
  To: programmingblind@xxxxxxxxxxxxx 
  Sent: Wednesday, December 12, 2007 3:35 AM
  Subject: Re: using lParam if it's a pointer


  thanks. will do.
  Also. one last question.
  If I have a struct like:
  struct data{
  int a,b,c,d,e,f,g;
  };
  will it order it in memory with a being first, g being last? I'm working on a 
program that requires me to have an int size, and then read the first 4 bytes 
to know how big the struct is.
  Thanks,
  Tyler Littlefield
  Vertigo head coder.
  "I can only please one person per day; Today doesn't seem like your day, and 
tomorrow doesn't look to promising either."
  "A life? Where can I download that at?"

  Contact information:
  email: tyler@xxxxxxxxxxxxx
  skype: st8amnd127
  aim: st8amnd2005
  msn: tyler@xxxxxxxxxxxxx
    ----- Original Message ----- 
    From: Will Pearson 
    To: programmingblind@xxxxxxxxxxxxx 
    Sent: Tuesday, December 11, 2007 4:56 PM
    Subject: Re: using lParam if it's a pointer


    Hi Tyler,

    I suspect you will need to cast the lParam value.  If you don't then the 
compiler won't know that you are dealing with a structure and you will likely 
get some compile errors.  As the structure is a user defined data type then 
there are likely no standard conversions.

    Without a conversion the compiler will asumme that you are just dealing 
with an unsigned 32-bit integer.  LPARAM's is a typedef for LONG_PTR, and 
LONG_PTR is in turn a typedef for long.  As 32-bit unsigned numeric values 
don't have members then tge compiler is likely to trow some compile errors.

    Will
      ----- Original Message ----- 
      From: Littlefield, Tyler 
      To: programmingblind@xxxxxxxxxxxxx 
      Sent: Tuesday, December 11, 2007 11:18 PM
      Subject: Re: using lParam if it's a pointer


      it says it's a pointer to a struct. I just want to get the data at like 
lParam->foo;

      Tyler Littlefield
      Vertigo head coder.
      "I can only please one person per day; Today doesn't seem like your day, 
and tomorrow doesn't look to promising either."
      "A life? Where can I download that at?"

      Contact information:
      email: tyler@xxxxxxxxxxxxx
      skype: st8amnd127
      aim: st8amnd2005
      msn: tyler@xxxxxxxxxxxxx
        ----- Original Message ----- 
        From: Ken Perry 
        To: programmingblind@xxxxxxxxxxxxx 
        Sent: Tuesday, December 11, 2007 7:30 AM
        Subject: RE: using lParam if it's a pointer




        This depends if your doing it in c++ or C but truthfully it probably 
doesn't matter you should be able to do it with out a cast but it would give 
you a warning it really depends on what your doing with it.

        Ken



------------------------------------------------------------------------
        From: programmingblind-bounce@xxxxxxxxxxxxx 
[mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of Littlefield, Tyler
        Sent: Tuesday, December 11, 2007 5:27 AM
        To: programmingblind@xxxxxxxxxxxxx
        Subject: using lParam if it's a pointer


        Hello list,
        I've got a question.
        I'm using a callback function, and lParam contains a pointer to a 
struct of data.
        I'm using like lParam->bla=32; do I need to cast lParam to the struct 
first? (struct)lParam->bla=32;
        Thanks,
        Tyler Littlefield
        Vertigo head coder.
        "I can only please one person per day; Today doesn't seem like your 
day, and tomorrow doesn't look to promising either."
        "A life? Where can I download that at?"

        Contact information:
        email: tyler@xxxxxxxxxxxxx
        skype: st8amnd127
        aim: st8amnd2005
        msn: tyler@xxxxxxxxxxxxx

Other related posts: