编写了一个扩展的dll,供外部程序调用的。可是出现了问题不知道该如何解决。
问题现象是调用dll中的一个窗体完成登录。在dll的导出函数中 中使用 dlg->DoModule() dll程序进入到DllMain中
然后循环两次后就出现 assetion failed 错误
说文件是afxwin1.inl
位置在22行不知道怎么回事啊,各位老大救命。
DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
{
// Remove this if you use lpReserved
UNREFERENCED_PARAMETER(lpReserved); if (dwReason == DLL_PROCESS_ATTACH)
{
TRACE0("LOGIN.DLL Initializing!\n");

// Extension DLL one-time initialization
if (!AfxInitExtensionModule(LoginDLL, 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(LoginDLL);
}
else if (dwReason == DLL_PROCESS_DETACH)
{
TRACE0("LOGIN.DLL Terminating!\n");
// Terminate the library before destructors are called
AfxTermExtensionModule(LoginDLL);
}
return 1;   // ok
}
extern "C" _declspec(dllexport) BOOL UserLogin(char *strDepartment,_ConnectionPtr dllconn)
{
strdllDepartment=strDepartment;
CDlgLogin *dlg=new CDlgLogin();
    dlg->m_conn=dllconn;
  
  if(dlg->DoModal()==IDOK)   //执行到这里就跳入了DLLMain开始循环了,dlg就是一个一般的窗体
  {
  delete dlg;
  return TRUE;  
  }
  else
  {
  delete dlg;
      return FALSE;
  }}调用代码typedef BOOL (*FuncUserLogin)(char *,_ConnectionPtr);
    HINSTANCE hInstance=LoadLibrary("Login.dll");
    FuncUserLogin pUserLogin=(FuncUserLogin)GetProcAddress(hInstance,"UserLogin");
    if(pUserLogin(strCurrentUser.strCurrentUserDepartment.GetBuffer(10),GlobalConn)==false)
{
return FALSE;
}

strCurrentUser.strCurrentUserDepartment.ReleaseBuffer();
FreeLibrary(hInstance);

解决方案 »

  1.   

    发现好像不是dll的问题。是调用程序的问题,如果使用静态链接就会出现上述问题。如果使用动态链接就正常。搞晕了 哪位能救命
      

  2.   

    对于扩展DLL,EXE项目和DLL项目使用MFC的方式必须相同,不能一个静态另一个动态。
      

  3.   

    2楼对极了,你的扩展DLL是MFC的扩展,你怎么可以不用MFC的dll ?
      

  4.   

    DllMain  通常用在动态链接.
      

  5.   

    对于扩展DLL,EXE项目和DLL项目使用MFC的方式必须相同,不能一个静态另一个动态。
      

  6.   

    DllMain中不允许使用wait 类的API,,检查CDynLinkLibrary中是否有此类函数。