Re: Can COM class be used as Template Class
On Oct 15, 3:37 pm, Piaoger Gong <piao...@gmail.com> wrote:
[Snip non-compiling sample code]
It's always easier for people to help you if you post a compiling
sample that demonstrates what you are talking about.
The above code will get a link error for ComClass::DoSomething is
unresolved.
if I have ComClass::DoSomething called outside of template class. No
link error again.
Is there any method for this issue and I am thirsty for you solution.
I've seen this also, when using COM interfaces that were #imported
from a dll. I never got to the root cause, but it seems that MSVC (I
was using version 2003) wasn't pulling in the required function
definitions from the auto-generated tli file.
The workaround that I used at the time was to add a non-templated call
to the required function, which would pull in the function definition
for the linker to find. Something like:
namespace{
void DontCallThis(CComPtr<COMClass>& e){
e->Remove();
}
}
You don't have to ever call the DontCallThis function, it's only
purpose it to make the project link.
Another solution that seems to work is to use the "raw" function call,
like:
void DoSomething(int num, CComPtr<T> spiNode){
HRESULT hr = spiNode->raw_Remove();
}
If you look in the tli file, you'll see that the missing function is
just an error-checking wrapper around this one.
Since this is such a platform-specific problem, we should take any
further discussion to email or another forum.
Hope it helps,
Brian
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]