CoCreateInstance 失败

发布于 2024-11-19 14:42:37 字数 124 浏览 2 评论 0原文

我有一个调用 CoCreateInstance 的函数。该函数被调用多次并且它可以工作,但是有一次 CoCreateInstance 失败并出现“错误的变量类型”错误。问题是无论成功还是失败,参数总是相同的。什么可能导致这种情况发生?

I have a function where I am calling CoCreateInstance. This function is called multiple times and it works, however one time the CoCreateInstance fails with the "Bad variable type" error. The thing is the parameters are always the same both when it succedes and when it fails. What could cause this to happen?

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

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

发布评论

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

评论(2

孤独陪着我 2024-11-26 14:42:37

我的代码中还有一个函数调用 CoCreateInstance(...)。有时它有效,有时则无效,而无需更改代码。
但是当查看返回的 HRESULT 时,结果是内存不足错误,“E_OUTOFMEMORY 内存不足”。我确实做了一些有关该主题的研究,发现发生这种情况的原因如下。

  1. 必须首先调用 CoInitialize()

必须在调用 CoCreateInstance 函数之前调用 CoInitialize 函数

  1. COM 对象注册不正确

当 COM 对象(或代理存根)未正确注册时,通常会发生这种情况。您可以使用 Oleview 工具通过尝试实例化对象来检查 COM 对象的注册情况。

Oleview.exe 包含在 Windows SDK 中,位置通常位于 C:\Program Files\Microsoft SDKs\Windows\v6.0\Bin。

如果不存在,您可以尝试安装适用于 Windows Server 2008 的 Microsoft Windows SDK:http://www.microsoft.com/downloads/details.aspx?FamilyId=F26B1AA4-741A-433A-9BE5-FA919850BDBF&displaylang=en

注意:它不仅适用于Windows 2008,它只是以最新的Windows版本命名,并且支持Windows Server 2003; Windows Server 2008; Windows Vista; Windows XP。

  1. DLL 版本丢失、损坏

对我来说,这种情况发生在不同的项目配置中,在调试模式下我捕获了异常,但在发布中它没有出现。

I also had a function in my code calling CoCreateInstance(...). When one time it worked and another time it did not, without changing the code.
But when looking at the HRESULT which was returned, the result was an Out of Memeory Error, "E_OUTOFMEMORY Ran out of memory." I did do some research regarding the subjects and found the following reasons that this can occur.

  1. You must first call the CoInitialize()

The CoInitialize function must be called prior to calling the CoCreateInstance function

  1. Incorrect COM object registration

This can often occurred when the COM object (or the proxy-stub) wasn't registered properly. You can check the registration of the COM object using the Oleview tool by trying to instantiate the object.

The Oleview.exe is included in Windows SDK, the location is typically at C:\Program Files\Microsoft SDKs\Windows\v6.0\Bin.

If it is not there you can try installing Microsoft Windows SDK for Windows Server 2008: http://www.microsoft.com/downloads/details.aspx?FamilyId=F26B1AA4-741A-433A-9BE5-FA919850BDBF&displaylang=en.

Note: it is not only for Windows 2008, it is just named after the recent Windows version and it supports Windows Server 2003; Windows Server 2008; Windows Vista; Windows XP.

  1. Missing, corrupt of incorrect versions of DLLs

For me, this was happening in different projects configuration, in Debug mode I caught the exception but in Release it did not appear.

相守太难 2024-11-26 14:42:37

我修好了这个。
该调用是从不同的线程进行的。当调用成功时,是从主线程调用的。失败时,源是另一个线程,并且不会事先调用 CoInitialize()。
调用CoInitialize解决了这个问题。

I fixed this.
The call was made from different threads. When the call succeded, it was called from the main thread. On fail, a different thread was the source and CoInitialize() wasn't called beforehand.
Calling CoInitialize solved the problem.

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