如果已安裝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;