IDebugDocumentContext2::GetName
Applies to: Visual Studio Visual Studio for Mac
Note
This article applies to Visual Studio 2017. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here
Gets the displayable name of the document that contains this document context.
Syntax
HRESULT GetName(
GETNAME_TYPE gnType,
BSTR* pbstrFileName
);
int GetName(
enum_GETNAME_TYPE gnType,
out string pbstrFileName
);
Parameters
gnType
[in] A value from the GETNAME_TYPE enumeration that specifies the type of name to return.
pbstrFileName
[out] Returns the name of the file.
Return Value
If successful, returns S_OK
; otherwise, returns an error code.
Remarks
This method typically forwards the call to the GetName method, unless the document context is written to store the document name itself (as the Example show).
Example
The following example shows how to implement this method for a simple CDebugContext
object that exposes the IDebugDocumentContext2 interface.
HRESULT CDebugContext::GetName(GETNAME_TYPE gnType, BSTR* pbstrFileName)
{
HRESULT hr;
// Check for a valid file name argument.
if (pbstrFileName)
{
*pbstrFileName = NULL;
switch (gnType)
{
case GN_NAME:
case GN_FILENAME:
{
// Copy the member file name into the local file name.
*pbstrFileName = SysAllocString(m_sbstrFileName);
// Check for successful copy.
hr = (*pbstrFileName) ? S_OK : E_OUTOFMEMORY;
break;
}
default:
{
hr = E_FAIL;
break;
}
}
}
else
{
hr = E_INVALIDARG;
}
return hr;
}