0

I am writing a COM wrapper for a managed C++ class within a C++ project. After adding one ATL Simple Object to my ATL project I then enabled Common Language Runtime Support (/clr) in the project properties, as required. However I now find that I am unable to add further ATL objects to my project - if I right-click the project and select Add and New Item the ATL option has disappeared from the list of Installed Visual C++ templates in the left-hand pane of the Add New Item dialog.

Is this a bug, or is there some good reason for it?

I will try turning off CLR, adding the classes and then turning on CLR again, hopefully this will work, but it seems a bit odd.

Dave
  • 3,429
  • 2
  • 26
  • 29
  • I don't kow why this doesn't work. But I would probably create 2 projects anyway. One to create the COM server (dll or exe) this will be reusable (and seperatly testable). And then I would create a small managed wrapper dll using clr. – Pepijn Kramer Nov 02 '22 at 13:04
  • I probably wasn't clear - the COM wrapper is a separate project, referencing the project that contains the managed C++ class. The wrapper project still needs to have CLR support in order to access the managed class. – Dave Nov 02 '22 at 13:20
  • I also did read your question a bit backward, I read it as writing a managed wrapper for a COM project (but it is the other way around)... – Pepijn Kramer Nov 02 '22 at 13:26
  • JFI If I disable CLR support, add the new ATL Simple Objects and then reenable CLR it all seems to work. Interestingly I only have to disable CLR in one platform/configuration to do this. – Dave Nov 02 '22 at 13:29
  • I haven't done anything like this myself, but in C# you have attributes like ComVisible and something similar seems to exist for C++/cli (https://stackoverflow.com/questions/1256047/comvisible-in-c-cli) maybe you can try that instead of using ATL wrapper COM objects? – Pepijn Kramer Nov 02 '22 at 13:29
  • I can't reproduce (and BTW adding /clr is not enough to compile you need to enable/disable some other switches). Can you post the project somewhere on the internet? – Simon Mourier Nov 02 '22 at 18:16

1 Answers1

-1

I think I'll answer this question myself - the answer, or rather the workaround, seems to be to turn off CLR support, add the ATL class(es) and turn CLR on again. If anyone can comes up with a good reason why Microsoft may have done this deliberately, and/or why this workaround doesn't/shouldn't work, please comment, otherwise let's assume it's just a little buglet.

Dave
  • 3,429
  • 2
  • 26
  • 29