Skip to content

Commit 070e9a9

Browse files
committed
Added IE string utility method for creating GUIDs
1 parent 53254bf commit 070e9a9

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

cpp/iedriver/StringUtilities.cpp

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,4 +211,29 @@ void StringUtilities::Split(const std::wstring& input,
211211
}
212212
}
213213

214-
} // namespace webdriver
214+
std::wstring StringUtilities::CreateGuid() {
215+
UUID guid;
216+
RPC_WSTR guid_string = NULL;
217+
RPC_STATUS status = ::UuidCreate(&guid);
218+
if (status != RPC_S_OK) {
219+
// If we encounter an error, not bloody much we can do about it.
220+
// Just log it and continue.
221+
// LOG(WARN) << "UuidCreate returned a status other then RPC_S_OK: " << status;
222+
}
223+
status = ::UuidToString(&guid, &guid_string);
224+
if (status != RPC_S_OK) {
225+
// If we encounter an error, not bloody much we can do about it.
226+
// Just log it and continue.
227+
// LOG(WARN) << "UuidToString returned a status other then RPC_S_OK: " << status;
228+
}
229+
230+
// RPC_WSTR is currently typedef'd in RpcDce.h (pulled in by rpc.h)
231+
// as unsigned short*. It needs to be typedef'd as wchar_t*
232+
wchar_t* cast_guid_string = reinterpret_cast<wchar_t*>(guid_string);
233+
std::wstring returned_guid(cast_guid_string);
234+
235+
::RpcStringFree(&guid_string);
236+
return returned_guid;
237+
}
238+
239+
} // namespace webdriver

cpp/iedriver/StringUtilities.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ class StringUtilities {
3030
static std::wstring ToWString(const std::string& input);
3131
static std::string ToString(const std::wstring& input);
3232

33+
static std::wstring CreateGuid(void);
34+
3335
static std::string Format(const char* format, ...);
3436
static std::wstring Format(const wchar_t* format, ...);
3537

@@ -53,4 +55,4 @@ class StringUtilities {
5355

5456
} // namespace webdriver
5557

56-
#endif // WEBDRIVER_IE_STRINGUTILITIES_H
58+
#endif // WEBDRIVER_IE_STRINGUTILITIES_H

0 commit comments

Comments
 (0)