neslib / Chet

C Header Translator for Delphi
BSD 2-Clause "Simplified" License
204 stars 43 forks source link

Translation Error #20

Open laoqiuqiu opened 1 year ago

laoqiuqiu commented 1 year ago

Parsed error

// Callbacks should be prepared to treat NULL strings as empty strings.
typedef int (CALLBACK *PFNCHECKINPUTA)(HWND hWnd,LPARAM lParamCheckInput,LPCSTR lpszOrigString,LPCSTR lpszString,LPSTR pszErrorBuf,int cchErrorMax);
typedef int (CALLBACK *PFNCHECKINPUTW)(HWND hWnd,LPARAM lParamCheckInput,LPCWSTR lpszOrigString,LPCWSTR lpszString,LPWSTR pszErrorBuf,int cchErrorMax);
typedef BOOL (CALLBACK *PFNOKINPUTA)(HWND hWnd,LPARAM lParamCheckInput,LPCSTR lpszOrigString,LPCSTR lpszString);
typedef BOOL (CALLBACK *PFNOKINPUTW)(HWND hWnd,LPARAM lParamCheckInput,LPCWSTR lpszOrigString,LPCWSTR lpszString);

Change to

typedef int (__stdcall *PFNCHECKINPUTA)(HWND hWnd,LPARAM lParamCheckInput,LPCSTR lpszOrigString,LPCSTR lpszString,LPSTR pszErrorBuf,int cchErrorMax);
typedef int (__stdcall *PFNCHECKINPUTW)(HWND hWnd,LPARAM lParamCheckInput,LPCWSTR lpszOrigString,LPCWSTR lpszString,LPWSTR pszErrorBuf,int cchErrorMax);
typedef BOOL (__stdcall *PFNOKINPUTA)(HWND hWnd,LPARAM lParamCheckInput,LPCSTR lpszOrigString,LPCSTR lpszString);
typedef BOOL (__stdcall *PFNOKINPUTW)(HWND hWnd,LPARAM lParamCheckInput,LPCWSTR lpszOrigString,LPCWSTR lpszString);

Parsed

  PFNCHECKINPUTA = function(hWnd: HWND; lParamCheckInput: LPARAM; lpszOrigString: LPCSTR; lpszString: LPCSTR; pszErrorBuf: LPSTR; cchErrorMax: Integer): Integer; cdecl;
  PFNCHECKINPUTW = function(hWnd: HWND; lParamCheckInput: LPARAM; lpszOrigString: LPCWSTR; lpszString: LPCWSTR; pszErrorBuf: LPWSTR; cchErrorMax: Integer): Integer; cdecl;
  PFNOKINPUTA = function(hWnd: HWND; lParamCheckInput: LPARAM; lpszOrigString: LPCSTR; lpszString: LPCSTR): LongBool; cdecl;
  PFNOKINPUTW = function(hWnd: HWND; lParamCheckInput: LPARAM; lpszOrigString: LPCWSTR; lpszString: LPCWSTR): LongBool; cdecl;

cdecl ought to be stdcall

alexeydott commented 1 year ago

This is currently controlled globally in the "Conversion Settings"> "Calling convention" settings. But experimental support for extended call conversion translation is available in my fork. see https://github.com/alexeydott/Chet/tree/master/Bin But remember, for conversion to work correctly, you need to specify directories with included files, as well as set command line parameters that define the target platform. For example, for windows it is --target=i686-pc-win32 --target=i686-pc-windows-msvc.

laoqiuqiu commented 1 year ago
#define BUTTONS_OKA (LPSTR)1    // Ok

Parsed

BUTTONS_OKA = (LPSTR)1;

ought to be

BUTTONS_OKA = LPSTR(1);
alexeydott commented 1 year ago

Regarding call conversion - are your examples handled correctly? If yes - I will create a pullrequest to synchronize my code with the main branch and close this issue.

As for handling #define BUTTONS_OKA (LPSTR)1 -. This is a different issue that needs to be separated from this issue. It is about how the THeaderTranslator.WriteConstantsRhs method works. At the moment I don't see how to fix this without disturbing other macros (e.g. #define COMPLEX_CONSTANT ((((INT_CONSTANT<<2)+INT_CONSTANT) | 0xFE) & 255)).

PS There is a workaround - use the postprocessing script. For your case it would look like this ReplaceLine(1, "BUTTONS_OKA = (LPSTR)1;", " BUTTONS_OKA = LPSTR(1);", 0).