]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/ole/uuid.cpp
1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: implements Uuid class, see uuid.h for details
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows license
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
17 #pragma implementation "uuid.h"
20 // For compilers that support precompilation, includes "wx.h".
21 #define IN_WX_MAIN_CPP
22 #include "wx/wxprec.h"
24 #if defined(__BORLANDC__)
33 #include <rpc.h> // UUID related functions
35 #include <wx/msw/ole/uuid.h>
39 // ============================================================================
41 // ============================================================================
43 // length of UUID in C format
44 #define UUID_CSTRLEN 100 // real length is 66
47 Uuid::Uuid(const Uuid
& uuid
)
49 // bitwise copy Ok for UUIDs
52 // force the string to be allocated by RPC
53 // (we free it later with RpcStringFree)
54 UuidToString(&m_uuid
, &m_pszUuid
);
56 // allocate new buffer
57 m_pszCForm
= new char[UUID_CSTRLEN
];
59 memcpy(m_pszCForm
, uuid
.m_pszCForm
, UUID_CSTRLEN
);
62 // assignment operator
63 Uuid
& Uuid::operator=(const Uuid
& uuid
)
67 // force the string to be allocated by RPC
68 // (we free it later with RpcStringFree)
69 UuidToString(&m_uuid
, &m_pszUuid
);
71 // allocate new buffer if not done yet
73 m_pszCForm
= new char[UUID_CSTRLEN
];
76 memcpy(m_pszCForm
, uuid
.m_pszCForm
, UUID_CSTRLEN
);
84 // this string must be allocated by RPC!
85 // (otherwise you get a debug breakpoint deep inside RPC DLL)
87 RpcStringFree(&m_pszUuid
);
89 // perhaps we should just use a static buffer and not bother
90 // with new and delete?
95 // update string representation of new UUID
96 void Uuid::Set(const UUID
&uuid
)
100 // get string representation
101 UuidToString(&m_uuid
, &m_pszUuid
);
103 // cache UUID in C format
119 bool Uuid::Set(const char *pc
)
121 // get UUID from string
122 if ( UuidFromString((uchar
*)pc
, &m_uuid
) != RPC_S_OK
)
123 // failed: probably invalid string
126 // transform it back to string to normalize it
127 UuidToString(&m_uuid
, &m_pszUuid
);
135 // stores m_uuid in m_pszCForm in a format required by
136 // DEFINE_GUID macro: i.e. something like
137 // 0x7D8A2281L,0x4C61,0x11D0,0xBA,0xBD,0x00,0x00,0xC0,0x18,0xBA,0x27
138 // m_pszUuid is of the form (no, it's not quite the same UUID :-)
139 // 6aadc650-67b0-11d0-bac8-0000c018ba27
140 void Uuid::UuidToCForm()
142 if ( m_pszCForm
== NULL
)
143 m_pszCForm
= new char[UUID_CSTRLEN
];
145 wsprintf(m_pszCForm
, "0x%8.8X,0x%4.4X,0x%4.4X,0x%2.2X,0x2.2%X,"
146 "0x2.2%X,0x2.2%X,0x2.2%X,0x2.2%X,0x2.2%X,0x2.2%X",
147 m_uuid
.Data1
, m_uuid
.Data2
, m_uuid
.Data3
,
148 m_uuid
.Data4
[1], m_uuid
.Data4
[2], m_uuid
.Data4
[3], m_uuid
.Data4
[4],
149 m_uuid
.Data4
[5], m_uuid
.Data4
[6], m_uuid
.Data4
[7], m_uuid
.Data4
[8]);