Import a function which returns a structure with X64
Posted: Thu Feb 26, 2026 1:41 pm
Hi,
I use a static lib compiled in VS2022.
There is a function inside which returns a structure. The return value is not really needed.
If I use X86 everything works fine. If I use X64, it results in a memory error and it looks like the parameters are 'shifted'.
In X64 VS uses a 'hidden' first parameter to return the pointer to the structure.
Ok, as workarround I can write a wrapper function, but than I always have to modify the original code of the library, when there is a new version available.
Is there any trick on the PB side to make this work?
C:
PJ_DEF(pj_str_t) pj_strerror(pj_status_t statcode, char *buf, pj_size_t bufsize);
PB:
ImportC #LibPJProjectFile
pj_strerror.i(statcode.pj_status_t, *buf, bufsize.pj_size_t)
EndImport
This results in X64 in a memory error writing to address 79, which is the bufsize - 1., so the 3rd parameter is used as 2nd parameter.
Any idea how this can be fixed with PB stuff?
I use a static lib compiled in VS2022.
There is a function inside which returns a structure. The return value is not really needed.
If I use X86 everything works fine. If I use X64, it results in a memory error and it looks like the parameters are 'shifted'.
In X64 VS uses a 'hidden' first parameter to return the pointer to the structure.
Ok, as workarround I can write a wrapper function, but than I always have to modify the original code of the library, when there is a new version available.
Is there any trick on the PB side to make this work?
C:
PJ_DEF(pj_str_t) pj_strerror(pj_status_t statcode, char *buf, pj_size_t bufsize);
PB:
ImportC #LibPJProjectFile
pj_strerror.i(statcode.pj_status_t, *buf, bufsize.pj_size_t)
EndImport
This results in X64 in a memory error writing to address 79, which is the bufsize - 1., so the 3rd parameter is used as 2nd parameter.
Any idea how this can be fixed with PB stuff?