#importing a typelibrary with non-8 byte alignment 
Author Message
 #importing a typelibrary with non-8 byte alignment

Hi,

I have a type library generated by delphi with 1-byte alignment and I want
to use it from VC++
When I import the .tlb file usign the #import VC++ generates a .tlh wrapper
file with 8-byte alignment
...
#pragma pack(push, 8)
...

When generating the type library with MIDL I've tryed to spec. the "/align
1" or "/pack 1" or "/Zp1", but the #import seems to ignore the type library
alignment setting and always use 8-byte alignment.

So, at the moment I modify the .tlh file to 1 byte alignment and include
this file instead of importing the type library.

Is it possible to specify the you want to use 1 byte allignment when
importing a type library??

Regards,

Morten S?rensen



Fri, 23 May 2003 03:00:00 GMT  
 #importing a typelibrary with non-8 byte alignment

There is no alignment property in the type library. In fact VB uses
a four byte alignment which is incompatible with the #import
pragma. Automation added structures but didn't say anything
anout alignment. If we consider the VB behavior as the standard,
4-byte alignment it is...

Shortly, don't rely on type libraries...

--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD

MVP VC FAQ: http://www.mvps.org/vcfaq
=====================================


Quote:
> Hi,

> I have a type library generated by Delphi with 1-byte alignment and I want
> to use it from VC++
> When I import the .tlb file usign the #import VC++ generates a .tlh
wrapper
> file with 8-byte alignment
> ...
> #pragma pack(push, 8)
> ...

> When generating the type library with MIDL I've tryed to spec. the "/align
> 1" or "/pack 1" or "/Zp1", but the #import seems to ignore the type
library
> alignment setting and always use 8-byte alignment.

> So, at the moment I modify the .tlh file to 1 byte alignment and include
> this file instead of importing the type library.

> Is it possible to specify the you want to use 1 byte allignment when
> importing a type library??

> Regards,

> Morten S?rensen



Fri, 23 May 2003 03:00:00 GMT  
 #importing a typelibrary with non-8 byte alignment


Quote:
> There is no alignment property in the type library.

What I was refering to was the packing level for structures controlled by
the #pragma pack directive, or the
/align, /pack, or /Zp options on the MIDL compiler.

Regards,

Morten S?rensen



Sat, 24 May 2003 03:00:00 GMT  
 #importing a typelibrary with non-8 byte alignment
That's exactly what I meant too. It is called byte alignment.

--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD

MVP VC FAQ: http://www.mvps.org/vcfaq
=====================================


Quote:



> > There is no alignment property in the type library.

> What I was refering to was the packing level for structures controlled by
> the #pragma pack directive, or the
> /align, /pack, or /Zp options on the MIDL compiler.

> Regards,

> Morten S?rensen



Sat, 24 May 2003 03:00:00 GMT  
 #importing a typelibrary with non-8 byte alignment
Try adding: inject_statement("#pragma pack(1)")

to your #import line, if you are absolutely certain you want this behavior.
This will inject right after the namespace declaration, which occurs later
than the injected header.

By not using a 'push' with the pack, the final pack/pop at the end of the
file should correctly restore the state to what it was before the .tlh file
was parsed.


Quote:
> Hi,

> Is it possible to specify the you want to use 1 byte allignment when
> importing a type library??

> Regards,

> Morten S?rensen



Sat, 24 May 2003 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. HP-UX C complier struct byte packing alignment question

2. Byte alignment on structs

3. Byte Alignment

4. Byte vs. Word Alignment - (nf)

5. Byte .vs. Word Alignment

6. What is byte-alignment?

7. Byte alignment

8. structure byte alignment

9. Byte ordering and alignment restrictions

10. Byte alignment on PA-RISC question

11. Byte Array alignment to long.

12. BYTE ALIGNMENT FOR HP-9000

 

 
Powered by phpBB® Forum Software