|
From: roozbeh on 10 Apr 2008 04:45 Hi, i am not that good at c++ interfaces and classes,so... Here is my situation: for some apis windows wants me to give him a pointer to an interface. (ie implement him an interface) i have another dll that implements this interface and i can get it via a function. is it possible that i use that interface and reimplement one of its functions and send back my new interface to windows?so i can benefit from what has already implemented in that dll and also use my own? I somehow managed to do this,but maybe because i dont know the proper way when freeing interfaces i get errors. (i simply call other interface functions in my interface) For uknown reason the interface refcount i get for the first time from dll is 6. should i also call addref,queary and release of main interface when i do it for myself? thanks
From: SvenC on 10 Apr 2008 05:02 Hi roozbeh, > Here is my situation: > for some apis windows wants me to give him a pointer to an interface. > (ie implement him an interface) > i have another dll that implements this interface and i can get it via > a function. > ... > I somehow managed to do this,but maybe because i dont know the proper > way when freeing interfaces i get errors. > (i simply call other interface functions in my interface) > For uknown reason the interface refcount i get for the first time from > dll is 6. > should i also call addref,queary and release of main interface when i > do it for myself? Do not count on the return value of Addref/Release to assume when you have to call AddRef/Release. Just follow the rules: when you create a COM object you get an interface which is already addreffed for you, so you must call Release once when you are finished. For any additional QueryInterface or AddRef call you will need to call an additional Release. So in your case: create the helper object which implements the interface once in your object and when release it when your object is released. If that dll is really giving you a special function to get an interface pointer then you might get an interface pointer to an already created object which is referenced by multiple users. So that might be the reason why you get a ref count of 6. More important: is anything not working as you expect? -- SvenC
From: Alexander Nickolov on 11 Apr 2008 14:30 In COM this is called containment/delegation and it's certainly possible. You implement all methods of the interface in question on your object and for those you are not interested in you simply delegate the calls to another object, while the ones you are interested in you hanlde yourself and then possibly delegate if appropriate. It begs the question, however, do you really need to delegate to another object? For example for COM events it makes no sense - simply do nothing for the events you don't care about (e.g. return S_OK without any processing). -- ===================================== Alexander Nickolov Microsoft MVP [VC], MCSD email: agnickolov(a)mvps.org MVP VC FAQ: http://vcfaq.mvps.org ===================================== "roozbeh" <roozbehid(a)gmail.com> wrote in message news:0bb343e6-9717-455e-a667-a0e4306d4efd(a)2g2000hsn.googlegroups.com... > Hi, > > i am not that good at c++ interfaces and classes,so... > > Here is my situation: > for some apis windows wants me to give him a pointer to an interface. > (ie implement him an interface) > i have another dll that implements this interface and i can get it via > a function. > is it possible that i use that interface and reimplement one of its > functions and send back my new interface to windows?so i can benefit > from what has already implemented in that dll and also use my own? > > I somehow managed to do this,but maybe because i dont know the proper > way when freeing interfaces i get errors. > (i simply call other interface functions in my interface) > For uknown reason the interface refcount i get for the first time from > dll is 6. > should i also call addref,queary and release of main interface when i > do it for myself? > > thanks
|
Pages: 1 Prev: search engine optimization (SEO) Next: Standard C Library and utf-8 |