]>
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 licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
19 #if defined(__BORLANDC__)
25 #if wxUSE_OLE && ( wxUSE_DRAG_AND_DROP || (defined(__WXDEBUG__) && wxUSE_DATAOBJ) )
28 #if wxCHECK_W32API_VERSION( 1, 0 )
29 #include "wx/msw/wrapwin.h"
31 #include <rpc.h> // UUID related functions
33 #include "wx/msw/ole/uuid.h"
37 // ============================================================================
39 // ============================================================================
41 // length of UUID in C format
42 #define UUID_CSTRLEN 100 // real length is 66
45 Uuid::Uuid(const Uuid
& uuid
)
47 // bitwise copy Ok for UUIDs
50 // force the string to be allocated by RPC
51 // (we free it later with RpcStringFree)
53 UuidToString(&m_uuid
, (unsigned short **)&m_pszUuid
);
55 UuidToString(&m_uuid
, &m_pszUuid
);
58 // allocate new buffer
59 m_pszCForm
= new wxChar
[UUID_CSTRLEN
];
61 memcpy(m_pszCForm
, uuid
.m_pszCForm
, UUID_CSTRLEN
*sizeof(wxChar
));
64 // assignment operator
65 Uuid
& Uuid::operator=(const Uuid
& uuid
)
69 // force the string to be allocated by RPC
70 // (we free it later with RpcStringFree)
72 UuidToString(&m_uuid
, (unsigned short **)&m_pszUuid
);
74 UuidToString(&m_uuid
, &m_pszUuid
);
77 // allocate new buffer if not done yet
79 m_pszCForm
= new wxChar
[UUID_CSTRLEN
];
82 memcpy(m_pszCForm
, uuid
.m_pszCForm
, UUID_CSTRLEN
*sizeof(wxChar
));
90 // this string must be allocated by RPC!
91 // (otherwise you get a debug breakpoint deep inside RPC DLL)
94 RpcStringFree((unsigned short **)&m_pszUuid
);
96 RpcStringFree(&m_pszUuid
);
99 // perhaps we should just use a static buffer and not bother
100 // with new and delete?
102 delete [] m_pszCForm
;
105 // update string representation of new UUID
106 void Uuid::Set(const UUID
&uuid
)
110 // get string representation
112 UuidToString(&m_uuid
, (unsigned short **)&m_pszUuid
);
114 UuidToString(&m_uuid
, &m_pszUuid
);
117 // cache UUID in C format
133 bool Uuid::Set(const wxChar
*pc
)
135 // get UUID from string
137 if ( UuidFromString((unsigned short *)pc
, &m_uuid
) != RPC_S_OK
)
139 if ( UuidFromString((wxUChar
*)pc
, &m_uuid
) != RPC_S_OK
)
141 // failed: probably invalid string
144 // transform it back to string to normalize it
146 UuidToString(&m_uuid
, (unsigned short **)&m_pszUuid
);
148 UuidToString(&m_uuid
, &m_pszUuid
);
157 // stores m_uuid in m_pszCForm in a format required by
158 // DEFINE_GUID macro: i.e. something like
159 // 0x7D8A2281L,0x4C61,0x11D0,0xBA,0xBD,0x00,0x00,0xC0,0x18,0xBA,0x27
160 // m_pszUuid is of the form (no, it's not quite the same UUID :-)
161 // 6aadc650-67b0-11d0-bac8-0000c018ba27
162 void Uuid::UuidToCForm()
164 if ( m_pszCForm
== NULL
)
165 m_pszCForm
= new wxChar
[UUID_CSTRLEN
];
167 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"),
168 m_uuid
.Data1
, m_uuid
.Data2
, m_uuid
.Data3
,
169 m_uuid
.Data4
[0], m_uuid
.Data4
[1], m_uuid
.Data4
[2], m_uuid
.Data4
[3],
170 m_uuid
.Data4
[4], m_uuid
.Data4
[5], m_uuid
.Data4
[6], m_uuid
.Data4
[7]);
174 // wxUSE_DRAG_AND_DROP