rlottie icon indicating copy to clipboard operation
rlottie copied to clipboard

Windows: wrong cast of functions returnedd by GetProcAddress

Open vtorri opened this issue 6 years ago • 11 comments

../src/vector/vimageloader.cpp:53:79: error: cast between incompatible function types from 'FARPROC' {aka 'long long int ()()'} to 'lottie_image_load_f' {aka 'unsigned char ()(const char, int*, int*, int*, int)'} [-Werror=cast-function-type]

Add WINAPI in front of the function, like that :

using lottie_image_load_f = unsigned char *(WINAPI *)(const char *filename, int *x, int *y, int *comp, int req_comp); using lottie_image_load_data_f = unsigned char *(WINAPI *)(const char *data, int len, int *x, int *y, int *comp, int req_comp); using lottie_image_free_f = void (WINAPI *)(unsigned char *);

vtorri avatar Jun 29 '19 13:06 vtorri

this could be a g++ 8.* compiler error, i'll try with a more recent one

vtorri avatar Jul 01 '19 07:07 vtorri

@vtorri , i just used reinterpret_cast. and tried with vs2019 , i don't get that error. you can test and let me know

smohantty avatar Jul 01 '19 07:07 smohantty

yes, i'll let you know with g++ 9.*

vtorri avatar Jul 01 '19 07:07 vtorri

@vtorri , I have pushed a patch for meson build with werror and warning_level as part of default_options . so you can configure your project according to your need. ex: meson -Dwerror=false -Dwarning_level=1 builddir

smohantty avatar Jul 01 '19 08:07 smohantty

what about this solution :

https://github.com/JBamro/Makruk-Stockfish/commit/2a6d2ee8a5461113391c7776f92b30cb09898649

?

it works for me

vtorri avatar Jul 01 '19 09:07 vtorri

Note that WINAPI should be used, imho, because it sets the calling convention to what FARPROC uses : __stdcall

vtorri avatar Jul 01 '19 09:07 vtorri

@vtorri , I see .. have not much idea about windows env .. if the code works for you in your env. Could you please raise a patch for the same.

smohantty avatar Jul 01 '19 09:07 smohantty

I will have a look.

hermet avatar Jul 05 '19 06:07 hermet

see : https://docs.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-getprocaddress for FARPROC : https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-callwindowproca

usally, WINAPI is the standard calling convention : __stdcall : https://docs.microsoft.com/en-us/windows/win32/winprog/windows-data-types

vtorri avatar Jul 05 '19 07:07 vtorri

@vtorri if you have vs2019, this patch might be useful for you.

commit bfda7feee5dffd298c2b756219586c6c429152f8 (HEAD -> master, origin/master, origin/HEAD) Author: Hermet Park [email protected] Date: Fri Jul 5 18:05:43 2019 +0900

vs2019: added the preset visual studio project.

This is a compilable vs project to generate library
for the fan of visual studio.

Still, there are a lot of compile warnings,
it works to generate working dll and lib.

hermet avatar Jul 05 '19 09:07 hermet

as i have said, it's a gcc >= 8.* bug

vtorri avatar Jul 07 '19 12:07 vtorri