Creating COM using ATL in C++ from VS2012

2019-06-24 01:55发布

问题:

Trying to create simple COM library using ATL in Visual Studio 2012. I do:

 New ATL Project
 Welcome to the ATL Project Wizard
 Next
 Application Settings - no change (DLL)
 Next
 Finish

Got a lot of files:

Trying to understand where to add simple function that can be called by COM user. I found only one place where I can add function using wizard:

But I see that something is missing there regarding parameters selection like in,out,retval.

And I was hoping that after adding new function at least IDL file will be updated too, but this not happened.

What is the way of creating simple COM class using ATL from Visual C++ from VS2012 ?

回答1:

  1. Add a new class

  2. Fill in fields

After this step SomeObject.h, SomeObject.cpp files will be created and added to your solution, the ISomeObject interface declaration will be added to the .idl file.

  1. Go to Class View (the combination ctrl+shift+C by default), select ISomeObject, add a new method

  2. Fill in fields

After this step the someMethod will be added to .idl file, .h file and .cpp file. All you have to do - is to write an implementation of someMethod in .cpp file.