From 070e9a9b905e25ed354f2158b82636fa16fe3cd0 Mon Sep 17 00:00:00 2001 From: Jim Evans Date: Tue, 6 Mar 2018 06:40:39 -0800 Subject: [PATCH] Added IE string utility method for creating GUIDs --- cpp/iedriver/StringUtilities.cpp | 27 ++++++++++++++++++++++++++- cpp/iedriver/StringUtilities.h | 4 +++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/cpp/iedriver/StringUtilities.cpp b/cpp/iedriver/StringUtilities.cpp index e25fa46f63d77..40abc463abaca 100644 --- a/cpp/iedriver/StringUtilities.cpp +++ b/cpp/iedriver/StringUtilities.cpp @@ -211,4 +211,29 @@ void StringUtilities::Split(const std::wstring& input, } } -} // namespace webdriver \ No newline at end of file +std::wstring StringUtilities::CreateGuid() { + UUID guid; + RPC_WSTR guid_string = NULL; + RPC_STATUS status = ::UuidCreate(&guid); + if (status != RPC_S_OK) { + // If we encounter an error, not bloody much we can do about it. + // Just log it and continue. + // LOG(WARN) << "UuidCreate returned a status other then RPC_S_OK: " << status; + } + status = ::UuidToString(&guid, &guid_string); + if (status != RPC_S_OK) { + // If we encounter an error, not bloody much we can do about it. + // Just log it and continue. + // LOG(WARN) << "UuidToString returned a status other then RPC_S_OK: " << status; + } + + // RPC_WSTR is currently typedef'd in RpcDce.h (pulled in by rpc.h) + // as unsigned short*. It needs to be typedef'd as wchar_t* + wchar_t* cast_guid_string = reinterpret_cast(guid_string); + std::wstring returned_guid(cast_guid_string); + + ::RpcStringFree(&guid_string); + return returned_guid; +} + +} // namespace webdriver diff --git a/cpp/iedriver/StringUtilities.h b/cpp/iedriver/StringUtilities.h index fe2c184f072fd..8ae546c3974f1 100644 --- a/cpp/iedriver/StringUtilities.h +++ b/cpp/iedriver/StringUtilities.h @@ -30,6 +30,8 @@ class StringUtilities { static std::wstring ToWString(const std::string& input); static std::string ToString(const std::wstring& input); + static std::wstring CreateGuid(void); + static std::string Format(const char* format, ...); static std::wstring Format(const wchar_t* format, ...); @@ -53,4 +55,4 @@ class StringUtilities { } // namespace webdriver -#endif // WEBDRIVER_IE_STRINGUTILITIES_H \ No newline at end of file +#endif // WEBDRIVER_IE_STRINGUTILITIES_H