|
Perhaps I should description how i had realized the methods:
//Methods of IHeader
STDMETHODIMP CHeader::get_ID(long *ID)
{
// TODO: Add your implementation code here
*ID=m_ID;
return S_OK;
}
STDMETHODIMP CHeader::put_ID(long ID)
{
// TODO: Add your implementation code here
m_ID=ID;
return S_OK;
}
//Methods of IMotoCar
STDMETHODIMP CMotoCar::get_Header(IHeader **Header)
{
// TODO: Add your implementation code here
*Header=m_pBoundRect;
(*Header)->AddRef();
return S_OK;
}
STDMETHODIMP CMotoCar::put_Header(IHeader *Header)
{
// TODO: Add your implementation code here
m_pHeader=Header;
m_pHeader->AddRef();
return S_OK;
}
when Traced into put method: m_ID=10
when trace into get method :m_ID=0
|
|
|
|
|
Bob Davis wrote:
STDMETHODIMP CMotoCar::get_Header(IHeader **Header)
{
*Header=m_pBoundRect;
(*Header)->AddRef();
return S_OK;
}
STDMETHODIMP CMotoCar::put_Header(IHeader *Header)
{
m_pHeader=Header;
m_pHeader->AddRef();
return S_OK;
}
I think your problem is in get_Header(). In set_Header() you let m_pHeader take a reference, but your get_Header-method returns a reference to a m_pBoundRect object?? It's clearly not symmetric...
Also, you should check m_pHeader in set_Header to see if it already references an object. If it does, it should Release() before you let it refer to another pointer. Can you spell resource leaks?
--
standing so tall, the ground behind
no trespassers, on every floor
a garden swing, and another door
she makes it clear, that everything is hers
A place of abode, not far from here, Ms. Van de Veer
|
|
|
|
|
I'm a newer in Com/ATL.
I have an interface named "IMotoCar",it has a method
GetHeader(/*[out,retval]IHeader **Header).
In this method ,I want to return another interface nameed
"IHeader",b ut how to realize it?
|
|
|
|
|
I believe you can return an IDispatch *, which you'll then have to upcast again at the other end.
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002
|
|
|
|
|
You do like:
STDMETHODIMP CMotoCar::GetHeader( IHeader** pHeader)
{
*pHeader = m_pHeader;
if(*pHeader)
(*pHeader)->AddRef();
return S_OK;
}
May I advise you to pick up a book on COM?
--
standing so tall, the ground behind
no trespassers, on every floor
a garden swing, and another door
she makes it clear, that everything is hers
A place of abode, not far from here, Ms. Van de Veer
|
|
|
|
|
Why do you call addref?
If a scripting client like VB calls this function, it also calls addref itself.
- Anders
Money talks, but all mine ever says is "Goodbye!"
|
|
|
|
|
I've always followed the rules found in http://msdn.microsoft.com/library/default.asp?url=/library/en-us/com/com_1vxv.asp[^] for out parameters:
Retrieving a copy of an internally stored pointer When a function retrieves a copy of a pointer that is stored internally by the object called, that object's code must call AddRef on the pointer before the function returns. Once the pointer has been retrieved, the originating object has no other way of determining how its lifetime relates to that of the internally stored copy of the pointer.
And:
Out parameters from functions, including return values To set the out parameter, the function must have a stable copy of the interface pointer. On return, the caller is responsible for releasing the pointer. Therefore, the out parameter does not need a separate reference count.
This means that:
- If you are returning a value by reference - AddRef() is required
- If you are returning a value by value - AddRef() should NOT be called
In this case, he was returning a value by reference, thus the AddRef() was required.
--
standing so tall, the ground behind
no trespassers, on every floor
a garden swing, and another door
she makes it clear, that everything is hers
A place of abode, not far from here, Ms. Van de Veer
|
|
|
|
|
Sorry, you are right, I should not try to be smart that late at night
Usually I do it this way:
STDMETHODIMP CClient::get_Devices(IDevices **pVal)
{
HRESULT hr = m_Devices->QueryInterface(__uuidof(IDevices), (void**)pVal);
if (FAILED(hr))
{
return E_FAIL;
}
return S_OK;
}
- Anders
Money talks, but all mine ever says is "Goodbye!"
|
|
|
|
|
<pre>Under VC++ 6.0, I have some code like this:
typedef struct __Item
{
int m_iXX1;
int m_iXX2;
list<struct __Item> m_Right;// error C2143: syntax error : missing ';' before '<'
}_Item;
class CItemSet
{
vector<list<_Item>> m_ItemSet[10]; ;// error C2143: syntax error : missing ';' before '<'
}; </pre>
Why???
|
|
|
|
|
Simple - >> is a shift operator, you need to put a space between them.
BTW, you lost your <> symbols.
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. - Alex E. - 12-Sept-2002
|
|
|
|
|
Can you show me a complete code sample with these code?
|
|
|
|
|
You just need to add a space
typedef struct __Item
{
int m_iXX1;
int m_iXX2;
list<__Item> m_Right;// error C2143: syntax error : missing ';' before '<'
}_Item;
class CItemSet
{
vector<list<_Item> > m_ItemSet[10]; ;// error C2143: syntax error : missing ';' before '<'
};
oh, and get rid of the struct declaration in the struct.
And I don't know what m_ItemSet[10] is trying to do, but you are declaring a variable here, and it cannot be an array, I don't think. What are you trying to do here ?
Christian
<i>No offense, but I don't really want to encourage the creation of another VB developer.</i> - <b>Larry Antram 22 Oct 2002</b>
<i>Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that...</i> - <b>Shog9 04-09-2002</b>
<i>During last 10 years, with invention of VB and similar programming environments, every ill-educated moron became able to develop software. </i> - <B>Alex E. - 12-Sept-2002</B>
|
|
|
|
|
This:
typedef struct __Item
{
int m_iXX1;
int m_iXX2;
list<__Item> m_Right;
}_Item;
The list<__Item> is not a valid type since it recursively depends on a type which it is itself part of. Ouch! Compare it to this:
struct list {
int value;
list next;
};
You need another level of indirection...
--
standing so tall, the ground behind
no trespassers, on every floor
a garden swing, and another door
she makes it clear, that everything is hers
A place of abode, not far from here, Ms. Van de Veer
|
|
|
|
|
I'm designing a crossplatform (Win/Unix) object and having problems typedef'ing an iterator for a set of these objects. The actual object is IProjectObserver (but that is of course, unimportant). The compiler complains about the 2nd typedef in IProjectObserver.h. The error message is:
Error C2653: 'set<class IProjectObserver *,int,class std::allocator<class IProjectObserver *> >' : is not a class or namespace name.
#ifndef IProjectObserver_h
#define IProjectObserver_h
#include <set>
using std::iterator;
using std::set;
class IProjectObserver
{
public:
IProjectObserver();
virtual ~IProjectObserver();
public:
virtual void handleEvent
(void* pEvent) = 0;
};
typedef set< IProjectObserver *, int > ProjectObserverSet;
typedef set< IProjectObserver *, int >::iterator ProjectObserverSetIterator;
#endif The code compiles fine if I comment out the 2nd typedef. Any help would be appreciated. Thanks!
/ravi
Let's put "civil" back in "civilization"
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
I fixed my syntax error and now just end up with a bunch of warnings, similar to the slew of warnings I get when I use simple STL in my app (actually my lib). Odd.
Convenience typedefs
typedef set< IProjectObserver *> ProjectObserverSet;
typedef ProjectObserverSet::iterator ProjectObserverSetIterator; /ravi
Let's put "civil" back in "civilization"
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
You can use the std prefix:
typedef set< IProjectObserver *> ProjectObserverSet;
typedef std::set< IProjectObserver *>::iterator ProjectObserverSetIterator;
Best regards,
Alexandru Savescu
|
|
|
|
|
|
When you write using std::set that does not recursively use nested classes in set (such as iterator ) so you have to write std::set<blah blah>::iterator
--Mike--
"alyson hannigan is so cute it's crazy" -- Googlism
Just released - 1ClickPicGrabber - Grab & organize pictures from your favorite web pages, with 1 click!
My really out-of-date homepage
Sonork-100.19012 Acid_Helm
|
|
|
|
|
|
Is that C++ or a workaround for a broken VC++?
--
standing so tall, the ground behind
no trespassers, on every floor
a garden swing, and another door
she makes it clear, that everything is hers
A place of abode, not far from here, Ms. Van de Veer
|
|
|
|
|
Jörgen Sigvardsson wrote:
Is that C++ or a workaround for a broken VC++?
It's far too early in the morning to try and find it in the C++ spec, so let's just assume the latter for now.
--Mike--
"alyson hannigan is so cute it's crazy" -- Googlism
Just released - 1ClickPicGrabber - Grab & organize pictures from your favorite web pages, with 1 click!
My really out-of-date homepage
Sonork-100.19012 Acid_Helm
|
|
|
|
|
Safe bet.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
i *think* set uses 1 param.Did you intend to use map.it should work fine.
benefactor
|
|
|
|
|
Yes, I'd fixed that syntax error. Thanks,
/ravi
Let's put "civil" back in "civilization"
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
Are there any special requirements/dlls/etc. that your users computers need if you implement ATL / WTL / STL ? New to this area.
"Best file compression around: DEL *.* = 100% compression."
<><><><><><><><><><><><><>
Matthew R. Miller
mattrmiller@computersmarts.net
www.computersmarts.net
|
|
|
|