mockcpp icon indicating copy to clipboard operation
mockcpp copied to clipboard

Compile error when using API Hook on Visual Studio 2019

Open sinojelly opened this issue 4 years ago • 2 comments

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 avatar Mar 25 '21 03:03 sinojelly

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 avatar Mar 26 '21 07:03 sinojelly

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); }

sinojelly avatar Jun 25 '21 15:06 sinojelly