If not difficult, explain the meaning of preprocessing:

#ifdef TRANS2QUIK_EXPORTS #define TRANS2QUIK_API __declspec (dllexport) #pragma message ("TRANS2QUIK_API defined as __declspec (dllexport)") #else #define TRANS2QUIK_API __declspec (dllimport) #endif 

full code

 #pragma once #define TRANS2QUIK_API __declspec (dllimport) extern "C" { typedef void (__stdcall *TRANS2QUIK_CONNECTION_STATUS_CALLBACK) (long nConnectionEvent, long nExtendedErrorCode, LPCSTR lpcstrInfoMessage); typedef void (__stdcall *TRANS2QUIK_TRANSACTION_REPLY_CALLBACK) (long nTransactionResult, long nTransactionExtendedErrorCode, long nTransactionReplyCode, DWORD dwTransId, double dOrderNum, LPCSTR lpcstrTransactionReplyMessage); #define TRANS2QUIK_SUCCESS 0 #define TRANS2QUIK_FAILED 1 #define TRANS2QUIK_QUIK_TERMINAL_NOT_FOUND 2 #define TRANS2QUIK_DLL_VERSION_NOT_SUPPORTED 3 #define TRANS2QUIK_ALREADY_CONNECTED_TO_QUIK 4 #define TRANS2QUIK_WRONG_SYNTAX 5 #define TRANS2QUIK_QUIK_NOT_CONNECTED 6 #define TRANS2QUIK_DLL_NOT_CONNECTED 7 #define TRANS2QUIK_QUIK_CONNECTED 8 #define TRANS2QUIK_QUIK_DISCONNECTED 9 #define TRANS2QUIK_DLL_CONNECTED 10 #define TRANS2QUIK_DLL_DISCONNECTED 11 #define TRANS2QUIK_MEMORY_ALLOCATION_ERROR 12 #define TRANS2QUIK_WRONG_CONNECTION_HANDLE 13 #define TRANS2QUIK_WRONG_INPUT_PARAMS 14 long TRANS2QUIK_API __stdcall TRANS2QUIK_SEND_SYNC_TRANSACTION (LPSTR lpstTransactionString, long* pnReplyCode, PDWORD pdwTransId, double* pdOrderNum, LPSTR lpstrResultMessage, DWORD dwResultMessageSize, long* pnExtendedErrorCode, LPSTR lpstErrorMessage, DWORD dwErrorMessageSize); long TRANS2QUIK_API __stdcall TRANS2QUIK_SEND_ASYNC_TRANSACTION (LPSTR lpstTransactionString, long* pnExtendedErrorCode, LPSTR lpstErrorMessage, DWORD dwErrorMessageSize); long TRANS2QUIK_API __stdcall TRANS2QUIK_CONNECT (LPSTR lpstConnectionParamsString, long* pnExtendedErrorCode, LPSTR lpstrErrorMessage, DWORD dwErrorMessageSize); long TRANS2QUIK_API __stdcall TRANS2QUIK_DISCONNECT (long* pnExtendedErrorCode, LPSTR lpstrErrorMessage, DWORD dwErrorMessageSize); long TRANS2QUIK_API __stdcall TRANS2QUIK_SET_CONNECTION_STATUS_CALLBACK (TRANS2QUIK_CONNECTION_STATUS_CALLBACK pfConnectionStatusCallback, long* pnExtendedErrorCode, LPSTR lpstrErrorMessage, DWORD dwErrorMessageSize); long TRANS2QUIK_API __stdcall TRANS2QUIK_SET_TRANSACTIONS_REPLY_CALLBACK (TRANS2QUIK_TRANSACTION_REPLY_CALLBACK pfTransactionReplyCallback, long* pnExtendedErrorCode, LPSTR lpstrErrorMessage, DWORD dwErrorMessageSize); long TRANS2QUIK_API __stdcall TRANS2QUIK_IS_QUIK_CONNECTED (long* pnExtendedErrorCode, LPSTR lpstrErrorMessage, DWORD dwErrorMessageSize); long TRANS2QUIK_API __stdcall TRANS2QUIK_IS_DLL_CONNECTED (long* pnExtendedErrorCode, LPSTR lpstrErrorMessage, DWORD dwErrorMessageSize); 
  • Kill though, I do not understand where the link with TRANS2QUIK.dll is going on? - rejie
  • in the properties of the project, not? or #pragma must be appropriate. - gecube
  • Here it is: #pragma comment(lib, "libname.lib") - gecube
  • And if in properties, where? (VS2010) - rejie

2 answers 2

It's simple.

TRANS2QUIK_API is a macro that is put into a function definition. And he speaks about the belonging of the function to a particular library. The macro TRANS2QUIK_EXPORTS is defined in the code of the library itself, and therefore the functions are exported, and in the program code the macro TRANS2QUIK_EXPORTS is not defined and, due to this, the functions are imported, i.e. called from an external DLL.

Additional Information:

  • And what is the meaning of this condition !? #ifdef TRANS2QUIK_EXPORTS - rejie 2:44 pm
  • I explained - use one hider for your programs and the library itself. TRANS2QUIK_EXPORTS defined only in the code of the library itself. - gecube
  • Good, but why you can’t just say: #define TRANS2QUIK_API __declspec (dllimport) - rejie
  • You can ... And who said that it is impossible? Just the developers of the header file took it from the library bundle and were not particularly bothered by writing any other versions of the file. - gecube pm
  • one
    > Just the developers of the header file took it from the library bundle and were not particularly bothered by writing any other versions of the file not quite. It would be more correct to say this: “just for the correct use of the same header both in the library and in its programs used” - hasalex

Kill though, I do not understand where the link with TRANS2QUIK.dll is going on?

or include the corresponding TRANS2QUIK.LIB in the project (add this file to the project). If you do not have this file, you can get it with the implib utility, for example, from the command line of the folder with the lib like this: implib.exe TRANS2QUIK.LIB TRANS2QUIK.DLL