简体   繁体   English

从MFC调用ATL COM dll

[英]Calling ATL COM dll from MFC

I've written a com dll using VS2012. 我已经使用VS2012编写了一个com dll。 I got 2 projects - my DLL project and a PS Project. 我有2个项目-我的DLL项目和一个PS项目。 PS has 3 classes: myproj_i.h myProj_i.c myProj_p.c PS具有3个类:myproj_i.h myProj_i.c myProj_p.c

now I want to call the dll from another MFC project: 现在我想从另一个MFC项目中调用dll:

hr = CoCreateInstance( CLSID_MYTASK, NULL, CLSCTX_INPROC_SERVER, IID_IMYTASK, (void**) &pMYTASK );

I have included the myproj_i.h file - so I get all the symbols recognised, yet I can't link them, as I'm missing the _i.c file. 我已经包含了myproj_i.h文件-因此我可以识别所有符号,但是由于缺少_i.c文件,因此无法链接它们。

If I add them to the project I get planty of PCH errors. 如果将它们添加到项目中,则会出现PCH错误。

How should I Link my MFC project and call the DLL ? 我应该如何链接我的MFC项目并调用DLL?

I have also tried to use #import of the dll but then I get missing TLH error, and I haven't found that file in the DLL project. 我也尝试使用dll的#import,但是随后我丢失了TLH错误,并且我没有在DLL项目中找到该文件。

Including the myProjPS.lib did not solve it either... 包括myProjPS.lib也没有解决它...

MIDL-generated .c files do not use precompiled headers. MIDL生成的.c文件不使用预编译头。 If you link them into your program (I usually make static libs of them, but that's a different method), you need to turn OFF precompiled headers for those specific .c files. 如果将它们链接到程序中(我通常将它们制成静态库,但这是另一种方法),则需要为这些特定的.c文件关闭预编译的头文件。

  • Right-click the myProj_i.c file in the soluton explorer and bring up its properties. 在解决方案资源管理器中右键单击myProj_i.c文件,并显示其属性。
  • Select All Platforms/All configurations in the top two drop lists. 在顶部两个下拉列表中选择“所有平台/所有配置”。
  • Expand the C++ Settings in the left tree. 展开左侧树中的“ C ++设置”。
  • Select Precompiled Headers in the left tree 在左侧树中选择“预编译头”
  • Switch them OFF for that file. 为该文件将它们关闭。

That should allow it to compile and link successfully. 那应该允许它成功编译和链接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM