]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/ole/uuid.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/ole/uuid.cpp
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 licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
19 #if defined(__BORLANDC__)
23 #if wxUSE_OLE && ( wxUSE_DRAG_AND_DROP || (defined(__WXDEBUG__) && wxUSE_DATAOBJ) )
26 #include "wx/msw/wrapwin.h"
29 #include <rpc.h> // UUID related functions
31 #include "wx/msw/ole/uuid.h"
35 // ============================================================================
37 // ============================================================================
39 // length of UUID in C format
40 #define UUID_CSTRLEN 100 // real length is 66
43 Uuid::Uuid(const Uuid
& uuid
)
45 // bitwise copy Ok for UUIDs
48 // force the string to be allocated by RPC
49 // (we free it later with RpcStringFree)
51 UuidToString(&m_uuid
, (unsigned short **)&m_pszUuid
);
53 UuidToString(&m_uuid
, &m_pszUuid
);
56 // allocate new buffer
57 m_pszCForm
= new wxChar
[UUID_CSTRLEN
];
59 memcpy(m_pszCForm
, uuid
.m_pszCForm
, UUID_CSTRLEN
*sizeof(wxChar
));
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)
70 UuidToString(&m_uuid
, (unsigned short **)&m_pszUuid
);
72 UuidToString(&m_uuid
, &m_pszUuid
);
75 // allocate new buffer if not done yet
77 m_pszCForm
= new wxChar
[UUID_CSTRLEN
];
80 memcpy(m_pszCForm
, uuid
.m_pszCForm
, UUID_CSTRLEN
*sizeof(wxChar
));
88 // this string must be allocated by RPC!
89 // (otherwise you get a debug breakpoint deep inside RPC DLL)
92 RpcStringFree((unsigned short **)&m_pszUuid
);
94 RpcStringFree(&m_pszUuid
);
97 // perhaps we should just use a static buffer and not bother
98 // with new and delete?
100 delete [] m_pszCForm
;
103 // update string representation of new UUID
104 void Uuid::Set(const UUID
&uuid
)
108 // get string representation
110 UuidToString(&m_uuid
, (unsigned short **)&m_pszUuid
);
112 UuidToString(&m_uuid
, &m_pszUuid
);
115 // cache UUID in C format
131 bool Uuid::Set(const wxChar
*pc
)
133 // get UUID from string
135 if ( UuidFromString((unsigned short *)pc
, &m_uuid
) != RPC_S_OK
)
137 if ( UuidFromString((wxUChar
*)pc
, &m_uuid
) != RPC_S_OK
)
139 // failed: probably invalid string
142 // transform it back to string to normalize it
144 UuidToString(&m_uuid
, (unsigned short **)&m_pszUuid
);
146 UuidToString(&m_uuid
, &m_pszUuid
);
155 // stores m_uuid in m_pszCForm in a format required by
156 // DEFINE_GUID macro: i.e. something like
157 // 0x7D8A2281L,0x4C61,0x11D0,0xBA,0xBD,0x00,0x00,0xC0,0x18,0xBA,0x27
158 // m_pszUuid is of the form (no, it's not quite the same UUID :-)
159 // 6aadc650-67b0-11d0-bac8-0000c018ba27
160 void Uuid::UuidToCForm()
162 if ( m_pszCForm
== NULL
)
163 m_pszCForm
= new wxChar
[UUID_CSTRLEN
];
165 wsprintf(m_pszCForm
, wxT("0x%8.8X,0x%4.4X,0x%4.4X,0x%2.2X,0x2.2%X,0x2.2%X,0x2.2%X,0x2.2%X,0x2.2%X,0x2.2%X,0x2.2%X"),
166 m_uuid
.Data1
, m_uuid
.Data2
, m_uuid
.Data3
,
167 m_uuid
.Data4
[0], m_uuid
.Data4
[1], m_uuid
.Data4
[2], m_uuid
.Data4
[3],
168 m_uuid
.Data4
[4], m_uuid
.Data4
[5], m_uuid
.Data4
[6], m_uuid
.Data4
[7]);
172 // wxUSE_DRAG_AND_DROP