Complete .h macro definition

Package ## points

  • __declspec(dllexport)

Show function export function * `extern" C "`

Function name and the export declaration is consistent, or the export function name does not work properly

Of course, the normal function name can also be achieved by defining `.def` file *` _stdcall`

32 can not use this statement

linux can not use this statement * WIN32 & _WINDOWS * WIN32 compiled using C + 32 * _WINDOWS compiler 64 using




# Ifdef _WINDOWS // 64-bit systems are no predefined WIN32 #ifdef __cplusplus # The DEFINE DLL_EXPORT_C_DECL extern "C " __declspec (dllexport) # the else # the DEFINE DLL_EXPORT_DECL __declspec (dllexport) #endif # the else # ifdef # __cplusplus the DEFINE DLL_EXPORT_C_DECL extern "C " # the else # the DEFINE DLL_EXPORT_DECL extern # endif # endif # ifdef # _WINDOWS the DEFINE WINAPI # __stdcall the DEFINE WIN32_LEAN_AND_MEAN // exclude from Windows header files rarely used information # the include "stddef.h " # the else # the DEFINE WINAPI # endif

 

 

x1
>
<
>>
<<
O

Code ##

 

test.h

  
#pragma once
# The DEFINE TEST_API extern "C " __declspec (dllexport) # the DEFINE WINAPI __stdcall // 32 bits can not be declared as __stdcall, otherwise the function name garbled # the DEFINE WIN32_LEAN_AND_MEAN // # exclude information from the rarely used Windows header file the include "stddef. H " // this class is derived from Test.dll CTest {public class: CTest ( void); // TODO: Add your approach here. };

 

test.cpp

#include "stdafx.h" # The include "Test.h " // callback type declaration typedef int (* WINAPI FrontConnected) (); // callback variable void * _connect; // set using the transfer function of the callback function pointer to the upper layer C + layer, and the assignment TEST_API to _connect void WINAPI SetConnect ( void * Conn) = {_connect Conn;} // + C layer is formed by an upper layer calls a callback function _connect TEST_API int WINAPI fnTest ( int a, int B) { IF (! _connect = NULL) { ((FrontConnected) _connect) ();} return a + B;} // this is the constructor for class exported. // class definition information, see Test.h CTest :: CTest () { return;}

Guess you like

Origin www.cnblogs.com/marklove/p/11081095.html