ReadMsiProperties.exe evince-2.32.0.145.msi (MsiOpenDatabase-6ren">
gpt4 book ai didi

c++ - MsiViewFetch "SELECT * FROM ` 属性 `"is successful, but returns "函数不正确。”在 C++ 中

转载 作者:太空宇宙 更新时间:2023-11-04 13:54:52 25 4
gpt4 key购买 nike

我想读取一个 msi 文件的属性表。该表显示正确。

这是调用和(部分)输出:

>ReadMsiProperties.exe evince-2.32.0.145.msi
(MsiOpenDatabase The operation completed successfully.)
(MsiViewFetch Incorrect function.) WixAppFolder = WixPerUserFolder
(MsiViewFetch Incorrect function.) WixUIRMOption = UseRM
(MsiViewFetch Incorrect function.) WIXUI_INSTALLDIR = APPLICATIONFOLDER
(MsiViewFetch Incorrect function.) ALLUSERS = 2

MsiViewFetch 成功但返回“不正确的函数”。这是来自 winerror.h 的错误代码 1 (ERROR_INVALID_FUNCTION)

我假设我错过了一些东西并且不想忽略错误。

我已尝试调试,但似乎无法调试到 MsiViewFetch。

有人有提示吗?

谢谢,马库斯

这是代码:

// Requirements: Add Msi.lib to "Resource Files" 

#include "stdafx.h"
#include <windows.h>
#include <msi.h>
#include <msiquery.h>

MSIHANDLE hDB;
MSIHANDLE hViewSELECT;
MSIHANDLE hRecord;
TCHAR svPropname[256];
TCHAR svPropvalue[256];
DWORD nBuffer;
UINT errorI;
_TCHAR errorM[256];


void errorCode2char (UINT error, _TCHAR *buf) {
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, error, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buf, 256, NULL);
// chop \r\n
if (buf[_tcslen(buf)-1] = '\n') buf[_tcslen(buf)-1] = '\0';
if (buf[_tcslen(buf)-1] = '\r') buf[_tcslen(buf)-1] = '\0';
}

void _tmain(int argc, _TCHAR* argv[]) {
errorI = MsiOpenDatabase(argv[1], MSIDBOPEN_READONLY, &hDB);
errorCode2char(errorI, errorM);
printf("(MsiOpenDatabase %S)\n", errorM);
if (errorI != ERROR_SUCCESS) return;

MsiDatabaseOpenView(hDB, _T("SELECT `Property`, `Value` FROM `Property`"), &hViewSELECT);
MsiViewExecute(hViewSELECT, NULL);
while (errorI = MsiViewFetch (hViewSELECT, &hRecord) != ERROR_NO_MORE_ITEMS) { // *errorI <-- Incorrect function.
errorCode2char(errorI, errorM);
nBuffer = (DWORD)256; MsiRecordGetString(hRecord, 1, svPropname, &nBuffer);
nBuffer = (DWORD)256; MsiRecordGetString(hRecord, 2, svPropvalue, &nBuffer);
printf("(MsiViewFetch %S) %S = %S\n", errorM, svPropname, svPropvalue);
}
MsiViewClose(hViewSELECT);
MsiDatabaseCommit(hDB);
MsiCloseHandle(hViewSELECT);
MsiCloseHandle(hDB);
}

最佳答案

编码错误扭曲了 MsiViewFetch 的返回码,未扭曲的返回码为 0(对于 ERROR_SUCCESS)。

在 C++ 中,比较 (!=) 优先于直接赋值 (=)。

因此,声明

while (a = b != c)

被解释为

while (a = (b != c))

这不是我的本意。

程序通过插入括号修正

while ((a = b) != c)

明确地

while ((errorI = MsiViewFetch(hView, &hRecord)) != ERROR_NO_MORE_ITEMS)

关于c++ - MsiViewFetch "SELECT * FROM ` 属性 `"is successful, but returns "函数不正确。”在 C++ 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21955250/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com