测试主程序:
#include "stdafx.h"int APIENTRY WinMain(HINSTANCE hInstance,
                    HINSTANCE hPrevInstance,
                    LPSTR    lpCmdLine,
                    int      nCmdShow)
{
// TODO: Place code here.
typedef BOOL (WINAPI *pFUNCTION)(CWnd*);
pFUNCTION pFunction;HINSTANCE hDll = LoadLibrary("ebdk_com.dll");pFunction = (pFUNCTION)::GetProcAddress(hDll, "DLL_ConfigureCommPort");if(!pFunction) 
MessageBox(NULL,"failed to load dll","Test",MB_OK );
else
MessageBox(NULL,"success loading dll","Test",MB_OK );// throw up DLL_Conf dialog to make connection
pFunction(NULL);return 0;

解决方案 »

  1.   

    在你得DLL中得函数DLL_ConfigureCommPort开头增加如下语句AFX_MANAGE_STATE(AfxGetStaticModuleState());
      

  2.   

    这是Debug版本的问题,你调用函数时用的是
    pFunction(NULL);
    在这里,传入的参数是一个空指针,而在Debug版本中,ASSERT宏是会加入你地编译后的代码中的,一旦当条件值为FALSE时便会弹出Debug Assertion Failed!的对话框,一般在程序中用这个宏来检查指针类型的变量是否有效,尤其在VC的MFC类中,在任何窗口类中都有对窗口句柄的检查,这是在Debug版本中为方便调试而做的。
    如果你在调试中仔细看得话,很有可能会看见如下一句:
    ASSERT(m_hWnd != NULL); 或 ASSERT(m_hWnd);
    由于你的函数参数是CWnd的指针类型,所以,MFC会自动对其有效性进行检查,因此会出现Debug Assertion Failed!的警告。一旦你将其编译成Release版本之后,就不会有Debug Assertion Failed!的警告了!
      

  3.   

    出现assertion failed的地方是在ASSERT(afxCurrentResourceHandle != NULL)第一贴中