上篇写的是.dll
本篇写调用它的.exe
1.以管理员身份,把dll动态库注册到注册表中 .
2.调用DLL的exe
2.1新建项目MFC应用-基于对话框:
2.2 添加dll的.c和.h文件到exe文件
#include "UnifiedRegistInterface_i.c"
#include "UnifiedRegistInterface_i.h"
void CATLTestDlg::OnBnClickedButton1()
{
HRESULT hr = S_OK;
hr = CoInitialize(NULL);
ITypeLib* pTypeLib = NULL;
hr = ::LoadTypeLib(L"D:\\Source\\repos\\ATLTest\\UnifiedRegistInterface.dll", &pTypeLib);
if (FAILED(hr))
{
return;
}
int nTypeInfoCount = pTypeLib->GetTypeInfoCount();
if (nTypeInfoCount <= 0) //返回类型库中的类型说明的数量
{
return;
}
ITypeInfo* pTypeInfo = NULL;
TYPEATTR* pTypeAttr = NULL;
//!!!此处一定要注意导出类在.idl文件中的顺序!!!
hr = pTypeLib->GetTypeInfo(6, &pTypeInfo);
hr = pTypeInfo->GetTypeAttr(&pTypeAttr);
CLSID clsid = pTypeAttr->guid;
hr = pTypeLib->GetTypeInfo(6, &pTypeInfo);
hr = pTypeInfo->GetTypeAttr(&pTypeAttr);
IID iid = pTypeAttr->guid;
IScadantRegister* pScadaRegister = NULL;
hr = CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER, iid, (void**)&pScadaRegister);
hr = CoCreateInstance(CLSID_ScadantRegister, NULL, CLSCTX_INPROC_SERVER, IID_IScadantRegister, (void**)&pScadaRegister);
BSTR* retstr = NULL;
BSTR PutInstr = SysAllocString(L"2023 - 12 - 18 | V20 |7226526141");
pScadaRegister->getRegString(PutInstr, retstr);
pTypeInfo->ReleaseTypeAttr(pTypeAttr);
pTypeInfo->Release();
CoUninitialize();
}
示例代码:
https://download.csdn.net/download/aggie4628/88694018
https://download.csdn.net/download/aggie4628/88694013