1

This question is about using Visual Studio 2019 for building an out-of-process COM server using ATL. (I have done this before in Borland but this is my first time using MSVC).

I created a project called MyObjectsProject with ATL Project wizard. This created the module class CMyObjectsProjectModule : public ATL::CAtlExeModuleT<CMyObjectsProjectModule> in file MyObjectsProject.cpp .

Then I added a simple object MyObject via "Add > ATL Simple Object" as described in the documentation . This created files MyObject.cpp and MyObject.h containing an interface IMyObject and CoClass CMyObject. So far so good.

I go to IMyObject in the Class View, and right-click "Add > Method" and give it some details, then it adds the method declaration to CMyObject in MyObject.h and an empty definition to MyObject.cpp as CMyObject::method_name() . So far, so good (again).

However at the same time, it added the method declaration and definition to MyObjectsProject.cpp as a class member of CMyObjectsProjectModule. Furthermore:

  • The CMyObjectsProjectModule::method_name() version is never called -- when I use the COM server via a client, and call IMyObject::method_name() on an instance of MyObject, it executes the version defined as CMyObject::method_name() as expected.
  • I can delete the method declaration and definition from CMyObjectsProjectModule and there are no errors.

The same thing happens if adding a Property. Also, the "Completing operation..." takes about 45-50 seconds to run.


My question is: What is the reason behind the method being added to the Module as well as to the CoClass , and when would that version of the Method be called? (Or is this just a bug and it is not supposed to be added to the module at all?)

In the Borland IDE , the similar function wouldn't add methods to the Module.


EDIT: Originally posted the question with the project called MyProject , however the problem only occurs when the project is called MyObjectsProject . I used different names in the question originally from what I observed the problem with, but have now edited the question and reproduced using the exact names in the question.

M.M
  • 138,810
  • 21
  • 208
  • 365
  • I don't reproduce on my 2019 16.9.2 (and never seen that before), and of course that shouldn't happen, nothing should be added to the module. I only get a method_name on MyObject.idl, MyObject.cpp, MyObject.h – Simon Mourier Mar 30 '21 at 06:36
  • Was the project originally created in VS 2019, and which build? The ATL wizards were broken in VS 2017 at some point, and underwent several rounds of fixes that spilled into early VS 2019 versions. – dxiv Mar 30 '21 at 16:02
  • @dxiv yes, fresh project (I started a new project to reproduce). VS Professional 2019 ver 16.9.2 – M.M Mar 30 '21 at 19:55
  • Another slightly odd thing; in the Class View, `IMyOjbect` shows up three times. Twice with the interface icon and once with the line and two dots icon. Using "Go to Definition" on each: one goes to the `.idl` file, and two go to the `MyObject_i.h` file. I've been doing "Add > Add Method" on the former. After filling in the dialog, a "Completing operation..." pops up , which takes about 50 seconds to apply, and the machine is not otherwise slow – M.M Mar 30 '21 at 20:07
  • @M.M I cannot duplicate it with 16.9.2, neither the extra module method, nor the repeated interface. Something must be different with your configuration, though not sure where/what to look for. – dxiv Mar 30 '21 at 23:54
  • @dxiv regarding the repeated interface - it appears if you Build the project, then close and reopen the Solution, at which point it notices the `_i` and `_c` files that were generated by the Build, and includes their contents in the Class View, leading to the two copies of everything – M.M Mar 31 '21 at 02:01
  • 1
    @dxiv Edited question now -- if you take your existing attempt to reproduce, and in the Class View. rightclick CMyProjectModule and "Rename" it to CMyObjectsProjectModule then the problem should occur – M.M Mar 31 '21 at 02:44
  • Have posted answer as Community Wiki, feel free to edit – M.M Mar 31 '21 at 02:53

1 Answers1

1

The method is not supposed to be added to the Module, and it is not supposed to take 45-50 seconds to add the method.

The problem seems to occur whenever the CoClass name is an initial substring of the Module name.

For example it occurs for CMyObject with module CMyObjectsProjectModule, but does not occur for CMyObject with a module of CMyProjectModule.

When the problem is occurring, the Class View for CMyObject > Derived Types > shows derived types CMyObject and CMyObjectsProjectModule.

I guess it is "deducing" a derived type relationship between two types where one is an initial substring of the other; and furthermore, that the behaviour of the "Add Method" decides to add the method to everything that it thinks is a derived type of the CoClass having the method added to.


Conclusion: This seems to be a bug (or at least, questionable design) in the IDE; and to work around it, you can rename the Module to begin with some unique substring such that none of the CoClasses will coincide with initial substrings of the Module.

The Class Designer tool does not show the two types as derived (i.e. that tool doesn't appear to use the same heuristic as the Class View window does for deciding if one type is derived from another)

M.M
  • 138,810
  • 21
  • 208
  • 365
  • 1
    (+1) You may want to file a formal bug report on [feedback](https://developercommunity.visualstudio.com/search?space=62) and call it [The big ATL wizard misery](https://developercommunity.visualstudio.com/t/the-big-atl-wizard-misery/289506) season 2 ;-) FWIW the substring bug doesn't even stop at the first match. If you add another simple object `MyObj` and add a method `alt_method()` to it, VC++ will freeze for a few good minutes, then once it comes back to life the new method shows up in all of `CMyObj`, `CMyObject` (though not in the IDL for IMyObject) and `CMyObjectsProjectModule`. – dxiv Mar 31 '21 at 03:31