Click here to Skip to main content
15,895,777 members
Home / Discussions / COM
   

COM

 
AnswerRe: interview question on COM Pin
sheshidar21-Jul-06 18:58
sheshidar21-Jul-06 18:58 
GeneralDCOM Connection in Windows XP SP2 Pin
shibu george21-Jul-06 1:48
shibu george21-Jul-06 1:48 
GeneralRe: DCOM Connection in Windows XP SP2 Pin
sudeesh24-Jul-06 21:01
sudeesh24-Jul-06 21:01 
GeneralRe: DCOM Connection in Windows XP SP2 Pin
shibu george26-Jul-06 18:51
shibu george26-Jul-06 18:51 
GeneralRe: DCOM Connection in Windows XP SP2 Pin
Steve S26-Jul-06 21:24
Steve S26-Jul-06 21:24 
QuestionActivex control Pin
sunita ramesh21-Jul-06 0:24
sunita ramesh21-Jul-06 0:24 
Question#pragma pack Pin
anu_8820-Jul-06 23:01
anu_8820-Jul-06 23:01 
AnswerRe: #pragma pack Pin
Steve S20-Jul-06 23:32
Steve S20-Jul-06 23:32 
If you declare a struct with

char dummy;
short x;
long y;

members, the "optimal" size would be 1 + 2 + 4 (assume x86 for the moment).
However, this would be with alignment of 1. This says what byte boundary you use for packing. With an alignment of 2, each member begins on the next available 2 byte boundary, so the single char would be followed by an unnamed pad byte, the short would already be aligned correctly, as would the long.

Similarly with 4 byte, the char is followed by 3 unnamed pad bytes, the short by another two, and the long would be OK as is.

I can almost hear you asking "Why would I want to waste memory like that?"
[fx: pause for reader to actually ask...]

It's all to do with the way the processor accesses memory, and for some CPUs, like the SPARC, trying to access a packed (1) long would cause an exception.

The important thing is to consistently use the same alignment for all in memory versions of a structure. For instance, if you build a DLL with a function that takes a structure, the declaration of that structure should really include

#pragma pack(push)
#pragma pack(n)
struct {
....
};
#pragma pack(pop)

so that irrespective of the compile time options elsewhere, it has the packing n (where n is a power of 2). Without this, you might build the DLL with pack(2), for instance, and a client might be built with pack(1). This would misalign the data, and might even result in an access violation when you call the DLL function.

Does that help?

Steve S
Developer for hire
GeneralRe: #pragma pack Pin
anu_8821-Jul-06 0:32
anu_8821-Jul-06 0:32 
Questionsafearray of user defined structure store in variant Pin
rudo3220-Jul-06 21:31
rudo3220-Jul-06 21:31 
AnswerRe: safearray of user defined structure store in variant Pin
Aamir Butt25-Jul-06 0:29
Aamir Butt25-Jul-06 0:29 
AnswerRe: safearray of user defined structure store in variant Pin
Tim Paaschen25-Jul-06 2:42
Tim Paaschen25-Jul-06 2:42 
QuestionEcxel.dll is not working Pin
ersinsivaz20-Jul-06 10:00
ersinsivaz20-Jul-06 10:00 
Questionsafearray access returns junk pls help Pin
nikhil_ag198520-Jul-06 2:07
nikhil_ag198520-Jul-06 2:07 
QuestionGUID [modified] Pin
RRRB20-Jul-06 0:09
RRRB20-Jul-06 0:09 
AnswerRe: GUID Pin
nikhil_ag198520-Jul-06 2:14
nikhil_ag198520-Jul-06 2:14 
GeneralRe: GUID Pin
RRRB20-Jul-06 2:26
RRRB20-Jul-06 2:26 
AnswerRe: GUID [modified] Pin
sudeesh26-Jul-06 3:07
sudeesh26-Jul-06 3:07 
QuestionPlease help. Problem with including .idl file [modified] Pin
Kiran Pinjala19-Jul-06 21:35
Kiran Pinjala19-Jul-06 21:35 
AnswerRe: Please help. Problem with including .idl file Pin
Steve S19-Jul-06 21:59
Steve S19-Jul-06 21:59 
GeneralRe: Please help. Problem with including .idl file Pin
Kiran Pinjala19-Jul-06 23:47
Kiran Pinjala19-Jul-06 23:47 
Questionhow to use activeX inside ActiveX [modified] Pin
Chetan Sheladiya19-Jul-06 19:38
professionalChetan Sheladiya19-Jul-06 19:38 
AnswerRe: how to use activeX inside ActiveX Pin
Prakash Nadar1-Aug-06 1:18
Prakash Nadar1-Aug-06 1:18 
Questionhow to login Pin
With_problem19-Jul-06 17:48
With_problem19-Jul-06 17:48 
Questionstarting problem with Netmeeting sdk program Pin
Kiran Pinjala19-Jul-06 2:28
Kiran Pinjala19-Jul-06 2:28 

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.