sinojelly / mockcpp

Two C/C++ testing tools, mockcpp and testngpp.
Apache License 2.0
66 stars 39 forks source link

Compile error when using API Hook on Visual Studio 2019 #20

Open sinojelly opened 3 years ago

sinojelly commented 3 years ago

The error information is:

mockcpp/ApiHookGenerator.h(52,34): error C2039:  'freeApiHook': is not a member of 'mockcpp::ApiHookFunctor<F,10>'

I think this issue may be related to the code below in https://github.com/sinojelly/mockcpp/blob/master/include/mockcpp/ApiHookFunctor.h

#if _MSC_VER >= 1920    // VS 2019 
#define MOCKCPP_API_HOOK_FUNCTOR_DEF(n) \
__MOCKCPP_API_HOOK_FUNCTOR_DEF(n, __stdcall)
#else
#define MOCKCPP_API_HOOK_FUNCTOR_DEF(n) \
__MOCKCPP_API_HOOK_FUNCTOR_DEF(n, ); \
__MOCKCPP_API_HOOK_FUNCTOR_DEF(n, __stdcall) 
#endif

Maybe some template features changed in Visual Studio 2019, so the code above must be modified to compile pass. I just have modified it to pass the compilation, but not test using API hook tests (they crashed now, see https://github.com/sinojelly/mockcpp/issues/18 ).

sinojelly commented 3 years ago

If compiled with cmake flag "-A Win32", then report this compile error. If compiled X64 version, compile success, but run crash, see https://github.com/sinojelly/mockcpp/issues/18

sinojelly commented 3 years ago

X64 version, 如果注释掉 TESTCPP_SET_RESOURCE_CHECK_POINT(); 相关代码,则VS2019 TestMockObject2.h 中的用例都可以通过。 void setUp() { checkpoint = TESTCPP_SET_RESOURCE_CHECK_POINT(); }

 void tearDown()

{ TESTCPP_VERIFY_RESOURCE_CHECK_POINT(checkpoint); }