使用 C++ 在 QT 中加载 COM DLL(无头文件)?
我刚开始使用QT。现在我需要将 Visual C++ 项目上的一些代码转移到 QT。
目前该项目唯一要做的就是打开 Photoshop 并将可见标志设置为 false(它将用于自动化,因此稍后会添加很多东西)。
我所做的是,导入 2 个 Photoshop dll(注意:我没有它们的 .h 或 .lib,只有 .dll 文件) 我用来导入这些 dll 的方法是通过 import libid,因为我尝试过的所有其他方法都不起作用。顺便说一句,它们是 COM 对象。
这是我的 VC++ 代码:
//library ID of Photoshop.dll
#import "libid:E891EE9A-D0AE-4cb4-8871-F92C0109F18E"
//library ID of PhotoshopTypeLibrary.dll
#import "libid:4B0AB3E1-80F1-11CF-86B4-444553540000"
int main()
{
Photoshop::_ApplicationPtr app( __uuidof(Photoshop::Application));
app->Visible = false;
return 0;
}
现在,我使用带有 MinGW 的 QT Creator 来编译此代码,它在导入行上给了我一些警告和错误:
warning: #import is a deprecated GCC extension
error: libid:E891EE9A-D0AE-4cb4-8871-F92C0109F18E: No such file or directory
然后,在那之后,它(显然)说“Photoshop”没有声明。
现在,我进行了搜索,找到的最接近的解决方案是包含在我的 VC++ 项目上创建的 .tlh 文件,但是当我这样做时,我收到了超过 1000 个错误和警告,因此这显然不起作用。
有人可以告诉我在这里做什么吗?我严重卡住了!
I just started using QT. Right now I need to transfer some code I have on a Visual C++ project to QT.
The only thing the project does at the moment is open photoshop and set the visible flag to false (it will be used for automation, so a lot of things will be added later).
What I do is, I import 2 photoshop dlls (NOTE: I don't have .h or .lib for them, just the .dll files)
The method I'm using to import these dlls is through import libid, since all the other methods I tried didn't work. They are COM objects, btw.
This is my VC++ code:
//library ID of Photoshop.dll
#import "libid:E891EE9A-D0AE-4cb4-8871-F92C0109F18E"
//library ID of PhotoshopTypeLibrary.dll
#import "libid:4B0AB3E1-80F1-11CF-86B4-444553540000"
int main()
{
Photoshop::_ApplicationPtr app( __uuidof(Photoshop::Application));
app->Visible = false;
return 0;
}
Now, I'm using the QT Creator with MinGW to compile this code, and it gives me some warnings and errors on the import lines:
warning: #import is a deprecated GCC extension
error: libid:E891EE9A-D0AE-4cb4-8871-F92C0109F18E: No such file or directory
And then, after that, it says (obviously) that "Photoshop" is not declared.
Now, I searched and the closest solution I found was to include the .tlh files that were created on my VC++ project, but when I did that, I got more than 1 thousand errors and warnings, so that obviously didn't work.
Can someone please tell me what to do here? I'm seriously stuck!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
#import
是一个 Microsoft 扩展,可用于在 VisualC++ 中导入 COM 库。从你的问题来看,你似乎可以访问 VisualC++,但你的 QT 代码是用 gcc 编译的。
如果您在 VisualC++ 中创建一个简单的项目,您可以添加 #import 代码并编译它。
你会发现编译器生成了.tlh和.tli文件。
这些文件包含使用 COM 库所需的所有信息,并且可供任何编译器使用。
然后,您可以将这些文件复制到 gcc 项目目录,并对这些生成的文件使用 #include (而不是 #import)。
.tlh 相当于 C++ 标头,.tli 更像是 .cpp 文件。
#import
is a Microsoft extension that you can use to import COM libraries in VisualC++.From your question it looks as if you have access to VisualC++ but that your QT code is compiled with gcc.
If you create a simple project in VisualC++ you can add the #import code and compile it.
You will find that the compiler has generated a .tlh and .tli file.
These files contain all the information that you need to use the COM library and can be used by any compiler.
You can then copy these files to your gcc project directory and use #include (not #import) on these generated files.
The .tlh is equaivalent of a c++ header, the .tli is more like a .cpp file.