我在我的项目中运行来自单独项目的代码,当我下载并编译原始源代码时,它运行顺畅,但在我的内容中呕吐错误。我试图通过将变量类型转换为编译器预期的变量来修复错误,但这会导致CoCreateInstance
和后续函数失败,从而导致我得出的结论是问题是我错过了使调用工作所需的代码,因此我搜索了原始资源,但我无法找到该代码。有人可以解释一下出了什么问题吗?我已经在这里待了4-5个小时。
错误是:
#include "stdafx.h"
#include <objbase.h>
#include <Windows.h>
#include <ntstatus.h>
#include <CommCtrl.h>
#include <shlobj.h>
#include <iostream>
#include <fci.h>
#include <fcntl.h>
#pragma comment(lib,"Ole32.lib")
#define T_CLSID_UninstallStringLauncher L"{FCC74B77-EC3E-4DD8-A80B-008A702075A9}"
#define T_IID_IARPUninstallStringLauncher L"{F885120E-3789-4FD9-865E-DC9B4A6412D2}"
BOOL ucmMasqueradedAPRLaunchFile(
_In_ LPWSTR lpszFileGuid
)
{
BOOL bCond = FALSE;
HRESULT r = E_FAIL;
IID xIID_IARPUninstallStringLauncher;
CLSID xCLSID_IARPUninstallStringLauncher;
IARPUninstallStringLauncher *USLauncher = NULL;
do {
if (lpszFileGuid == NULL)
break;
if (CLSIDFromString(T_CLSID_UninstallStringLauncher, &xCLSID_IARPUninstallStringLauncher) != NOERROR) {
break;
}
if (IIDFromString(T_IID_IARPUninstallStringLauncher, &xIID_IARPUninstallStringLauncher) != S_OK) {
break;
}
//Error in CoCreateInstance
r = CoCreateInstance(&xCLSID_IARPUninstallStringLauncher, NULL,
CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER | CLSCTX_INPROC_HANDLER,
&xIID_IARPUninstallStringLauncher, &USLauncher);
if (r != S_OK)
break;
//Error here too
r = ucmMasqueradedCoGetObjectElevate(T_CLSID_UninstallStringLauncher,
CLSCTX_LOCAL_SERVER, &xIID_IARPUninstallStringLauncher, &USLauncher);
if (r != S_OK)
break;
r = USLauncher->lpVtbl->LaunchUninstallStringAndWait(USLauncher, 0, lpszFileGuid, FALSE, NULL);
} while (bCond);
if (USLauncher != NULL) {
USLauncher->lpVtbl->Release(USLauncher);
}
return SUCCEEDED(r);
}
BOOL ucmUninstallLauncherMethod(
_In_ LPWSTR lpszExecutable
)
{
BOOL bResult = FALSE, bCond = FALSE;
HKEY hKey = NULL;
LRESULT lResult;
GUID guid;
WCHAR szKeyName[MAX_PATH], szGuid[64];
do {
if (lpszExecutable == NULL)
break;
if (CoCreateGuid(&guid) != S_OK)
break;
_strcpy_w(szKeyName, L"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\");
//the &guid returns an error, aswell.
if (StringFromGUID2(&guid, szGuid, sizeof(szGuid) / sizeof(WCHAR))) {
_strcat_w(szKeyName, szGuid);
lResult = RegCreateKeyEx(HKEY_CURRENT_USER,
szKeyName, 0, NULL, REG_OPTION_NON_VOLATILE, MAXIMUM_ALLOWED, NULL, &hKey, NULL);
if (lResult != ERROR_SUCCESS)
break;
lResult = RegSetValueEx(hKey, L"UninstallString", 0, REG_SZ, (BYTE*)lpszExecutable,
(DWORD)(_strlen_w(lpszExecutable) * sizeof(WCHAR)));
if (lResult != ERROR_SUCCESS)
break;
bResult = ucmMasqueradedAPRLaunchFile(szGuid);
}
} while (bCond);
if (hKey != NULL) {
RegCloseKey(hKey);
RegDeleteKey(HKEY_CURRENT_USER, szKeyName);
}
return bResult;
}
int main()
{
bool h = ucmUninstallLauncherMethod(L"c:\\windows\\system32\\cmd.exe");
if (h == TRUE)
std::cout << "function returned true" << std::endl;
else
std::cout << "Function failed you imbicile" << std::endl;
return 0;
}
答案 0 :(得分:1)
原始源代码编写在C
中,其中引用不存在,因此在CoCreateInstance
中声明C
接受指向CLSID
的指针作为第一个参数。虽然在C++
CoCreateInstance
中声明接受对CLSID
的引用作为第一个参数,但您仍尝试传递指针。等等。因此,您会收到这些错误。将代码重新编译为C
或删除不必要的地址。