2 john jian John_jian 于 2017.08.31 10:35 提问

__declspec(dllexport)

问题和代码如下(问题在代码中有标注)
#ifndef rcs_id_api_h
#define rcs_id_api_h
#if !defined(lint)
static char* doors_ers_rcs_id_api_h = (char*)"@(#)DOORS %full_filespec: api.h~8.1.4:incl:ERS#1 % %date_created: Tue Jul 16 15:41:59 2013 %";
#endif
#endif
/**********************************************************************
** api.h
*/

/*
Licensed Materials - Property of IBM - some unique copyrights (i.e., the ability to copy, modify, distribute) may be licensed in certain circumstances (e.g., sample/template code intended to be used by customers to build upon and distribute as their own products).

DOORS - %full_filespec: api.h~8.1.4:incl:ERS#1 % %date_created: Tue Jul 16 15:41:59 2013 %

(c) Copyright IBM Corporation 1993, 2008. All Rights Reserved.

U.S. Government Users Restricted Rights: Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
*/

#ifndef DOORS_API_H
#define DOORS_API_H

/* Required to build Serena Version Manager */
#ifndef NLS_
#define NLS_(a)a
#endif

/* Type seperation for 64 vs 32 bit variant */

#if defined (_WIN64)

if defined (datum)

undef datum

endif

define datum long long

#else

if defined (datum)

undef datum

endif

define datum long

#endif

/* Categorize the type of C/C++ we are using */

#if defined(__cplusplus) || defined(c_plusplus)
#define API_CPLUSPLUS 1
#else
#define API_CPLUSPLUS 0
#endif

#if defined(__STDC__) || API_CPLUSPLUS || defined(_WIN32)
#define API_ARGS(args) args
#else
#define API_ARGS(args) ()
#endif

/**********************************************************************
** Some typical CPP definitions
*/

#ifndef TRUE
#define TRUE 1
#define FALSE 0
#endif

#ifndef global
#define global /* global entry point (extern in .h file) /
#define local static /
local entry point /
#define globalvar /
global variable (externvar .in .h file) /
#define externvar extern /
global variable .h file entry */
#endif

#if defined(_WIN32)
#define API_WIN32
#ifndef API_DLL
#define API_DLL _declspec(dllexport) 编译的时候总在提示在(dllexport)前面那个括号出少了构造函数和析构函数,求大神指教
#define API_CALL _stdcall
#endif
#define API_EXTERN(type) API_DLL type API_CALL
#define API_EXTERNVAR API_DLL
#else
#define API_EXTERN(type) extern type
#define API_EXTERNVAR externvar
#endif

#ifndef NULL
#define NULL 0
#endif

#ifndef NUL
#define NUL '\0'
#endif

/* heap things */

#ifndef mnew
#define mnew(Type) (Type*)malloc(sizeof(Type))
#define msave(Str) strcpy((char )malloc(qss_strlen(Str)+1), (Str))
#define mnew_array(Type, Num) (Type
)malloc(sizeof(Type)*(Num))
#endif

/* miscellaneous */

#ifndef M_Min
#define M_Min(a, b) ((a) < (b) ? (a) : (b))
#define M_Max(a, b) ((a) > (b) ? (a) : (b))

#define M_Abs(a) ((a) < 0 ? -(a) : (a))

#define M_Xor(a, b) (((a) || (b)) && ( ! ((a) && (b))))
#endif

/* Macro token concatenation */

#ifndef CAT_
#define ID_(x) x

#ifdef STDC
#define CAT_(x,y) x ## y
#else
#define CAT_(x,y) ID_(x)y
#endif
#endif

#ifndef StrMP_
#if defined (__STDC__) || defined(API_WIN32)
#define StrMP_(x) (char *)#x
#else
#define StrMP_(x) (char *)NLS_("x")
#endif
#endif

/* API Stuff */

/* Error States
*/

/*

  • CL58 - had to reintroduce apiErrorStates typedef,
  • because api.h is included by C (not C++) code which
  • uses apiErrorStates as a type name. */ enum apiErrorStates_ { DOORS_API_OK, DOORS_API_PARSE_BAD_DXL, DOORS_API_SEND_BAD_DXL, DOORS_API_CONNECT_FAILED, DOORS_API_ERROR };

typedef enum apiErrorStates_ apiErrorStates;

#define apiInstall(proto,fn) apiInstallN(proto,StrMP_(fn),fn)

#define BEGIN_FN(name,ins,outs) \
local int name API_ARGS((void)) { \
char* name__ = StrMP_(name); \
int inp_i_ = ins; \
int outp_i_ = ins; \
int inn_i_ = ins; \
int outn_i_ = outs;

#define END_DECLS \
if (apiParCheck(name__,inn_i_,outn_i_,inp_i_)) ; else goto err_exit__

#define END_FN \
err_exit__: \
apiResCheck(name__,inp_i_,inn_i_,outp_i_,outn_i_); \
return (outn_i_ - inn_i_); }

#define P_(t,x) \
t x = (t)apiPar(inp_i_--)

#define RETURN_(x) \
apiReturn((datum)x,outp_i_--);

/* for loop perm macros */

#define BEGIN_FOR_DO(name,ft,f,st,scan) \
local int name (char pc) \
{ \
char
loop; \
int irv = 0; \
st* scanp__; \
ft f; \
st scan; \
scanp__ = (st*)apiLoop(pc,&loop,(void **)&f,&irv); \
if (scanp__ == NULL) return irv; \
{

#define PROCESS_DO(scan) \
{*scanp__ = scan;\
if (apiLoopBody(loop,&irv)) break;}

#define END_FOR_DO \
} \
return apiLoopDone(loop,irv,pc); \
}

/* Definitions */

#if API_CPLUSPLUS
extern NLS_("C") {
#endif

API_EXTERN(void) apiError API_ARGS((char *format, ...));

API_EXTERN(void) apiWarn API_ARGS((char *format, ...));

API_EXTERN(int) apiParCheck API_ARGS((char *n, int ins, int outs, int ip));

API_EXTERN(void) apiResCheck API_ARGS((char *n, int ip, int in, int op,
int on));

API_EXTERN(datum) apiPar API_ARGS((int ip));

API_EXTERN(void) apiReturn API_ARGS((long r, int op));

API_EXTERN(char*) apiLoop API_ARGS((char* pc, char** loop,
void** fp, int* ret));

API_EXTERN(int) apiLoopBody API_ARGS((char* loop, int* irvp));

API_EXTERN(int) apiLoopDone API_ARGS((char* loop, int irv, char* pp));

API_EXTERN(void) apiMainProg API_ARGS((int argc,
char* argv[],
char* n,
char* ext,
char* include,
void (*init)(void),
void (*done)(void)));

API_EXTERN(void) apiInitLibrary API_ARGS((char* n, char* ext, char* include));

API_EXTERN(void) apiFinishLibrary API_ARGS((void));

API_EXTERN(void) apiInstallN API_ARGS((char* proto, char* name,
int (*)()));

API_EXTERN(void) apiParse API_ARGS((char *format, ...));

API_EXTERN(void) apiConnect API_ARGS((char *s));

API_EXTERN(void) apiConnectSock API_ARGS((unsigned short portno, char* host));

API_EXTERN(void) apiConnectSockV2 API_ARGS((unsigned short portno, char* host));

API_EXTERN(void) apiSend API_ARGS((char *format, ...));

API_EXTERN(void) apiAuthenticatedSend API_ARGS((char *response, char *format, ...));

API_EXTERN(void) apiSendTimesout API_ARGS((int tmt, char *format, ...));

API_EXTERN(void) apiSendFile API_ARGS((char* f));

API_EXTERN(void) apiExitOnError API_ARGS((int onoff));

API_EXTERN(void) apiQuietError API_ARGS((int onoff));

API_EXTERN(int) apiGetErrorState API_ARGS((void));

API_EXTERN(void*) apiGetIPC API_ARGS((void));

API_EXTERN(int) apiSetIPC API_ARGS((void* newIPC));

API_EXTERN(void) apiDeleteIPC API_ARGS((void* newIPC));

API_EXTERN(void) apiFree API_ARGS((void*));

API_EXTERN(char*) apiAuthenticate API_ARGS((void));

#if API_CPLUSPLUS
}
#endif

#endif /* DOORS_API_H */


2个回答

justin_bkdrong
justin_bkdrong   2017.08.31 11:00

代码里面少了好多#,是否是转网页的时候漏了?
下面代码就OK了。

#ifndef rcs_id_api_h
#define rcs_id_api_h
#if !defined(lint)
static char* doors_ers_rcs_id_api_h = (char*)"@(#)DOORS %full_filespec: api.h~8.1.4:incl:ERS#1 % %date_created: Tue Jul 16 15:41:59 2013 %";
#endif
#endif
/**********************************************************************
** api.h
*/
/*
Licensed Materials - Property of IBM - some unique copyrights (i.e., the ability to copy, modify, distribute) may be licensed in certain circumstances (e.g., sample/template code intended to be used by customers to build upon and distribute as their own products).
DOORS - %full_filespec: api.h~8.1.4:incl:ERS#1 % %date_created: Tue Jul 16 15:41:59 2013 %
(c) Copyright IBM Corporation 1993, 2008. All Rights Reserved.
U.S. Government Users Restricted Rights: Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
*/
#ifndef DOORS_API_H
#define DOORS_API_H
/* Required to build Serena Version Manager */
#ifndef NLS_
#define NLS_(a) a
#endif
/* Type seperation for 64 vs 32 bit variant */
#if defined (_WIN64)
#if defined(datum)
#undef datum
#endif
#define datum long long
#else
#if defined(datum)
#undef datum
#endif
#define datum long
#endif
/* Categorize the type of C/C++ we are using */
#if defined(__cplusplus) || defined(c_plusplus)
#define API_CPLUSPLUS 1
#else
#define API_CPLUSPLUS 0
#endif
#if defined(__STDC__) || API_CPLUSPLUS || defined(_WIN32)
#define API_ARGS(args) args
#else
#define API_ARGS(args) ()
#endif
/**********************************************************************
** Some typical CPP definitions
*/
#ifndef TRUE
#define TRUE 1
#define FALSE 0
#endif
#ifndef global
#define global /* global entry point (extern in .h file) /
#define local static / local entry point /
#define globalvar / global variable (externvar .in .h file) /
#define externvar extern / global variable .h file entry */
#endif
#if defined(_WIN32)
#define API_WIN32
#ifndef API_DLL
#define API_DLL _declspec(dllexport) //编译的时候总在提示在(dllexport)前面那个括号出少了构造函数和析构函数,求大神指教
#define API_CALL _stdcall
#endif
#define API_EXTERN(type) API_DLL type API_CALL
#define API_EXTERNVAR API_DLL
#else
#define API_EXTERN(type) extern type
#define API_EXTERNVAR externvar
#endif
#ifndef NULL
#define NULL 0
#endif
#ifndef NUL
#define NUL '\0'
#endif
/* heap things */
#ifndef mnew
#define mnew(Type) (Type*)malloc(sizeof(Type))
#define msave(Str) strcpy((char )malloc(qss_strlen(Str)+1), (Str))
#define mnew_array(Type, Num) (Type)malloc(sizeof(Type)*(Num))
#endif
/* miscellaneous */
#ifndef M_Min
#define M_Min(a, b) ((a) < (b) ? (a) : (b))
#define M_Max(a, b) ((a) > (b) ? (a) : (b))
#define M_Abs(a) ((a) < 0 ? -(a) : (a))
#define M_Xor(a, b) (((a) || (b)) && ( ! ((a) && (b))))
#endif
/* Macro token concatenation */
#ifndef CAT_
#define ID_(x) x
#ifdef STDC
#define CAT_(x,y) x ## y
#else
#define CAT_(x,y) ID_(x)y
#endif
#endif
#ifndef StrMP_
#if defined (__STDC__) || defined(API_WIN32)
#define StrMP_(x) (char *)#x
#else
#define StrMP_(x) (char *)NLS_("x")
#endif
#endif
/* API Stuff */
/* Error States
*/
/*
CL58 - had to reintroduce apiErrorStates typedef,
because api.h is included by C (not C++) code which
uses apiErrorStates as a type name. */ enum apiErrorStates_ { DOORS_API_OK, DOORS_API_PARSE_BAD_DXL, DOORS_API_SEND_BAD_DXL, DOORS_API_CONNECT_FAILED, DOORS_API_ERROR };
typedef enum apiErrorStates_ apiErrorStates;
#define apiInstall(proto,fn) apiInstallN(proto,StrMP_(fn),fn)
#define BEGIN_FN(name,ins,outs) \
local int name API_ARGS((void)) { \
char* name__ = StrMP_(name); \
int inp_i_ = ins; \
int outp_i_ = ins; \
int inn_i_ = ins; \
int outn_i_ = outs;
#define END_DECLS \
if (apiParCheck(name__,inn_i_,outn_i_,inp_i_)) ; else goto err_exit__
#define END_FN \
err_exit__: \
apiResCheck(name__,inp_i_,inn_i_,outp_i_,outn_i_); \
return (outn_i_ - inn_i_); }
#define P_(t,x) \
t x = (t)apiPar(inp_i_--)
#define RETURN_(x) \
apiReturn((datum)x,outp_i_--);
/* for loop perm macros */
#define BEGIN_FOR_DO(name,ft,f,st,scan) \
local int name (char pc) \
{ \
char loop; \
int irv = 0; \
st* scanp__; \
ft f; \
st scan; \
scanp__ = (st*)apiLoop(pc,&loop,(void **)&f,&irv); \
if (scanp__ == NULL) return irv; \
{
#define PROCESS_DO(scan) \
{*scanp__ = scan;\
if (apiLoopBody(loop,&irv)) break;}
#define END_FOR_DO \
} \
return apiLoopDone(loop,irv,pc); \
}
/* Definitions */
#if API_CPLUSPLUS
extern NLS_("C") {
#endif
    API_EXTERN(void) apiError API_ARGS((char *format, ...));
    API_EXTERN(void) apiWarn API_ARGS((char *format, ...));
    API_EXTERN(int) apiParCheck API_ARGS((char *n, int ins, int outs, int ip));
    API_EXTERN(void) apiResCheck API_ARGS((char *n, int ip, int in, int op,
        int on));
    API_EXTERN(datum) apiPar API_ARGS((int ip));
    API_EXTERN(void) apiReturn API_ARGS((long r, int op));
    API_EXTERN(char*) apiLoop API_ARGS((char* pc, char** loop,
        void** fp, int* ret));
    API_EXTERN(int) apiLoopBody API_ARGS((char* loop, int* irvp));
    API_EXTERN(int) apiLoopDone API_ARGS((char* loop, int irv, char* pp));
    API_EXTERN(void) apiMainProg API_ARGS((int argc,
        char* argv[],
        char* n,
        char* ext,
        char* include,
        void(*init)(void),
        void(*done)(void)));
    API_EXTERN(void) apiInitLibrary API_ARGS((char* n, char* ext, char* include));
    API_EXTERN(void) apiFinishLibrary API_ARGS((void));
    API_EXTERN(void) apiInstallN API_ARGS((char* proto, char* name,
        int(*)()));
    API_EXTERN(void) apiParse API_ARGS((char *format, ...));
    API_EXTERN(void) apiConnect API_ARGS((char *s));
    API_EXTERN(void) apiConnectSock API_ARGS((unsigned short portno, char* host));
    API_EXTERN(void) apiConnectSockV2 API_ARGS((unsigned short portno, char* host));
    API_EXTERN(void) apiSend API_ARGS((char *format, ...));
    API_EXTERN(void) apiAuthenticatedSend API_ARGS((char *response, char *format, ...));
    API_EXTERN(void) apiSendTimesout API_ARGS((int tmt, char *format, ...));
    API_EXTERN(void) apiSendFile API_ARGS((char* f));
    API_EXTERN(void) apiExitOnError API_ARGS((int onoff));
    API_EXTERN(void) apiQuietError API_ARGS((int onoff));
    API_EXTERN(int) apiGetErrorState API_ARGS((void));
    API_EXTERN(void*) apiGetIPC API_ARGS((void));
    API_EXTERN(int) apiSetIPC API_ARGS((void* newIPC));
    API_EXTERN(void) apiDeleteIPC API_ARGS((void* newIPC));
    API_EXTERN(void) apiFree API_ARGS((void*));
    API_EXTERN(char*) apiAuthenticate API_ARGS((void));
#if API_CPLUSPLUS
}
#endif
#endif /* DOORS_API_H */

John_jian
John_jian 回复枫舞的季节: 在线等
3 个月之前 回复
justin_bkdrong
justin_bkdrong 回复John_jian: 我在vs2013中可以。dev我再试试
3 个月之前 回复
John_jian
John_jian 还是不行,我在dev中编译可以吗?
3 个月之前 回复
justin_bkdrong
justin_bkdrong   2017.08.31 13:52

你这个.h文件使用微软的语法格式,因此只能在微软的vs编译器中使用。
而dev c++ 是个IDE它集成了mingW 使用 gcc 来生成动态库。因此你必须用gcc 生成dll 的方式来组织代码.
dev设置编译的界面如下:
图片说明

你要么自己修改这个头文件,让它在gcc 下能编译过。要么使用vs来进行编译.

justin_bkdrong
justin_bkdrong 回复John_jian: 不客气
3 个月之前 回复
John_jian
John_jian 谢谢了
3 个月之前 回复
Csdn user default icon
上传中...
上传图片
插入图片