4

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

enter image description here

Got a lot of files:

enter image description here

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:

enter image description here

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

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 ?

2
  • Write the IDL by hand and then update the classes to match. Commented Oct 19, 2015 at 9:40
  • 1
    COM methods are exposed via interfaces, which are implemented by objects. You need to add object first (Add ATL Simple Object) using similar wizard). Then you add methods to interface, which will be created for you. Commented Oct 19, 2015 at 10:00

1 Answer 1

4
  1. Add a new class enter image description here

  2. Fill in fields enter image description here enter image description here

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 enter image description here

  2. Fill in fields enter image description here

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.

Sign up to request clarification or add additional context in comments.

4 Comments

I have created dll using your recomendation and have registered wit regsvr32 in 32bit WinXP OS, but I can't find its registration info. I use PowerShell script from powershellmagazine.com/2013/06/27/…
It is in the HKEY_CLASSES_ROOT\ATLProject1.SomeProject.1 key. The PS1 script is incorrect. It should match ^\w+\.\w+(?:$|.\d+).
Fine, I have ATLProject1.SomeProject.1. I suppose ATLProject1.SomeProject is what we have entered in ProgID, but what 1 at the end means?
It means the version of COM object. ATLProject1.SomeProject\CurVer = ATLProject1.SomeProject.1, ATLProject1.SomeProject.1\CLSID = {GUID}. So can create the object like var o = new ActiveXObject('ATLProject1.SomeProject'); in a script and you've got the actual (current) version of your COM object.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.