这里pWnd为NULL,但MFC为什么不报空指针异常,而是调用了当前文件的ShowInfo函数。
进入ShowInfo函数后m_editDisplay又是空指针,直接忽略了这句,继续向后执行。




2宏定义不改源码 用替换 用Log函数替换printf等 #define printf Log

优化版底层类Log显示
cpp
方法一:
//全局定义
CEdit* m_edit;
在初始化里
m_edit = &edit; // 指向当前界面edit
Log里操作edit显示
方法二:
void(*pLogMethod)(const char* strMsg, ...); //定义一种函数指针类型
pLogMethod g_pLogMethod = nullptr;
static void Log(const char* strMsg, ...)
{
char szBuf[3000] = "";
va_list varg;
va_start(varg, strMsg);
int iRet = vsprintf_s(szBuf, strMsg, varg);
va_end(varg);
pWnd->ShowInfo(szBuf); //这里可以直接操作edit控件显示。
}
CConfigDlg::CConfigDlg(CWnd* pParent /*=nullptr*/)
: CDialogEx(IDD_DIALOG_VersionCompareWriteConfig, pParent)
{
pWnd = this;
g_pLogMethod = Log;
}
使用 if (g_pLogMethod != nullptr) { g_pLogMethod(app + "应用安装失败。"); }