取消引用传递给 COM 函数的变量时出错
Errors dereferencing variables passed to COM functions
我是 运行 我项目中一个单独项目的代码,当我下载并编译原始源代码时,它运行顺利,但在我的代码中会出现错误。我试图通过将变量类型转换为编译器期望的类型来修复错误,但这导致 CoCreateInstance
和后续函数失败,导致我得出结论,问题是我'我缺少使调用正常工作所需的代码,因此我搜索了原始源代码,但找不到该代码。有人可以解释一下出了什么问题吗?我已经在这里待了 4-5 个小时。
错误是:
代码:
(https://pastebin.com/jffKKZAe完整代码,以防我遗漏了什么)
#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;
}
原始源代码在 C
中编写,其中不存在引用,因此 CoCreateInstance
在 C
中声明接受指向 CLSID
的指针作为第一个参数。虽然在 C++
中声明 CoCreateInstance
接受对 CLSID
的引用作为第一个参数,但您仍在尝试传递指针。等等。因此你会得到这些错误。将您的代码重新编译为 C
或删除不必要的地址占用。
我是 运行 我项目中一个单独项目的代码,当我下载并编译原始源代码时,它运行顺利,但在我的代码中会出现错误。我试图通过将变量类型转换为编译器期望的类型来修复错误,但这导致 CoCreateInstance
和后续函数失败,导致我得出结论,问题是我'我缺少使调用正常工作所需的代码,因此我搜索了原始源代码,但找不到该代码。有人可以解释一下出了什么问题吗?我已经在这里待了 4-5 个小时。
错误是:
代码:
(https://pastebin.com/jffKKZAe完整代码,以防我遗漏了什么)#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;
}
原始源代码在 C
中编写,其中不存在引用,因此 CoCreateInstance
在 C
中声明接受指向 CLSID
的指针作为第一个参数。虽然在 C++
中声明 CoCreateInstance
接受对 CLSID
的引用作为第一个参数,但您仍在尝试传递指针。等等。因此你会得到这些错误。将您的代码重新编译为 C
或删除不必要的地址占用。