“安装程序打开InfFile” Delphi2010 出现访问冲突错误

发布于 2024-10-17 16:29:09 字数 359 浏览 15 评论 0原文

在 Delphi 2010 中使用以下行代码时,出现“访问冲突”错误,但相同的代码在 VC++ 中工作正常。

Delphi 2010 代码是

var
  hMyInf : HINF;
begin
hMyInf := SetupOpenInfFile('.\\DIGIMHID.INF','Mouse', INF_STYLE_WIN4,Nil);

VC++ 代码是

hMyInf = SetupOpenInfFile(".\\DigimHID.inf", "Mouse", INF_STYLE_WIN4, NULL);

请帮我解决这个问题。 谢谢大家。

When using the following line code in Delphi 2010, a'm getting an "Access Violation" error, but the same code working fine in VC++.

The Delphi 2010 code is

var
  hMyInf : HINF;
begin
hMyInf := SetupOpenInfFile('.\\DIGIMHID.INF','Mouse', INF_STYLE_WIN4,Nil);

The VC++ code is

hMyInf = SetupOpenInfFile(".\\DigimHID.inf", "Mouse", INF_STYLE_WIN4, NULL);

Please help me to solve this issue.
Thanks All.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

分开我的手 2024-10-24 16:29:09

在使用 SetupAPI.pas

Edit 中的任何方法之前调用 LoadSetupAPI,以提供一些背景信息:正如 David 在他的回答中和我同时写的那样在我的评论中,该错误可能是由于调用未初始化的方法指针引起的。对我来说,第一个提示是错误消息,即访问冲突:如果相当于访问冲突的内容来自 Windows 本身,则称为运行时错误 216。代码非常简单,只使用常量和方法调用。常量无法生成 AV,因此错误必须来自方法本身,或者来自调用该方法。

由于提供的 Delphi 声明显示了“函数类型”,我怀疑 SetupOpenInfFile 实际上是一个方法指针,而不是 import 方法。这些指针需要以某种方式进行初始化。搜索 SetupAPI.pas (感谢 google 提供链接,因为我不使用 JEDI 库)我很快发现它是从 LoadSetupAPI 分配的。我的第一个想法:不是从 initialization 部分调用 LoadSetupAPI 吗?事实并非如此,因此需要从代码中调用它。 问题已解决。

Call LoadSetupAPI before using any methods in the SetupAPI.pas

Edit, to provide some background: As simultaneously wrote by David in his answer and by me in my comment, the error is probably caused by calling an uninitialized method pointer. For me the first tip was the error message, an Access Violation: If the equivalent of an Access Violation came from Windows itself, it'd be called a Runtime Error 216. The code is very simple, only uses constants and a method call. Constants can't generate AV's so the error had to come from the method itself, or from calling the method.

Since the Delphi declaration supplied showed a "function type", I suspected SetupOpenInfFile is actually an method pointer, not an import method. Those pointers need to somehow be initialized. Searching SetupAPI.pas (thanks google for providing a link, because I don't use JEDI libraries) I quickly found that it's being assigned from LoadSetupAPI. My first thought: isn't LoadSetupAPI called from the initialization section? It's not, so it needs to be called from code. Problem solved.

一江春梦 2024-10-24 16:29:09

Delphi 版本中你的文件名是错误的。在 Delphi 中你不能转义 \ ,一个就可以了。但这不会导致访问冲突。

我的猜测是您的 GetProcAddress 调用失败。但这只是猜测。我想查看更多代码和完整的错误消息。

编辑

看来我们走在正确的轨道上。 Cosmin的回答将为您解决问题。另一种方法是通过删除 SetupApi.pas 中条件 SETUPAPI_LINKONREQUEST 的定义来切换到隐式链接。

Your filename is wrong in the Delphi version. You don't escape \ in Delphi, a single one will do. But that wouldn't lead to an access violation.

My guess is that your GetProcAddress call is failing. But that is a guess. I'd like to see more code and the full error message.

EDIT

It seems that we were on the right track. Cosmin's answer will solve the problem for you. An alternative would be to switch to inplicit linking by removing the definition of the condition SETUPAPI_LINKONREQUEST in SetupApi.pas.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文