ObtainUserAgentString Function
Retrieves the User-Agent HTTP request header string that is currently being used.
Syntax
HRESULT ObtainUserAgentString( DWORD dwOption, LPCSTR *pcszUAOut, DWORD *cbSize );
Parameters
- dwOption
- [in] One of the following required values:
7 | UAS_EXACTLEGACY- Windows Internet Explorer 7 in exact legacy mode.
7- Internet Explorer 7 in compatible mode.
8- Internet Explorer 8.
- 0
- Default. As currently set.
- pcszUAOut
- [out] Pointer to a string value that contains the User-Agent request header string that is currently being used.
- cbSize
- [out] Pointer to an unsigned long integer value that contains the length of the User-Agent request header string.
Return Value
Returns one of the following values:
E_INVALIDARG One of the parameters is invalid. E_OUTOFMEMORY The operation ran out of memory. NOERROR The function completed successfully.
Remarks
Passing a bitwise OR of
7 | UAS_EXACTLEGACYto dwOption specifies Internet Explorer 7 running in exact legacy mode, as opposed to compatible mode.Internet Explorer 8. dwOption is no longer reserved and must have one of the required values.
Example
The following example is a User-Agent HTTP request header sent by Internet Explorer 7 on Windows XP with Microsoft Office:
Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; InfoPath.1)
Function Information
Stock Implementation urlmon.dll Custom Implementation No Header Urlmon.h Import library Urlmon.lib Minimum availability Internet Explorer 4.0 Minimum operating systems Windows NT 4.0, Windows 95, Windows CE 2.12
See Also
Community Content
DaveMethvin
A few missing nuggets
Just to reinforce, the buffer is indeed CHAR, not TCHAR, regardless of UNICODE's value.
The cbSize is [in,out], not just [out], since you need to pass in the size of the buffer in bytes.
If the function returns E_OUTOFMEMORY, it appears that cbSize returns the number of bytes required, so you can reallocate the buffer and make a second request.
If Microsoft could document this as part of the function's contract, it would be helpful.
The cbSize is [in,out], not just [out], since you need to pass in the size of the buffer in bytes.
If the function returns E_OUTOFMEMORY, it appears that cbSize returns the number of bytes required, so you can reallocate the buffer and make a second request.
If Microsoft could document this as part of the function's contract, it would be helpful.