PROCESSENTRY32W padding issue on 64bit lazarus for windows lazarus / 34-Windows ---------------------------------------------------------------------- marunguy · 2014-03-31 08:51 PROCESSENTRY32W padding in Jwawindows unit may wrong on 64bit lazarus for windows. lazarus 1.2.0 64bit version is used. * PROCESSENTRY32W size in VC2008. Quote- 32bit : 556 bytes - 64bit : 568 bytes * PROCESSENTRY32W size in lazarus (Jwawindows unit). Quote- 32bit : 556 bytes - 64bit : 560 bytes PPROCESSENTRY32W declaration is correct. * in vc2008 Code: [Select]typedef struct tagPROCESSENTRY32W {     DWORD   dwSize;     DWORD   cntUsage;     DWORD   th32ProcessID;          // this process     ULONG_PTR th32DefaultHeapID;     DWORD   th32ModuleID;           // associated exe     DWORD   cntThreads;     DWORD   th32ParentProcessID;    // this process's parent process     LONG    pcPriClassBase;         // Base priority of process's threads     DWORD   dwFlags;     WCHAR   szExeFile[MAX_PATH];    // Path } PROCESSENTRY32W; * in lazarus(C:\lazarus\fpc\2.6.2\source\packages\winunits- jedi\src\jwatlhelp32.pas) Code: [Select]type   PPROCESSENTRY32W = ^PROCESSENTRY32W;   {$EXTERNALSYM PPROCESSENTRY32W}   tagPROCESSENTRY32W = record     dwSize: DWORD;     cntUsage: DWORD;     th32ProcessID: DWORD;          // this process     th32DefaultHeapID: ULONG_PTR;     th32ModuleID:DWORD;            // associated exe     cntThreads: DWORD;     th32ParentProcessID: DWORD;    // this process's parent process     pcPriClassBase: LONG;          // Base priority of process's threads     dwFlags: DWORD;     szExeFile: array [0..MAX_PATH - 1] of WCHAR;   // Path   end; I test padding  - {$packrecords n}. {$packrecords n} works well.  Code: [Select].... {$packrecords 8} type   TESTRECORDW8 = record     dwSize: DWORD;     cntUsage: DWORD;     th32ProcessID: DWORD;          // this process     th32DefaultHeapID: ULONG_PTR;     th32ModuleID:DWORD;            // associated exe     cntThreads: DWORD;     th32ParentProcessID: DWORD;    // this process's parent process     pcPriClassBase: LONG;          // Base priority of process's threads     dwFlags: DWORD;     szExeFile: array [0..MAX_PATH - 1] of WCHAR;   // Path   end; {$packrecords default} {$packrecords 4} type   TESTRECORDW4 = record     dwSize: DWORD;     cntUsage: DWORD;     th32ProcessID: DWORD;          // this process     th32DefaultHeapID: ULONG_PTR;     th32ModuleID:DWORD;            // associated exe     cntThreads: DWORD;     th32ParentProcessID: DWORD;    // this process's parent process     pcPriClassBase: LONG;          // Base priority of process's threads     dwFlags: DWORD;     szExeFile: array [0..MAX_PATH - 1] of WCHAR;   // Path   end; {$packrecords default} .... Self.LogMsg(Format('TESTRECORDW8=%d, TESTRECORDW4=%d', [SizeOf(TESTRECORDW8), SizeOf(TESTRECORDW4)]));QuoteTESTRECORDW8=568, TESTRECORDW4=560 {$packrecords 8} is found at C:\lazarus\fpc\2.6.2\source\packages\winunits- jedi\src\jwatlhelp32.pas. But it don't works properly. Code: [Select]{$IFNDEF JWA_OMIT_SECTIONS} {$I jediapilib.inc} // switch back to default (natural alignment), bug 16361 {$ifdef FPC} {$ifdef cpu64}{$packrecords 8} {$endif} {$endif} interface uses   JwaWinType; {$ENDIF JWA_OMIT_SECTIONS} The padding of all record types in jwawindows unit may be wrong. Is 64bit support  not concrete as 32bit? ---------------------------------------------------------------------- marcov · 2014-03-31 16:11 Basically the "jedi" headers are third party(*), and were mostly 32-bit originally, though they haven't been synced since 2009-10 I think We had similar problems in our own headers (anything without jwa), but thanks to some persistent bug submitters-with-patches those have been mostly ironed out. One is currently working on the activex side of things. Probably syncing, and reporting a bug (preferably with short and to the point patch) if you notice something is the best way of tackling this. I'll put the syncing bit on my agenda. (*)http://sourceforge.net/projects/jedi-apilib/ ---------------------------------------------------------------------- marunguy · 2014-04-01 04:20 Thank for your answer!! This bug seems to be fixed already. http://sourceforge.net/p/jedi-apilib/code/1106/ Quote# upgraded JWAPI to XE2 (Win64 should also work) I want test latest jwawindows. But, I am beginner for lazarus and fpc. I don't know how to build fpc with latest jwawindows. How can I build fpc with latest jwawindows? ---------------------------------------------------------------------- marcov · 2014-04-02 08:56 Quote from: marunguy on April 01, 2014, 06:20:41 amHow can I build fpc with latest jwawindows? 1. Find the directory where FPC is installed (c:\fpc\2.6.4 or somewhere in the lazarus dir if your FPC came with Lazarus). 2. backup and erase  the units/i386-win32/winunits-jedi unit. 3. Put you own jedi sources in the compiler's searchpath somewhere ---------------------------------------------------------------------- marunguy · 2014-04-02 10:45 I cannot compile latest jwawindows unit. http://sourceforge.net/p/jedi-apilib/code/HEAD/tree/jwapi/trunk/ I fixed several compiler error related include path. But, I cannot fix below error as I am beginner for FPC. Code: [Select]D:\work\jwap_snap\jedi-apilib-code-1115-jwapi- trunk\Win32API\JwaWinNT.pas(7775,44) Error: Illegal expressionCode: [Select]  RTL_SRWLOCK_INIT : RTL_SRWLOCK = (Ptr : 0); Code: [Select]D:\work\jwap_snap\jedi-apilib-code-1115-jwapi- trunk\Win32API\JwaWinNT.pas(7790,66) Error: Illegal expressionCode: [Select]  RTL_CONDITION_VARIABLE_INIT : RTL_CONDITION_VARIABLE = (Ptr : 0); Code: [Select]D:\work\jwap_snap\jedi-apilib-code-1115-jwapi- trunk\Win32API\JwaStrSafe.pas(262,27) Error: Procedure directive "VARARGS" has conflicts with other directivesCode: [Select]  function StringCchPrintfW(     {__out_bcount(cbDest)} pszDest : STRSAFE_LPWSTR;     {__in} cchDest : size_t;     {__in __format_string} pszFormat : STRSAFE_LPCWSTR     {...}     ) : HRESULT; stdcall; varargs; external; ---------------------------------------------------------------------- Cyrax · 2014-04-05 13:25 Quote from: marunguy on April 02, 2014, 12:45:29 pmI cannot compile latest jwawindows unit. http://sourceforge.net/p/jedi-apilib/code/HEAD/tree/jwapi/trunk/ I fixed several compiler error related include path. But, I cannot fix below error as I am beginner for FPC. Code: [Select]D:\work\jwap_snap\jedi-apilib-code-1115-jwapi- trunk\Win32API\JwaWinNT.pas(7775,44) Error: Illegal expressionCode: [Select]  RTL_SRWLOCK_INIT : RTL_SRWLOCK = (Ptr : 0); Code: [Select]  RTL_SRWLOCK_INIT : RTL_SRWLOCK = (Ptr : NIL); Quote from: marunguy on April 02, 2014, 12:45:29 pmCode: [Select]D:\work\jwap_snap\jedi-apilib-code-1115-jwapi- trunk\Win32API\JwaWinNT.pas(7790,66) Error: Illegal expressionCode: [Select]  RTL_CONDITION_VARIABLE_INIT : RTL_CONDITION_VARIABLE = (Ptr : 0); Code: [Select]  RTL_CONDITION_VARIABLE_INIT : RTL_CONDITION_VARIABLE = (Ptr : NIL); Quote from: marunguy on April 02, 2014, 12:45:29 pmCode: [Select]D:\work\jwap_snap\jedi-apilib-code-1115-jwapi- trunk\Win32API\JwaStrSafe.pas(262,27) Error: Procedure directive "VARARGS" has conflicts with other directivesCode: [Select]  function StringCchPrintfW(     {__out_bcount(cbDest)} pszDest : STRSAFE_LPWSTR;     {__in} cchDest : size_t;     {__in __format_string} pszFormat : STRSAFE_LPCWSTR     {...}     ) : HRESULT; stdcall; varargs; external; Code: [Select]  function StringCchPrintfW(     {__out_bcount(cbDest)} pszDest : STRSAFE_LPWSTR;     {__in} cchDest : size_t;     {__in __format_string} pszFormat : STRSAFE_LPCWSTR     {...}     ) : HRESULT; cdecl; varargs; external; ---------------------------------------------------------------------- marunguy · 2014-04-08 10:46 Thanks for your answer. But I abort to compile jwawindows snapshot because of many other compiler error. This issue, I think, is due to compile option when builded jwawindow units. I cannot found compile option related padding or align in fpc sources. Below code works fine for me on 64bit lazarus/windows . Code: [Select].... {$ifdef WIN64} type   PROCESSENTRY32W_FIXPAD64 = record     dwSize: DWORD;     cntUsage: DWORD;     th32ProcessID: DWORD;          // this process     th32DefaultHeapID: ULONG_PTR;     th32ModuleID:DWORD;            // associated exe     cntThreads: DWORD;     th32ParentProcessID: DWORD;    // this process's parent process     pcPriClassBase: LONG;          // Base priority of process's threads     dwFlags: DWORD;     szExeFile: array [0..MAX_PATH - 1] of WCHAR;   // Path   end; {$endif} var   snapshot_hdl: HANDLE; .... {$ifdef WIN32}   proc_entry: Jwawindows.PROCESSENTRY32W; {$else}   proc_entry: PROCESSENTRY32W_FIXPAD64; {$endif} ....     proc_entry.dwSize := SizeOf(proc_entry);   {$ifdef WIN32}     if not Jwawindows.Process32FirstW(snapshot_hdl, proc_entry) then   {$else}     if not Jwawindows.Process32FirstW(snapshot_hdl, Jwawindows.PPROCESSENTRY32W(@proc_entry)^ ) then   {$endif}     begin       Self.LogMsg(Format('fail to Process32FirstW, LE=%d', [Windows.GetLastError()]));       exit;     end; .... ---------------------------------------------------------------------- marunguy · 2014-04-09 09:02 I did more analyze jwawindows source. "align" compiler directive is used for padding in jwawindows instead of "packrecords". * jwawindows.pas in fpc 2.6.2 source folder. Code: [Select]{$IFNDEF COMPILER6_UP}   {$ifndef FPC}     type PCardinal = ^Cardinal;   {$ELSE}     {$ALIGN 4}  // this line actived.   {$ENDIF} {$ELSE} {$ALIGN 4} {$ENDIF} * jwawindows.pas in latest jedi snapshot. Code: [Select]{$IFNDEF COMPILER6_UP}   {$ifndef FPC}     type PCardinal = ^Cardinal;   {$ELSE}     {$ALIGN 8}  // this line actived.   {$ENDIF} {$ELSE} {$ALIGN 8} {$ENDIF} "align" compiler directive is incorrect in fpc 2.6.2. Always all reccords in fpc2.6.2 is 4byte aligned on both win32 and win64. Above code for fpc 2.6.2, I think, become below code. * jwawindows.pas in fpc 2.6.2 source folder. Code: [Select]{$IFNDEF COMPILER6_UP}   {$ifndef FPC}     type PCardinal = ^Cardinal;   {$ELSE}     {$ifdef cpu32}  // or win32       {$ALIGN 4}    // 32bit     {$else}       {$ALIGN 8}    // 64bit     {$endif}   {$ENDIF} {$ELSE} {$ALIGN 4} {$ENDIF} I try to test above code. 1. backup and remove C:\lazarus\fpc\2.6.2\units\x86_64-win64\winunits- jedi 2. add C:\lazarus\fpc\2.6.2\source\packages\winunits-jedi\src\ to compiler's searchpath (project->Projcets Options->Paths->Other unit files) 3. rebuild. (Run->Clean up Build Files) Below error occurred. Quote..\..\fpc\2.6.2\source\packages\fcl- extra\src\win\ServiceManager.pas(21,31) Fatal: Can't find unit JwaWinNT used by ServiceManager fpc packages,I think, seems to be rebuilded. How can I test change code? ---------------------------------------------------------------------- marunguy · 2014-04-15 04:18 Additional work did in codetyphon because it is easy to rebuild fpc. Additional work is seen in below link. http://pilotlogic.com/sitejoom/index.php/forums/ms-windows- development/2851-processentry32w-padding-issue-on-64bit-lazarus- fo#5399