Lots o' quick ATL COM/DCOM questions
-
I'm starting with ATL, I've written several 'test' COMs but now I face the following problems. I want to create a COM object (class) that will be used from remote machines (DCOM). The COM will be an out of process server. Let's say my object is named MyObj and the C++ class CMyObj. 1. How do I get the count of open objects? Should I use a static member variable and increase/descrease it everytime an object is constructed/destructed? If yes (or even if no), where should I put the code for this? In the constructor/destructor of CMyObj or in the FinalConstruct-FinalRelease? 2. How to I prevent a client to create an object of that class based on runtime conditions? For example, in order to disallow more than 10 objects at the same time. Should I throw in the constructor? throw what? 3. What's the best way to destroy my object, even if the client hasn't done so yet? 'delete this;'? For example, if the client passes an invalid parameter on one method, I would like to be able to destroy the object (at least on the srv-side). 4. What happens when (in DCOM) the network layer fails? Is the object on the server and/or client side automatically destroyed? If not, can I catch an event or something (I'm more concerned on the server side) when that happens and ... do what? 5. How can I pass my object (and all the data it holds) through the network? Are there any functions I would have to override (something like ReadFromStream or WriteToStream, I don't know)? 6. What's the best way to inform the client of critical failures of a method he just called? Should all these methods have an [out,retval] long *result? Should I use the IErrorSomething that the ATL object wizard allows you to support? Can I return anything else than S_OK, or is HRESULT used internally from the COM/DCOM layer? Any help would be greatly appreciated. Moreover, the one who answers all of my questions, will win a free copy of my free Tetris game;)
-
I'm starting with ATL, I've written several 'test' COMs but now I face the following problems. I want to create a COM object (class) that will be used from remote machines (DCOM). The COM will be an out of process server. Let's say my object is named MyObj and the C++ class CMyObj. 1. How do I get the count of open objects? Should I use a static member variable and increase/descrease it everytime an object is constructed/destructed? If yes (or even if no), where should I put the code for this? In the constructor/destructor of CMyObj or in the FinalConstruct-FinalRelease? 2. How to I prevent a client to create an object of that class based on runtime conditions? For example, in order to disallow more than 10 objects at the same time. Should I throw in the constructor? throw what? 3. What's the best way to destroy my object, even if the client hasn't done so yet? 'delete this;'? For example, if the client passes an invalid parameter on one method, I would like to be able to destroy the object (at least on the srv-side). 4. What happens when (in DCOM) the network layer fails? Is the object on the server and/or client side automatically destroyed? If not, can I catch an event or something (I'm more concerned on the server side) when that happens and ... do what? 5. How can I pass my object (and all the data it holds) through the network? Are there any functions I would have to override (something like ReadFromStream or WriteToStream, I don't know)? 6. What's the best way to inform the client of critical failures of a method he just called? Should all these methods have an [out,retval] long *result? Should I use the IErrorSomething that the ATL object wizard allows you to support? Can I return anything else than S_OK, or is HRESULT used internally from the COM/DCOM layer? Any help would be greatly appreciated. Moreover, the one who answers all of my questions, will win a free copy of my free Tetris game;)
I can't pass up the chance for a free tetris game. 1. Thats one way to do it. Put it where ever you would like. In the ctor you can catch it before creating the object. In the FinalConstruct you can be sure the object was successfully created. 2. Don't throw just return an E_FAIL or some HRESULT of your own creation, using the MAKE_HRESULT macro. You could then set the IErrorInfo for more detailed explaination of the failure. 3. Release the object. 4. Don't know (Damn, there goes the Tetris) 5. Pass an interface pointer. You don't want to pass a 500mb object instance down the wire. 6. You could have a retval or use HRESULTs and IErrorInfo, refer to 2.
-
I can't pass up the chance for a free tetris game. 1. Thats one way to do it. Put it where ever you would like. In the ctor you can catch it before creating the object. In the FinalConstruct you can be sure the object was successfully created. 2. Don't throw just return an E_FAIL or some HRESULT of your own creation, using the MAKE_HRESULT macro. You could then set the IErrorInfo for more detailed explaination of the failure. 3. Release the object. 4. Don't know (Damn, there goes the Tetris) 5. Pass an interface pointer. You don't want to pass a 500mb object instance down the wire. 6. You could have a retval or use HRESULTs and IErrorInfo, refer to 2.
Thanks a lot. I decided I'll give you a copy of Tetris, since you're so excited about it. :) Get it from users.otenet.gr/~gtoub/ Btw, it's for DOS (but works on 3.1,95,98,2000 *maybe, it worked for me*).