Skip to content

Commit

Permalink
Added IE string utility method for creating GUIDs
Browse files Browse the repository at this point in the history
  • Loading branch information
jimevans committed Mar 6, 2018
1 parent 53254bf commit 070e9a9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
27 changes: 26 additions & 1 deletion cpp/iedriver/StringUtilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,4 +211,29 @@ void StringUtilities::Split(const std::wstring& input,
}
}

} // namespace webdriver
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<wchar_t*>(guid_string);
std::wstring returned_guid(cast_guid_string);

::RpcStringFree(&guid_string);
return returned_guid;
}

} // namespace webdriver
4 changes: 3 additions & 1 deletion cpp/iedriver/StringUtilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -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, ...);

Expand All @@ -53,4 +55,4 @@ class StringUtilities {

} // namespace webdriver

#endif // WEBDRIVER_IE_STRINGUTILITIES_H
#endif // WEBDRIVER_IE_STRINGUTILITIES_H

0 comments on commit 070e9a9

Please sign in to comment.