Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Translation Error #20

Open
laoqiuqiu opened this issue Jan 9, 2023 · 3 comments
Open

Translation Error #20

laoqiuqiu opened this issue Jan 9, 2023 · 3 comments

Comments

@laoqiuqiu
Copy link

laoqiuqiu commented Jan 9, 2023

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
Copy link
Contributor

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
Copy link
Author

#define BUTTONS_OKA (LPSTR)1    // Ok

Parsed

BUTTONS_OKA = (LPSTR)1;

ought to be

BUTTONS_OKA = LPSTR(1);

@alexeydott
Copy link
Contributor

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).

alexeydott pushed a commit to alexeydott/Chet that referenced this issue Jan 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants