]>
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 #include "wx/wxprec.h"
23 #if defined(__BORLANDC__)
29 #if wxUSE_DRAG_AND_DROP
32 #include <rpc.h> // UUID related functions
34 #include <wx/msw/ole/uuid.h>
38 // ============================================================================
40 // ============================================================================
42 // length of UUID in C format
43 #define UUID_CSTRLEN 100 // real length is 66
46 Uuid::Uuid(const Uuid
& uuid
)
48 // bitwise copy Ok for UUIDs
51 // force the string to be allocated by RPC
52 // (we free it later with RpcStringFree)
53 UuidToString(&m_uuid
, &m_pszUuid
);
55 // allocate new buffer
56 m_pszCForm
= new char[UUID_CSTRLEN
];
58 memcpy(m_pszCForm
, uuid
.m_pszCForm
, UUID_CSTRLEN
);
61 // assignment operator
62 Uuid
& Uuid::operator=(const Uuid
& uuid
)
66 // force the string to be allocated by RPC
67 // (we free it later with RpcStringFree)
68 UuidToString(&m_uuid
, &m_pszUuid
);
70 // allocate new buffer if not done yet
72 m_pszCForm
= new char[UUID_CSTRLEN
];
75 memcpy(m_pszCForm
, uuid
.m_pszCForm
, UUID_CSTRLEN
);
83 // this string must be allocated by RPC!
84 // (otherwise you get a debug breakpoint deep inside RPC DLL)
86 RpcStringFree(&m_pszUuid
);
88 // perhaps we should just use a static buffer and not bother
89 // with new and delete?
94 // update string representation of new UUID
95 void Uuid::Set(const UUID
&uuid
)
99 // get string representation
100 UuidToString(&m_uuid
, &m_pszUuid
);
102 // cache UUID in C format
118 bool Uuid::Set(const char *pc
)
120 // get UUID from string
121 if ( UuidFromString((uchar
*)pc
, &m_uuid
) != RPC_S_OK
)
122 // failed: probably invalid string
125 // transform it back to string to normalize it
126 UuidToString(&m_uuid
, &m_pszUuid
);
134 // stores m_uuid in m_pszCForm in a format required by
135 // DEFINE_GUID macro: i.e. something like
136 // 0x7D8A2281L,0x4C61,0x11D0,0xBA,0xBD,0x00,0x00,0xC0,0x18,0xBA,0x27
137 // m_pszUuid is of the form (no, it's not quite the same UUID :-)
138 // 6aadc650-67b0-11d0-bac8-0000c018ba27
139 void Uuid::UuidToCForm()
141 if ( m_pszCForm
== NULL
)
142 m_pszCForm
= new char[UUID_CSTRLEN
];
144 wsprintf(m_pszCForm
, "0x%8.8X,0x%4.4X,0x%4.4X,0x%2.2X,0x2.2%X,"
145 "0x2.2%X,0x2.2%X,0x2.2%X,0x2.2%X,0x2.2%X,0x2.2%X",
146 m_uuid
.Data1
, m_uuid
.Data2
, m_uuid
.Data3
,
147 m_uuid
.Data4
[1], m_uuid
.Data4
[2], m_uuid
.Data4
[3], m_uuid
.Data4
[4],
148 m_uuid
.Data4
[5], m_uuid
.Data4
[6], m_uuid
.Data4
[7], m_uuid
.Data4
[8]);
152 // wxUSE_DRAG_AND_DROP