移除DuiLib项目Linker中的riched20.lib

如果已安装Windows SDK、Windows Mobile SDK且默认包含这些目录编译源代码没有问题。由于一些改动需要版本管理发现Build Agent运行失败,考虑到迁移各方面原因还是决定修改调用部分。

首先移除项目几个配置版本Linker里的riched20.lib,之后打开UIRichEdit.cpp定位到如下源代码:

// Create Text Services component
if(FAILED(CreateTextServices(NULL, this, &pUnk)))
    goto err;

我们需要将Riched20.dll动态加载进来,CreateTextServices的函数原型如下:

HRESULT CreateTextServices(IUnknown*, IUnknown*, IUnknown*)

修改代码如下,需要注意在获取到ITextServices接口指针后不能立刻调用FreeLibrary释放Riched20.dll的模块句柄,而是在析构函数里:

typedef HRESULT(_stdcall *CTSFunc)(IUnknown *punkOuter, ITextHost *pITextHost, IUnknown **ppUnk);
CTSFunc ctsFunc = NULL;
auto hRiched20 = LoadLibrary(_T("Riched20.dll"));

if (NULL == hRiched20)
    goto err;
else
{
    ctsFunc = (CTSFunc)GetProcAddress(hRiched20, "CreateTextServices");

    if (NULL == ctsFunc)
        goto err;
}

if (FAILED(ctsFunc(NULL, this, &pUnk)))
    goto err;
原文地址:https://www.cnblogs.com/junchu25/p/3320778.html