class __declspec(dllexport) CMarkup  
{
public:
// allow function args to accept string objects as constant string pointers
struct MCD_CSTR
{
MCD_CSTR() { pcsz=NULL; };
MCD_CSTR( MCD_PCSZ p ) { pcsz=p; };
MCD_CSTR( const MCD_STR& s ) { pcsz = MCD_2PCSZ(s); };
operator MCD_PCSZ() const { return pcsz; };
MCD_PCSZ pcsz;
};
....................................//表示还有很多 内容;
}
还有很多内联函数,在导出时都得 去掉内联。才不会说无法解析的外部符号,
但是这个函数 CMarkup::GetAttrib(MCD_CSTR szAttrib )还是 无法解析    //MCD_CSTR 是CMarkup中嵌套的类,难道这个我也要声明成__declspec(dllexport)疑问中.....

解决方案 »

  1.   

    当然了,不导出的话外面怎么识别MCD_CSTR
      

  2.   

    放到类外面,并加上导出申明
    struct __declspec(dllexport) MCD_CSTR
    {
    MCD_CSTR() { pcsz=NULL; };
    MCD_CSTR( MCD_PCSZ p ) { pcsz=p; };
    MCD_CSTR( const MCD_STR& s ) { pcsz = MCD_2PCSZ(s); };
    operator MCD_PCSZ() const { return pcsz; };
    MCD_PCSZ pcsz;
    };
      

  3.   

    八成是你使用的问题。导出的时候 加上 __declspec(dllexport)。
    但你在使用的时候得改为 __declspec(dllimport)内联函数什么的完全不用改。
      

  4.   

    我自己定义了一个头文件 内容如下
    #ifndef XMLEXPORTDLL_H
    #define XMLEXPORTDLL_H
    #if defined(XML_EXPORT_DLLS)
    #define XML_EXPORT_DLL __declspec(dllexport)
    #else
    #define XML_EXPORT_DLL __declspec(dllimport)
    #endif#endif //XMLEXPORTDLL_H
    然后用宏 XML_EXPORT_DLL 
    class ML_EXPORT_DLL CMarkup
    {}这样使用还有问题吗?
      

  5.   

    谁用过 CMarkUP,当作基础库进行导出的?而不是在每一份dll里面加一个Markup.cpp文件
      

  6.   

    下了一个CMarkup 没发现有 内嵌类
      

  7.   

    csdn的下载抽风了,不然我给你传一下我的工程。我下了代码就添加了
    #ifdef MARKUP_EXPORTS
    #define MARKUP_API __declspec(dllexport)
    #else
    #define MARKUP_API __declspec(dllimport)
    #endifclass CMarkup 改为 class MARKUP_API CMarkup
    编译成dll再用MarkupTest.h调用,一切正常。
      

  8.   


    我将头文件部分 贴出来你看看
    class CMarkup  
    {
    public:
    // allow function args to accept string objects as constant string pointers
    struct MCD_CSTR
    {
    MCD_CSTR() { pcsz=NULL; };
    MCD_CSTR( MCD_PCSZ p ) { pcsz=p; };
    MCD_CSTR( const MCD_STR& s ) { pcsz = MCD_2PCSZ(s); };
    operator MCD_PCSZ() const { return pcsz; };
    MCD_PCSZ pcsz;
    }; CMarkup() { SetDoc( NULL ); InitDocFlags(); };
    CMarkup( MCD_CSTR szDoc ) { SetDoc( szDoc ); InitDocFlags(); };
    CMarkup( int nFlags ) { SetDoc( NULL ); m_nFlags = nFlags; };
    CMarkup( const CMarkup& up ) { *this = up; };
    void operator=( const CMarkup& up );
    ~CMarkup() {}; // Navigate
    bool Load( MCD_CSTR szFileName );
    bool SetDoc( MCD_PCSZ szDoc );
    bool SetDoc( const MCD_STR& strDoc );
    bool IsWellFormed();
    bool FindElem( MCD_CSTR szName=NULL );
    bool FindChildElem( MCD_CSTR szName=NULL );
    bool IntoElem();
    bool OutOfElem();
    void ResetChildPos() { x_SetPos(m_iPosParent,m_iPos,0); };
    void ResetMainPos() { x_SetPos(m_iPosParent,0,0); };
    void ResetPos() { x_SetPos(0,0,0); };
    MCD_STR GetTagName() const;
    MCD_STR GetChildTagName() const { return x_GetTagName(m_iPosChild); };
    MCD_STR GetData() const { return x_GetData(m_iPos); };
    MCD_STR GetChildData() const { return x_GetData(m_iPosChild); };
    MCD_STR GetElemContent() const { return x_GetElemContent(m_iPos); };
    MCD_STR GetAttrib( MCD_CSTR szAttrib ) const { return x_GetAttrib(m_iPos,szAttrib); };
    MCD_STR GetChildAttrib( MCD_CSTR szAttrib ) const { return x_GetAttrib(m_iPosChild,szAttrib); };
    MCD_STR GetAttribName( int n ) const;
    int FindNode( int nType=0 );
    int GetNodeType() { return m_nNodeType; };
    bool SavePos( MCD_CSTR szPosName=_T("") );
    bool RestorePos( MCD_CSTR szPosName=_T("") );
    const MCD_STR& GetError() const { return m_strError; };
    int GetDocFlags() const { return m_nFlags; };
    void SetDocFlags( int nFlags ) { m_nFlags = nFlags; };
    ....
    struct ElemPos
    {
    ElemPos() {};
    ElemPos( const ElemPos& pos ) { *this = pos; };
    enum { EP_STBITS=22, EP_STMASK=0x2fffff, EP_LEVMASK=0xffff };
    int StartTagLen() const { return (nTagLengths & EP_STMASK); };
    void SetStartTagLen( int n ) { nTagLengths = (nTagLengths & ~EP_STMASK) + n; };
    void AdjustStartTagLen( int n ) { nTagLengths += n; };
    int EndTagLen() const { return (nTagLengths >> EP_STBITS); };
    void SetEndTagLen( int n ) { nTagLengths = (nTagLengths & EP_STMASK) + (n << EP_STBITS); };
    bool IsEmptyElement() { return (StartTagLen()==nLength)?true:false; };
    int StartContent() const { return nStart + StartTagLen(); };
    int ContentLen() const { return nLength - StartTagLen() - EndTagLen(); };
    int StartAfter() const { return nStart + nLength; };
    int Level() const { return nFlags & EP_LEVMASK; };
    void SetLevel( int nLev ) { nFlags = (nFlags & ~EP_LEVMASK) | nLev; };
    void ClearVirtualParent() { memset(this,0,sizeof(ElemPos)); }; // Memory size: 8 32-bit integers == 32 bytes
    int nStart;
    int nLength;
    int nTagLengths; // 22 bits 4MB limit for start tag, 10 bits 1K limit for end tag
    int nFlags; // 16 bits flags, 16 bits level 65536 depth limit
    int iElemParent;
    int iElemChild; // first child
    int iElemNext; // next sibling
    int iElemPrev; // if this is first, iElemPrev points to last
    };
    .............
    }
    里面有结构体(类)
      

  9.   

    // Allow function args to accept string objects as constant string pointers
    struct MCD_CSTR
    {
    MCD_CSTR() { pcsz=NULL; };
    MCD_CSTR( MCD_PCSZ p ) { pcsz=p; };
    MCD_CSTR( const MCD_STR& s ) { pcsz = MCD_2PCSZ(s); };
    operator MCD_PCSZ() const { return pcsz; };
    MCD_PCSZ pcsz;
    };// On Linux and OS X, filenames are not specified in wchar_t
    #if defined(MARKUP_WCHAR) && defined(__GNUC__)
    #undef MCD_FOPEN
    #define MCD_FOPEN(f,n,m) f=fopen(n,m)
    #define MCD_T_FILENAME(s) s
    #define MCD_PCSZ_FILENAME const char*
    struct MCD_CSTR_FILENAME
    {
    MCD_CSTR_FILENAME() { pcsz=NULL; };
    MCD_CSTR_FILENAME( MCD_PCSZ_FILENAME p ) { pcsz=p; };
    MCD_CSTR_FILENAME( const std::string& s ) { pcsz = s.c_str(); };
    operator MCD_PCSZ_FILENAME() const { return pcsz; };
    MCD_PCSZ_FILENAME pcsz;
    };
    #else // not WCHAR GNUC
    #define MCD_CSTR_FILENAME MCD_CSTR
    #define MCD_T_FILENAME MCD_T
    #define MCD_PCSZ_FILENAME MCD_PCSZ
    #endif // not WCHAR GNUC// File fseek, ftell and offset type
    #if defined(__GNUC__) && ! defined(MARKUP_WINDOWS) // non-Windows GNUC
    #define MCD_FSEEK fseeko
    #define MCD_FTELL ftello
    #define MCD_INTFILEOFFSET off_t
    #elif _MSC_VER >= 1000 && defined(MARKUP_HUGEFILE) // VC++ HUGEFILE
    #if _MSC_VER < 1400 // before VC++ 2005
    extern "C" int __cdecl _fseeki64(FILE *, __int64, int);
    extern "C" __int64 __cdecl _ftelli64(FILE *);
    #endif // before VC++ 2005
    #define MCD_FSEEK _fseeki64
    #define MCD_FTELL _ftelli64
    #define MCD_INTFILEOFFSET __int64
    #else // not non-Windows GNUC or VC++ HUGEFILE
    #define MCD_FSEEK fseek
    #define MCD_FTELL ftell
    #define MCD_INTFILEOFFSET long
    #endif // not non-Windows GNUC or VC++ HUGEFILE// End of line choices: none, return, newline, or CRLF
    #if defined(MARKUP_EOL_NONE)
    #define MCD_EOL MCD_T("")
    #elif defined(MARKUP_EOL_RETURN) // rare; only used on some old operating systems
    #define MCD_EOL MCD_T("\r")
    #elif defined(MARKUP_EOL_NEWLINE) // Unix standard
    #define MCD_EOL MCD_T("\n")
    #elif defined(MARKUP_EOL_CRLF) || defined(MARKUP_WINDOWS) // Windows standard
    #define MCD_EOL MCD_T("\r\n")
    #else // not Windows and not otherwise specified
    #define MCD_EOL MCD_T("\n")
    #endif // not Windows and not otherwise specified
    #define MCD_EOLLEN (sizeof(MCD_EOL)/sizeof(MCD_CHAR)-1) // string length of MCD_EOLstruct FilePos;
    struct TokenPos;
    struct NodePos;
    struct PathPos;
    struct SavedPosMapArray;
    struct ElemPosTree;class MARKUP_API CMarkup
    {
    public:
    CMarkup() { x_InitMarkup(); SetDoc( NULL ); };
    CMarkup( MCD_CSTR szDoc ) { x_InitMarkup(); SetDoc( szDoc ); };
    CMarkup( int nFlags ) { x_InitMarkup(); SetDoc( NULL ); m_nDocFlags = nFlags; };
    CMarkup( const CMarkup& up ) { x_InitMarkup(); *this = up; };
    void operator=( const CMarkup& up );
    ~CMarkup(); // Navigate
    bool Load( MCD_CSTR_FILENAME szFileName );
    bool SetDoc( MCD_PCSZ pDoc );
    bool SetDoc( const MCD_STR& strDoc );
    bool IsWellFormed();
    bool FindElem( MCD_CSTR szName=NULL );
    bool FindChildElem( MCD_CSTR szName=NULL );
    bool IntoElem();
    bool OutOfElem();
    void ResetChildPos() { x_SetPos(m_iPosParent,m_iPos,0); };
    void ResetMainPos() { x_SetPos(m_iPosParent,0,0); };
    void ResetPos() { x_SetPos(0,0,0); };
    MCD_STR GetTagName() const;
    MCD_STR GetChildTagName() const { return x_GetTagName(m_iPosChild); };
    MCD_STR GetData() { return x_GetData(m_iPos); };
    MCD_STR GetChildData() { return x_GetData(m_iPosChild); };
    MCD_STR GetElemContent() const { return x_GetElemContent(m_iPos); };
    MCD_STR GetAttrib( MCD_CSTR szAttrib ) const { return x_GetAttrib(m_iPos,szAttrib); };
    MCD_STR GetChildAttrib( MCD_CSTR szAttrib ) const { return x_GetAttrib(m_iPosChild,szAttrib); };
    bool GetNthAttrib( int n, MCD_STR& strAttrib, MCD_STR& strValue ) const;
    MCD_STR GetAttribName( int n ) const;
    int FindNode( int nType=0 );
    int GetNodeType() { return m_nNodeType; };
    bool SavePos( MCD_CSTR szPosName=MCD_T(""), int nMap = 0 );
    bool RestorePos( MCD_CSTR szPosName=MCD_T(""), int nMap = 0 );
    bool SetMapSize( int nSize, int nMap = 0 );
    MCD_STR GetError() const;
    const MCD_STR& GetResult() const { return m_strResult; };
    int GetDocFlags() const { return m_nDocFlags; };
    void SetDocFlags( int nFlags ) { m_nDocFlags = (nFlags & ~(MDF_READFILE|MDF_WRITEFILE|MDF_APPENDFILE)); };
    enum MarkupDocFlags
    {
    MDF_UTF16LEFILE = 1,
    MDF_UTF8PREAMBLE = 4,
    MDF_IGNORECASE = 8,
    MDF_READFILE = 16,
    MDF_WRITEFILE = 32,
    MDF_APPENDFILE = 64,
    MDF_UTF16BEFILE = 128,
    MDF_TRIMWHITESPACE = 256,
    MDF_COLLAPSEWHITESPACE = 512
    };
    enum MarkupNodeFlags
    {
    MNF_WITHCDATA      = 0x01,
    MNF_WITHNOLINES    = 0x02,
    MNF_WITHXHTMLSPACE = 0x04,
    MNF_WITHREFS       = 0x08,
    MNF_WITHNOEND      = 0x10,
    MNF_ESCAPEQUOTES  = 0x100,
    MNF_NONENDED   = 0x100000,
    MNF_ILLDATA    = 0x200000
    };
    enum MarkupNodeType
    {
    MNT_ELEMENT = 1,    // 0x0001
    MNT_TEXT = 2,    // 0x0002
    MNT_WHITESPACE = 4,    // 0x0004
    MNT_TEXT_AND_WHITESPACE     = 6,    // 0x0006
    MNT_CDATA_SECTION = 8,    // 0x0008
    MNT_PROCESSING_INSTRUCTION = 16,   // 0x0010
    MNT_COMMENT = 32,   // 0x0020
    MNT_DOCUMENT_TYPE = 64,   // 0x0040
    MNT_EXCLUDE_WHITESPACE = 123,  // 0x007b
    MNT_LONE_END_TAG = 128,  // 0x0080
    MNT_NODE_ERROR              = 32768 // 0x8000
    }; // Create
    bool Save( MCD_CSTR_FILENAME szFileName );
    const MCD_STR& GetDoc() const { return m_strDoc; };
    bool AddElem( MCD_CSTR szName, MCD_CSTR szData=NULL, int nFlags=0 ) { return x_AddElem(szName,szData,nFlags); };
    bool InsertElem( MCD_CSTR szName, MCD_CSTR szData=NULL, int nFlags=0 ) { return x_AddElem(szName,szData,nFlags|MNF_INSERT); };
    bool AddChildElem( MCD_CSTR szName, MCD_CSTR szData=NULL, int nFlags=0 ) { return x_AddElem(szName,szData,nFlags|MNF_CHILD); };
    bool InsertChildElem( MCD_CSTR szName, MCD_CSTR szData=NULL, int nFlags=0 ) { return x_AddElem(szName,szData,nFlags|MNF_INSERT|MNF_CHILD); };
    bool AddElem( MCD_CSTR szName, int nValue, int nFlags=0 ) { return x_AddElem(szName,nValue,nFlags); };
    bool InsertElem( MCD_CSTR szName, int nValue, int nFlags=0 ) { return x_AddElem(szName,nValue,nFlags|MNF_INSERT); };
    bool AddChildElem( MCD_CSTR szName, int nValue, int nFlags=0 ) { return x_AddElem(szName,nValue,nFlags|MNF_CHILD); };
    bool InsertChildElem( MCD_CSTR szName, int nValue, int nFlags=0 ) { return x_AddElem(szName,nValue,nFlags|MNF_INSERT|MNF_CHILD); };
    bool AddAttrib( MCD_CSTR szAttrib, MCD_CSTR szValue ) { return x_SetAttrib(m_iPos,szAttrib,szValue); };
    bool AddChildAttrib( MCD_CSTR szAttrib, MCD_CSTR szValue ) { return x_SetAttrib(m_iPosChild,szAttrib,szValue); };
    bool AddAttrib( MCD_CSTR szAttrib, int nValue ) { return x_SetAttrib(m_iPos,szAttrib,nValue); };
    bool AddChildAttrib( MCD_CSTR szAttrib, int nValue ) { return x_SetAttrib(m_iPosChild,szAttrib,nValue); };
    bool AddSubDoc( MCD_CSTR szSubDoc ) { return x_AddSubDoc(szSubDoc,0); };
    bool InsertSubDoc( MCD_CSTR szSubDoc ) { return x_AddSubDoc(szSubDoc,MNF_INSERT); };
    MCD_STR GetSubDoc() { return x_GetSubDoc(m_iPos); };
    bool AddChildSubDoc( MCD_CSTR szSubDoc ) { return x_AddSubDoc(szSubDoc,MNF_CHILD); };
    bool InsertChildSubDoc( MCD_CSTR szSubDoc ) { return x_AddSubDoc(szSubDoc,MNF_CHILD|MNF_INSERT); };
    MCD_STR GetChildSubDoc() { return x_GetSubDoc(m_iPosChild); };
    bool AddNode( int nType, MCD_CSTR szText ) { return x_AddNode(nType,szText,0); };
    bool InsertNode( int nType, MCD_CSTR szText ) { return x_AddNode(nType,szText,MNF_INSERT); }; // Modify bool RemoveElem();
    bool RemoveChildElem();
    bool RemoveNode();
    bool SetAttrib( MCD_CSTR szAttrib, MCD_CSTR szValue, int nFlags=0 ) { return x_SetAttrib(m_iPos,szAttrib,szValue,nFlags); };
    bool SetChildAttrib( MCD_CSTR szAttrib, MCD_CSTR szValue, int nFlags=0 ) { return x_SetAttrib(m_iPosChild,szAttrib,szValue,nFlags); };
    bool SetAttrib( MCD_CSTR szAttrib, int nValue, int nFlags=0 ) { return x_SetAttrib(m_iPos,szAttrib,nValue,nFlags); };
    bool SetChildAttrib( MCD_CSTR szAttrib, int nValue, int nFlags=0 ) { return x_SetAttrib(m_iPosChild,szAttrib,nValue,nFlags); };
    bool SetData( MCD_CSTR szData, int nFlags=0 ) { return x_SetData(m_iPos,szData,nFlags); };
    bool SetChildData( MCD_CSTR szData, int nFlags=0 ) { return x_SetData(m_iPosChild,szData,nFlags); };
    bool SetData( int nValue ) { return x_SetData(m_iPos,nValue); };
    bool SetChildData( int nValue ) { return x_SetData(m_iPosChild,nValue); };
    bool SetElemContent( MCD_CSTR szContent ) { return x_SetElemContent(szContent); };
    // Utility
    static bool ReadTextFile( MCD_CSTR_FILENAME szFileName, MCD_STR& strDoc, MCD_STR* pstrResult=NULL, int* pnDocFlags=NULL, MCD_STR* pstrEncoding=NULL );
    static bool WriteTextFile( MCD_CSTR_FILENAME szFileName, const MCD_STR& strDoc, MCD_STR* pstrResult=NULL, int* pnDocFlags=NULL, MCD_STR* pstrEncoding=NULL );
    static MCD_STR EscapeText( MCD_CSTR szText, int nFlags = 0 );
    static MCD_STR UnescapeText( MCD_CSTR szText, int nTextLength = -1, int nFlags = 0 );
    static int UTF16To8( char *pszUTF8, const unsigned short* pwszUTF16, int nUTF8Count );
    static int UTF8To16( unsigned short* pwszUTF16, const char* pszUTF8, int nUTF8Count );
    static MCD_STR UTF8ToA( MCD_CSTR pszUTF8, int* pnFailed = NULL );
    static MCD_STR AToUTF8( MCD_CSTR pszANSI );
    static void EncodeCharUTF8( int nUChar, char* pszUTF8, int& nUTF8Len );
    static int DecodeCharUTF8( const char*& pszUTF8, const char* pszUTF8End = NULL );
    static void EncodeCharUTF16( int nUChar, unsigned short* pwszUTF16, int& nUTF16Len );
    static int DecodeCharUTF16( const unsigned short*& pwszUTF16, const unsigned short* pszUTF16End = NULL );
    static bool DetectUTF8( const char* pText, int nTextLen, int* pnNonASCII = NULL, bool* bErrorAtEnd = NULL );
    static MCD_STR GetDeclaredEncoding( MCD_CSTR szDoc );
    static int GetEncodingCodePage( MCD_CSTR pszEncoding );
      

  10.   

    用 tinyxml