#import ADOX 与使用 ADO 的托管 dll 发生冲突
我有一个旧版 C++ 应用程序,使用 /clr 调用托管 dll(用 C# 编写)。
该应用程序使用 #import
引用 ADOX。该 dll 还引用 ADOX。
一切都很好,直到我将 dll 的引用添加到 C++ 项目中。然后,在编译与 msadox.tli
和 msadox.tlh
相关的 STDAFX.CPP
时,我遇到了数百个错误。一些错误涉及接口重新定义等,其他错误则涉及尝试编译 tlh 和 tli,就好像它们是托管代码一样。
我已经在 #import
周围尝试了 #pragma Managed(off)
但没有成功。
如果相关,#import
使用 libid:...
方法。
我不明白这种冲突是如何发生的以及我能做些什么来克服它。请帮忙!
I have a legacy C++ application using /clr calling a managed dll (written in C#)
The app uses #import
to reference ADOX. The dll also references ADOX.
Everything is fine until I add a reference to my dll to the C++ project. Then I get hundreds of errors when compiling STDAFX.CPP
related to msadox.tli
and msadox.tlh
. Some of the errors refer to interface redefinition and suchlike, others to trying to compile the tlh and tli as if they were managed code.
I've tried #pragma managed(off)
around the #import
without success.
In case it's relevant the #import
uses the libid:...
method.
I don't understand how this conflict occurs and what I can do to overcome it. Please help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我通过从 C++ 项目引用中删除 dll 引用并在单个 cpp 文件(唯一引用该 dll 的文件)中使用
#using "my_management.dll"
解决了这个问题。然后编译器警告我,它无法从 dll 导入一些 ADOX 符号,因为它们已经被定义(由
#import ...
),但因为它们只是警告,我可以使用 < code>#pragma 将其关闭并忽略它们。现在一切正常了!
I got round the problem by removing the dll reference from the C++ project references and using
#using "my_managed.dll"
in a single cpp file (the only one that refers to the dll).Then the compiler warned me that it was unable to import some ADOX symbols from the dll because they had already been defined (by the
#import ...
) but because they were only warnings I could use a#pragma
to turn them off and ignore them.Now everything works!