Re: How to create a Win32::API::Struct struct if the struct has union in it?
[email protected] ("$Bill Luebkert")
| Newsgroups | perl.libwin32 |
|---|---|
| Message-ID | <[email protected]> |
On 11/30/2011 14:52, Cosimo Streppone wrote: > On Sun, 27 Nov 2011 02:29:01 +0100, Burak Gürsoy <[email protected]> wrote: > >> I'm wondering about how to create a SYSTEM_INFO structure from Perl: >> >> http://msdn.microsoft.com/en-us/library/windows/desktop/ms724958(v=vs.85).aspx >> >> to pass this to GetNativeSystemInfo(). Win32::API::Struct->typedef() >> seems to support >> simple structs only. Is there a way to create such a nested struct? > > Sorry, no idea... Since there is no union logic in the module, the easiest thing to do is replace the union with whatever variant that allows you to access the data the way you want. It's hard enough to even figure out from M$ docs how to actually pack a structure (no clear 100% exact algorithm). Apparently it's a choice that can also be altered by compiler options. Personally, I'd have made structure packing a hard and fast algorithm to avoid some of these issues created by different CPU architectures, but then again - can all CPUs follow the algorithm you create ? EG: typedef Win32::API::Struct SYSTEM_INFO => qw( WORD wProcessorArchitecture; WORD wReserved; DWORD dwPageSize; LPVOID lpMinimumApplicationAddress; LPVOID lpMaximumApplicationAddress; DWORD dwActiveProcessorMask; DWORD dwNumberOfProcessors; DWORD dwProcessorType; DWORD dwAllocationGranularity; WORD wProcessorLevel; WORD wProcessorRevision; );