c++ and windows api

B

B.C.

This might be a stupid question but the answer evades me at this moment. You
know how in C/C++ compiler settings influence the size of
structures/classes. How come the windows api (which often takes pointers to
structures as parameters) still works independently of my compiler settings?

Thanks
 
D

David

Hello B.C.,

This might be a stupid question but the answer evades me at this moment. You
know how in C/C++ compiler settings influence the size of
structures/classes. How come the windows api (which often takes pointers to
structures as parameters) still works independently of my compiler settings?

Thanks

The pointers are a certain, agreed upon size. The structures that they
point
to could have problems with your code if your code did not obey the packing
options expected by the Windows API. There are several ways to control
packing
in C and C++. One is by the compiler settings and that controls the packing
options for the entrire compile session. Another method is to use the
"#pragma pack" option. This can be used to set a desired packing option and
later restore the packing option to the default level. Good communications
code that depends on the packing options of a structure will include these
packing options around the critical structures in its headers. If you look
at the headers that define such critical Windows API Structures, you will
find where they have enclosed those structures with the desired packing
options. This is no different than how any other API could achieve the
same goal.

I hope that jogs your memory for you.

David
 
B

B.C.

Yes, it makes sense. I took a look at some h files and you are right, some
of the files include pshpack4.h which makes use of the #pragama pack option

Thank you

Thank you
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,202
Messages
2,571,057
Members
47,660
Latest member
vidotip479

Latest Threads

Top