我在有EVC建立一个dll时,用的是WINCE Dynamic-Link Liabrary选项,然后加入类如下:
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers#include <afxwin.h>         // MFC core and standard components//标准模板库和标准收集动态数据分配
#ifndef _AFX_STEMPL_COLL
#define _AFX_STEMPL_COLL
#include <afxtempl.h>
#include <afxcoll.h>
#include "math.h"
#endif//该头文件定义图像处理宏:#ifndef __m3d_h_
#ifndef __M3D_H_#define __m3d_h_
#define __M3D_H_#ifdef __cplusplus
extern "C" {
/////////////////////////////////////////////////////////////////////////////////
//
//  interface for the CVertex3d class.
//
////////////////////////////////////////////////////////////////////////////////
//has included afxcoll.h in the stdafx.h
class __declspec(dllexport) CVertex3d 
{

public:
CVertex3d();
CVertex3d(const CVertex3d& vSrc);
virtual ~CVertex3d();public:
CVertex3d operator = (const CVertex3d& vSrc); void DefineTopology(const int* pnInFacet, int nNumFacet);public:
 CArray <int,int>  m_asIndex;
};
然后编写相应的CPP文件,出现warning如下:
warning C4251: 'm_asIndex' : class 'CArray<int,int>' needs to have dll-interface to be used by clients of class 'CVertex3d'libli
并生成lib和dll文件。生成后新建新工程来引用 库中的类,但是当引用类成员
 m_asIndex并向其中增加一个成员时,出现异常,如下:
unhandled exception in xx.exe:0xc00000005 :Access Violation.对于此问题我是刚摸dll,还请各们大侠指教,定当高分送上,谢谢!!!!!

解决方案 »

  1.   

    自己找到
    Knowledge Base Articles   PRB: C4251 & C4275 Compiler Warnings While Compiling an AFXDLL
    Q134980
    --------------------------------------------------------------------------------
    The information in this article applies to:The Microsoft Foundation Classes (MFC), used with:
    Microsoft Visual C++, 32-bit Editions, versions 2.0, 2.1, 2.2--------------------------------------------------------------------------------
    SYMPTOMS
    The Compiler issues the following warning for a class derived from one of the MFC classes: warning C4275: non dll-interface class <XXX> used as base for dll-interface class <YYY> 
    A related warning is issued when an object of some MFC class is embedded as a data member of a user-defined class: 
    warning C4251: <identifier> : class <XXX> needs to have dll-interface to be used by clients of class <YYY> 
    See the "Sample Code" section of this article an example of a class declaration that generates these warnings.This problem no longer occurs in vc 4.0 or later. CAUSE
    The DLL version of MFC does not export its classes by declaring them with "class __declspec(dllexport)." Instead, it exports its classes through entries in the EXPORTS section of its module definition (.def) file.Because the compiler has only the header files to work with, it cannot determine whether the MFC classes were actually exported, and therefore it issues the warning. RESOLUTION
    Because the MFC classes are in fact exported, these warnings can be safely ignored. As shown in the DLLHUSK sample, you can disable these warnings by using the following pragma statements: 
      #pragma warning(disable: 4275)
      #pragma warning(disable: 4251) 
    On the other hand, if the warnings refer to some user-defined class rather an MFC class, you should ensure that the class is exported before disabling these warnings. STATUS
    This behavior is by design. MORE INFORMATIONSample Code to Reproduce Behavior/* Compile options needed: None
    */ // The following class declaration causes a C4275 warning
    // because the CObject class is not also declared with
    // __declspec(dllexport).
    class __declspec(dllexport) CMyClass : public CObject
    {
      ...
      // The following data member causes a C4251 warning,
      // because the CString class is not declared with
      // __declspec(dllexport).
      CString m_strName;
      ...
    }; REFERENCES
    For more information, please see MFC TechNote 33 for a discussion of the reasons behind the decision to export MFC's classes in the module definition file rather than in the class declaration. Additional query words: 2.00 2.10 2.20 3.00 3.10 3.20 Keywords : kberrmsg kbnokeyword kbDLL kbMFC kbVC200 kbVC220 kbGrpDSMFCATL 
    Issue type : kbprb 
    Technology : kbAudDeveloper kbMFC 
    Last Reviewed: May 6, 2001--------------------------------------------------------------------------------Send feedback to Microsoft&copy; 2002 Microsoft Corporation. All rights reserved.
     
      

  2.   

    不过这虽然知道了原因,但还是不知如何去解决它,我知道因为dll文件与exe文件的区别在于前者没有堆栈,而在进行动态分配内存进都是在堆栈中分配的。而上面的程序的CArray是要动态分配内存的,是不是因为这个才出错的???,以上是我的理解????不知各们有没有更好的意见????