情况如下:
(1)我做的是一个MXF Ext Dll;
(2)在内部我需要使用CSocket类,所以在DllMain中调用了AfxInitSocket;如下是DllMain的代码。static AFX_EXTENSION_MODULE EVTRExtDLL = { NULL, NULL };extern "C" int APIENTRY
DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
{
// Remove this if you use lpReserved
UNREFERENCED_PARAMETER(lpReserved);if (dwReason == DLL_PROCESS_ATTACH)
{
    TRACE0("EVTRExt.DLL Initializing!\n");

     // Extension DLL one-time initialization
    if (!AfxInitExtensionModule(EVTRExtDLL, hInstance))
        return 0;    // Insert this DLL into the resource chain
    // NOTE: If this Extension DLL is being implicitly linked to by
    //  an MFC Regular DLL (such as an ActiveX Control)
    //  instead of an MFC application, then you will want to
    //  remove this line from DllMain and put it in a separate
    //  function exported from this Extension DLL.  The Regular DLL
    //  that uses this Extension DLL should then explicitly call that
    //  function to initialize this Extension DLL.  Otherwise,
    //  the CDynLinkLibrary object will not be attached to the
    //  Regular DLL's resource chain, and serious problems will
    //  result.    new CDynLinkLibrary(EVTRExtDLL);    // Sockets initialization
    // NOTE: If this Extension DLL is being implicitly linked to by
    //  an MFC Regular DLL (such as an ActiveX Control)
    //  instead of an MFC application, then you will want to
    //  remove the following lines from DllMain and put them in a separate
    //  function exported from this Extension DLL.  The Regular DLL
    //  that uses this Extension DLL should then explicitly call that
    //  function to initialize this Extension DLL.
    //if (!AfxSocketInit())
    //{
    // return FALSE;
    //}

}
else if (dwReason == DLL_PROCESS_DETACH)
{
    TRACE0("EVTRExt.DLL Terminating!\n");    // Terminate the library before destructors are called
    AfxTermExtensionModule(EVTRExtDLL);}
    return 1;   // ok
}(3)导出一个类CFTPUtility如下:
class AFX_EXT_CLASS CFTPUtility{
  public:
      BOOL LogOn();
      BOOL DownloadFile();
      void LogOff();
};(4)在LogOn中我需要new一个CSocket,同时调用成员函数Create来创建socket。问题:(1)在调用CSocket.Create的时候出现异常,错误如下:
mfc71d.dll!AfxGetInstanceHandle()  Line 24 C++
mfc71d.dll!AfxRegisterWndClass(unsigned int nClassStyle=0, HICON__ * hCursor=0x00000000, HBRUSH__ * hbrBackground=0x00000000, HICON__ * hIcon=0x00000000)  Line 1413 + 0x5 C++
mfc71d.dll!CAsyncSocket::AttachHandle(unsigned int hSocket=2252, CAsyncSocket * pSocket=0x014e7d38, int bDead=0)  Line 470 + 0x22 C++
mfc71d.dll!CAsyncSocket::Socket(int nSocketType=1, long lEvent=63, int nProtocolType=0, int nAddressFormat=2)  Line 631 C++
mfc71d.dll!CAsyncSocket::Create(unsigned int nSocketPort=0, int nSocketType=1, long lEvent=63, const char * lpszSocketAddress=0x00000000)  Line 107 + 0x14 C++
mfc71d.dll!CSocket::Create(unsigned int nSocketPort=0, int nSocketType=1, const char * lpszSocketAddress=0x00000000)  Line 49 + 0x1d C++(2)此MFC Ext Dll将会被一个win32 dll来使用。在DllMain中的new 和AfxInitSocket函数的前面都有一段注释,请问题是什么意思?我怀疑错误(1)和此问题有关。(3)如果如问题(2)所说,那么我该如何做呢?是否需要添加一个成员函数Init,在内部调用AfxInitSocket? 我这样做了,但是问题没有解决。
(4)如果不是如(2)所说,那么问题出在什么地方,如何解决?在线等待,谢谢!

解决方案 »

  1.   

    试试AFX_MANAGE_STATE(AfxGetStaticModuleState());
      

  2.   

    编译不过,如下问题:
    Linking...
    LINK : LNK6004: D:\Filters\Debug/EVTRExt.dll not found or not built by the last incremental link; performing full link
    mfcs71d.lib(dllmodul.obj) : error LNK2005: _DllMain@12 already defined in EVTRExt.obj
    mfcs71d.lib(dllmodul.obj) : warning LNK4006: _DllMain@12 already defined in EVTRExt.obj; second definition ignored
       Creating library Debug/EVTRExt.lib and object Debug/EVTRExt.exp
    D:\Filters\Debug/EVTRExt.dll : fatal error LNK1169: one or more multiply defined symbols found
      

  3.   

    你用MFC的扩展DLL,为何又自己提供DllMain呢?
      

  4.   

    我是在一个regural dll中调用此ext dll。
      

  5.   

    AfxInitSocket放到dll 的初始化函数中