我有以下 JNA 接口(interface):
public interface MsiVersion extends StdCallLibrary {
MsiVersion INSTANCE = (MsiVersion)Native.loadLibrary( "msi", MsiVersion.class,
W32APIOptions.UNICODE_OPTIONS );
int MsiOpenDatabase( String szDatabasePath,
String szPersist,
Memory phDatabase );
}
如果我像这样打开 MSI,一切都很好:
int oparationResult = MsiVersion.INSTANCE.MsiOpenDatabase( "example.msi", "0",
dbPointerMemory );
如果我尝试打开补丁,则会收到错误代码 110。在文档中,我发现如果我想打开补丁,我应该以某种方式将 MSIDBOPEN_READONLY + MSIDBOPEN_PATCHFILE 作为“szPersist”而不是“0”传递。
我尝试根据此调用以下内容:http://archives.miloush.net/michkap/archive/2006/04/16/577108.html
int oparationResult = MsiVersion.INSTANCE.MsiOpenDatabase( "example.msp", "32",
dbPointerMemory );
但仍然收到错误代码 110。有人可以帮我找到正确的参数吗?
谢谢, 巴林特
最佳答案
问题是,MsiOpenDatabase
szPersist
参数需要一个字符串指针,但如果指定了持久模式,这实际上是一个转换为字符串指针的数字。
来自“msiquery.h”:
#define MSIDBOPEN_READONLY (LPCTSTR)0
#define MSIDBOPEN_PATCHFILE 32/sizeof(*MSIDBOPEN_READONLY)
您将字符串文字“32”传递给szPersist
参数,但您需要向其传递一个值为32的指针:
Pointer openMode = Pointer.createConstant(32);
int operationResult = MsiVersion.INSTANCE.MsiOpenDatabase( "example.msp", openMode, dbPointerMemory );
我不是 Java 程序员,所以我只是通过阅读 reference 来弥补这一点。还有这个FAQ (如何获得任意指针值?)。
我不确定您是否还需要更改 JNA 接口(interface):
int MsiOpenDatabase( String szDatabasePath,
Pointer szPersist,
Memory phDatabase );
注意:如 Heath Stewart explained ,头文件“msiquery.h”中的定义不正确。即使针对 Unicode 进行编译,MSIDBOPEN_PATCHFILE 的值也必须始终为 32
。
关于java - 对于使用 jna 的补丁,MsiOpendatabase 返回错误 110,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43394040/