Can't get simple COM project to work: where and how to put implementation?

情到浓时终转凉″ 提交于 2019-12-11 15:13:57

问题


I am trying to follow the steps of a Simple COM Tutorial which looks nice and logical to me. I would normally shy away from using a wizard but consensus seems to be this is the best way to do COM.

To summarize

  1. Create an ATL project with the wizard
  2. Use the Add Class dialog to create an ATL simple object (SimpleChatServer in the example)
  3. Navigate into ClassView, right click the interface for the object, Add Method (CallMe in the example)
  4. The tutorial gives a method body to use
  5. Compile

My compilation, however, fails because

error C2509: 'CallMe' : member function not declared in 'CSimpleChatServer' 

Has something gone wrong with the wizard? I would have expected VS to automatically declare the CallMe method in CSimpleChatServer, and provide a method stub for me to add the implementation, which it didn't.

(Another difference from the tutorial is that the class browser doesn't show the class CSimpleChatServer, which you would think it would. Might this be because I have disabled intellisense? Hopefully a separate issue).

So, what to do, where and how do I define and declare the actual C++ method with the functionality?


回答1:


The ATL wizard usually does declare the method in the header (with STDMETHOD(BLah)(...)), provides a stub implementation (with STDMETHODIMP CFoo::Blah(...)) and adds the declaration to the IDL file.

However, I recall that when you modify manually the header file, it gets confused and only adds the declaration into the IDL, but not to the .h and .cpp file. If I were you, I'd do it again from scratch (and avoid COM unless you have a good reason not to).

When you'll get experience, you'll get rid of the wizard to generate methods (for classes, it is probably too complex however).




回答2:


So - it was to do with intellisense. I had disabled intellisense by renaming feacp.dll due to the need to compile boost::geometry as recommended in the boost docs. This caused the COM add class dialog to silently fail to add stub methods to my .h and .cpp file.

Giving C:\Program Files\Microsoft Visual Studio 9.0\VC\vcpackages\feacp.dll its original name back seems to fix this.



来源:https://stackoverflow.com/questions/8509157/cant-get-simple-com-project-to-work-where-and-how-to-put-implementation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!