New to ATL... (simple question)
-
Hi, I'm kinda new to ATL and as such I'm after a little guidance :) Say i want to be able to get Cheeseburger objects from Maccas. ie. A client would have to create a Maccas and then ask it for a Cheeseburger. I can create the Maccas class using the ATL create object wizard, but i am unsure how i should create the stub code for the Cheeseburger object. Do i use the object wizard again? Would this not unnecessarily create a CoClass for the object and make it seperately instantiable (you don't have to get Cheeseburgers from Maccas anymore). How else do i do it? In case it is important its desireable to support c++ and VB automation clients (scripted from office macros). Thanks a bunch! Alex
-
Hi, I'm kinda new to ATL and as such I'm after a little guidance :) Say i want to be able to get Cheeseburger objects from Maccas. ie. A client would have to create a Maccas and then ask it for a Cheeseburger. I can create the Maccas class using the ATL create object wizard, but i am unsure how i should create the stub code for the Cheeseburger object. Do i use the object wizard again? Would this not unnecessarily create a CoClass for the object and make it seperately instantiable (you don't have to get Cheeseburgers from Maccas anymore). How else do i do it? In case it is important its desireable to support c++ and VB automation clients (scripted from office macros). Thanks a bunch! Alex
What I usually do is let ATL create it through the class wizard, then remove the stuff that I do not need. So as you said, you do not want to create it using the CoClass object. Therefore remove the derivation from CComCoClass in your Cheesburger class. You will also need to go to the main cpp file of your project where the DLL entry point is located and remove the Cheeseburger entry from the BEGIN_OBJECT_MAP map. This map tells the DLL which objects can be instantiated through CoCreateInstance. That is all that you will need to do in order to prevent the object from being instantiated outside of your DLL. Then when you want to instantiate your class from the Maccas object, you will not be able to use
new Cheeseburger
because your class is still an abstract base class. You will actually need to do something like this:CCheeseburger *pCheeseBurger = CComObject<CCheeseburger>
Good Luck
Build a man a fire, and he will be warm for a day
Light a man on fire, and he will be warm for the rest of his life! -
What I usually do is let ATL create it through the class wizard, then remove the stuff that I do not need. So as you said, you do not want to create it using the CoClass object. Therefore remove the derivation from CComCoClass in your Cheesburger class. You will also need to go to the main cpp file of your project where the DLL entry point is located and remove the Cheeseburger entry from the BEGIN_OBJECT_MAP map. This map tells the DLL which objects can be instantiated through CoCreateInstance. That is all that you will need to do in order to prevent the object from being instantiated outside of your DLL. Then when you want to instantiate your class from the Maccas object, you will not be able to use
new Cheeseburger
because your class is still an abstract base class. You will actually need to do something like this:CCheeseburger *pCheeseBurger = CComObject<CCheeseburger>
Good Luck
Build a man a fire, and he will be warm for a day
Light a man on fire, and he will be warm for the rest of his life!