Closed
Description
Amazingly, it turns out that some Win32 structs are packed. (In my case, OPENFILENAMEW
). I don't know how many Win32 structs are packed, but the lack of struct packing makes it difficult to interface with Win32.
Example:
class OpenFileNameW extends Struct<OpenFileNameW> {
@Int32()
int lStructSize; // DWORD lStructSize;
@IntPtr()
int hwndOwner; // HWND hwndOwner;
@IntPtr()
int hInstance; // HINSTANCE hInstance;
Pointer<Uint16 /* CWSTR */ > lpstrFilter; // LPCWSTR lpstrFilter;
Pointer<Uint16 /* WSTR */ > lpstrCustomFilter; // LPWSTR lpstrCustomFilter;
@Int32()
int nMaxCustFilter; // DWORD nMaxCustFilter;
@Int32()
int nFilterIndex; // DWORD nFilterIndex;
Pointer<Uint16 /* WSTR */ > lpstrFile; // LPWSTR lpstrFile;
@Int32()
int nMaxFile; // DWORD nMaxFile;
Pointer<Uint16 /* WSTR */ > lpstrFileTitle; // LPWSTR lpstrFileTitle;
@Int32()
int nMaxFileTitle; // DWORD nMaxFileTitle;
Pointer<Uint16 /* CWSTR */ > lpstrInitialDir; // LPCWSTR lpstrInitialDir;
Pointer<Uint16 /* CWSTR */ > lpstrTitle; // LPCWSTR lpstrTitle;
@Int32()
int Flags; // DWORD Flags;
@Int16()
int nFileOffset; // WORD nFileOffset;
@Int16()
int nFileExtension; // WORD nFileExtension;
Pointer<Uint16 /* CWSTR */ > lpstrDefExt; // LPCWSTR lpstrDefExt;
@IntPtr()
int lCustData; // LPARAM lCustData;
Pointer<Void /* OFNHOOKPROC */ > lpfnHook; // LPOFNHOOKPROC lpfnHook;
Pointer<Uint16 /* CWSTR */ > lpTemplateName; // LPCWSTR lpTemplateName;
Pointer<Void /* EditMenu */ > lpEditInfo; // LPEDITMENU lpEditInfo;
Pointer<CString> lpstrPrompt; // LPCSTR lpstrPrompt;
Pointer<Void> pvReserved; // void *pvReserved;
@Int32()
int dwReserved; // DWORD dwReserved;
@Int32()
int FlagsEx; // DWORD FlagsEx;
}
sizeOf returns 168, but in Godbolt with the actual comdlg headers, the result is 152. https://godbolt.org/z/6Tyt3h