smasherprog / screen_capture_lite

cross platform screen/window capturing library
MIT License
616 stars 156 forks source link

Use Screen_Capture in C# Code, Must Add _stdcall in Callback define #114

Closed flowerlove closed 2 years ago

flowerlove commented 2 years ago

My Test Project is .net framework 4.6.1, Win32, When i use C++ dll, exe will crash Crash Info : Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention.

So I download the code and build, change C/C++->Code Generation->Basic Runtime Checks to Default.But it not work, always crash but no crash info.

so I Check the extern code, i find this code should be:

typedef int(stdcall C_API_MonitorCallback)(Monitor buffer, int buffersize); typedef int(stdcall C_API_WindowCallback)(Window buffer, int buffersize); (as example)

then i rebuild dll, it work fine.

smasherprog commented 2 years ago

ill look into adding the calling convetion across the codebase. cdecl is the default normally so ill decorate everything with that. stdcall is not typically used. wont get to this until this weekened. Unless you want to do a PR with changes on the c# side and c code with the cdecl everywhere :)

smasherprog commented 2 years ago

Added cdcel as the calling convention to the dllimport. cdcel is the default calling convention for c/c++ net default import is stdcall so this should be fixed now. Give it a shot

smasherprog commented 2 years ago

Nice find!

smasherprog commented 2 years ago

going to close this. Let me know if this recurrs