|
|
Hi All,
I want to return a Class pointer from ATL Dll.Currently I am trying method using IDispatch * but giving problem, return pointer is invalid . Please give me a solution for this.
Thanks in Advance.
The secret of life is not enjoyment
but education through experience.
- Swami Vivekananda.
-- modified at 8:30 Monday 24th July, 2006
|
|
|
|
|
You don't return class pointers in COM: It violates the whole concept of COM. COM components are meant to be (programming) language neutral so you can't be returning classes from COM objects: What good is a C++ class to VB, for example? Can you be more specific with what (exactly) you're trying to achieve?
|
|
|
|
|
Thanks For the Reply.
Details : I have used one class in COM Interface. This class gets manipulated in the com method. Further I need the class pointer so that I can access the values of that class which are modified by the COM. I want the pointer in the function from where I invoked the COM method.
The secret of life is not enjoyment
but education through experience.
- Swami Vivekananda.
|
|
|
|
|
Is there anything preventing you from creating and exposing another COM Interface that returns the values you are interested in?
|
|
|
|
|
|
No you don't. A COM interface should provide all the functionality, which may well include accessors for properties.
If you start handing out raw C++ class pointers, it is no longer COM, no longer marshallable, remotable, or usable by anything other than a VC++ client, and possibly not even that if you later switch to a different version of VC++.
An interface is not a class. A class may implement one or more interfaces (typically IUnknown, sometimes IDispatch, and one or more interfaces derived from them), but an interface is not a pointer to an object, nor should it be treated as one. This means no access via an interface to member data, and no casting the interface to something else directly.
You need to read (or re-read) Don Box's "Essential COM", plus there is an MSDN article which essentially describes the process of going from a C++ class to COM interfaces in design terms (here[^])
Steve S
Developer for hire
|
|
|
|
|
Hi All,
I am writing a one component in which, I have to register the callback method in the component when client Advise for connection. How should i do this?
Thanks in Advance.
Amar.
|
|
|
|
|
Check out the documentation for IConnectionPointImpl and IConnectionPointContainerImpl.
Your component needs to implement IConnectionPoint, and the Advise method will typically store the provided sink in some container (like an array, or a map, or a list...)
When something happens in the component that triggers an event (such as changing a property, or a timer firing, or...) the component iterates through all the entries in that container, and calls the appropriate method(s) passing any parameters as required.
Steve S
Developer for hire
|
|
|
|
|
there is an m_vec member which contains a list of clients which the sinked the event.
Sudeesh
|
|
|
|
|
Dear Gurus,
You may not be aware that I have lost my job as our company has given us lay off.
I am really expecting a job in MFC, VC++.
I have given 2-3 technical interviews but it has made clear that interviews need special attention and preparation ,
I would be highly thankful , if someone provides me the compilation of interview questions on VC++, MFC, C++, ATL COM, Threading. If with answers then it will be a faster preparation for me. (Sorry being lazy here, but situation is a bit tedious with me right now).
ANy links also will help a lot.
If you want to send me few things, then email address is
rpathak03011978@yahoo.com
Looking forward some help from Codeproject.
Thanks ,
pathak
|
|
|
|
|
template<class TYPE, class ARG_TYPE>
class CBanana : public CObject
{
protected:
struct CApple
{
int x;
int y;
};
int GetInt(int);
CApple* GetApple(CApple*);
};
template<class TYPE, class ARG_TYPE>
int CBanana<TYPE, ARG_TYPE>::GetInt(int i)
{
return i;
}
template<class TYPE, class ARG_TYPE>
CBanana<TYPE, ARG_TYPE>::CApple*
CBanana<TYPE, ARG_TYPE>::GetApple(CBanana::CApple* pApple)
{
return pApple;
}
|
|
|
|
|
You don't use the template parameters anywhere....What's the point of using templates? There are times when this is done intentionally but this doesn’t like any case I’ve seen.
Steve
|
|
|
|
|
I was trying to illustrate the compile error as simply as possible. This is not the actual code.
|
|
|
|
|
Try this:
template<typename TYPE, typename ARG_TYPE>
typename CBanana<TYPE, ARG_TYPE>::CApple*
CBanana<TYPE, ARG_TYPE>::GetApple(typename CBananaa<TYPE, ARG_TYPE>::CApple* pApple)
{
return pApple;
}</code>
I believe you need the underlinded typename s in standard C++ but some non-standard complient compilers may not like them.
Steve
|
|
|
|
|
That works thanks. I'm still a bit concerned that this will come back
and bite me. The typename is used to resolve ambiguity but I don't see
any ambiguity and afxtempl.h manages without it. Is there something
more fundamentally wrong ?
Nvat.
|
|
|
|
|
You need to add the extra typename when you refer to a nested type of a class that is dependant on a template parameter in a template. It tells the compiler it's a type and in this case to interpret the "*" as a pointer not multiplication.
e.g.
template<typename TYPE, typename ARG_TYPE>
typename CBanana<TYPE, ARG_TYPE>::CApple*
\-----------\/------------/ \-\/-/
2. Is nested in this class 1. This nested type
which is dependant on the
template parameters 'TYPE'
and 'ARG_TYPE'.
CBanana<TYPE, ARG_TYPE>::GetApple(typename CBananaa<TYPE, ARG_TYPE>::CApple* pApple)
{
return pApple;
}
The same goes for the other use of typename. The reason you need to do this is quite involved but actually quite reasonable once you understand it.
Steve
|
|
|
|
|
typename and class are interchangible when dealing with templates. That is, in that case, they mean the exact same thing.
Hmm, hit pre and it posted it. Anyway, the following should work (don't have Visual Studio on this box, so I can't test it to be sure):
template<class TYPE, class ARG_TYPE>
class CBanana : public CObject
{
protected:
struct CApple
{
int x;
int y;
};
int GetInt(int);
CApple* GetApple(CApple*);
};
template<class TYPE, class ARG_TYPE>
int CBanana<TYPE, ARG_TYPE>::GetInt(int i)
{
return i;
}
template<class TYPE, class ARG_TYPE>
CBanana<TYPE, ARG_TYPE>::CApple*
CBanana<TYPE, ARG_TYPE>::GetApple(CBanana<TYPE, ARG_TYPE>::CApple* pApple)
{
return pApple;
}
You shouldn't need the typename specifier in the method signature (though, it won't necessarily hurt it, it can make the code a bit less readable).
-- modified at 12:12 Tuesday 25th July, 2006
|
|
|
|
|
Zac Howland wrote: You shouldn't need the typename specifier in the method signature
This is not the case. As I explained in a previous post you need to add a typename in a template if you refer to a type which is nested in another type which is dependant on a template parameter. In this context you can NOT use class . See here[^] for Microsoft's explaination.
|
|
|
|
|
I stand corrected. After looking at a few of the documents, I think I never ran into this issue because I almost always typedef in those situations.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
No that didn't work either, but I'm sure a bright bunch like yourselves
can fill in the missing angle brackets and formatting.
Sorry,
Nvat.
|
|
|
|
|
instead of reposting again and again... edit (use the [Modify] link at the bottom of your thread) and check the "Ignore HTML tags in this message (good for code snippets)" checkbox below the emoticons...
|
|
|
|
|
My previous copy / paste from Visual Studio didn't
work properly. Should have been :
template<class type,="" class="" arg_type="">
class CBanana : public CObject
{
protected:
struct CApple
{
int x;
int y;
};
int GetInt(int);
CApple* GetApple(CApple*);
};
template<class type,="" class="" arg_type="">
int CBanana<type, arg_type="">::GetInt(int i)
{
return i;
}
template<class type,="" class="" arg_type="">
CBanana<type, arg_type="">::CApple*
CBanana<type, arg_type="">::GetApple(CBanana::CApple* pApple)
{
return pApple;
}
Nvat
|
|
|
|
|
use check box 'ignore HTML Tags..." (present below) while posting code. modify your post by checking the option. That will make full code available for reading
|
|
|
|
|
Hi,
when I try to compile the following code
template<class type,="" class="" arg_type="">
class CBanana : public CObject
{
protected:
struct CApple
{
int x;
int y;
};
int GetInt(int);
CApple* GetApple(CApple*);
};
template<class type,="" class="" arg_type="">
int CBanana<type, arg_type="">::GetInt(int i)
{
return i;
}
template<class type,="" class="" arg_type="">
CBanana<type, arg_type="">::CApple*
CBanana<type, arg_type="">::GetApple(CBanana::CApple* pApple)
{
return pApple;
}
which is based on code found in the MFC afxtempl header, I get a compile
error on the line CBanana<type, arg_type="">::CApple*
syntax error : missing ';' before '*'
if I replace the above return type with an int it then complains
instead about the parameter CBanana::CApple* pApple
'pApple' : undeclared identifier
it doesn't like my CApple !
Any ideas why ?
Nvat.
|
|
|
|