Re: unique serial number for class objects
On Jul 6, 3:56 pm, Joseph M. Newcomer <newco...@flounder.com> wrote:
What unique serial number? What do you mean by "class objects"?
If you simply do
Thing * x = new Thing;
there is no unique serial number in the runtime; this is something you would have to
handle on your own, e.g.,
class Thing {
static long SerialNumberCounter; // initialize to 0
long SerialNumber;
public:
Thing() { SerialNumber = InterlockedIncrement(&SerialNumberCounter); ...}
long GetUniqueID() { return SerialNumber; }
};
So unless you create such an entity, it isn't going to happen on its own.
OTOH, some COM objects actually DO implement this kind of feature, so the answer is, in
those cases, RTFM.
joe
On Fri, 06 Jul 2007 14:13:45 -0000, wanwan <ericwa...@yahoo.com> wrote:
is there a way for me to retrieve it?
Joseph M. Newcomer [MVP]
email: newco...@flounder.com
Web:http://www.flounder.com
MVP Tips:http://www.flounder.com/mvp_tips.htm
your method only works in an application running alone in a local
system. Making such a counter is seriously flawed in a network
application, because applications can create class objects with
conflicting ID.
In Java, I've written a Peer to Peer application. I was able to get a
unique hash ID for any class object that I instantiate. There was a
built in function for me to do it.
I need to find some way to get the same result in MFC.