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