Platform SDK: Active Directory, ADSI, and Directory Services

IADsNameTranslate::GetEx

The IADsNameTranslate::GetEx method retrieves the names of the objects in the specified format. The names of the objects must have been set by IADsNameTranslate::SetEx.

HRESULT IADsNameTranslate::GetEx(
  long lnFormatType,
  VARIANT *pVarStr
);

Parameters

lnFormatType
The format type of the output names. See ADS_NAME_TYPE_ENUM for more information.
pVarStr
A variant array of strings that hold names of the objects returned.

Return Values

This method supports the standard HRESULT return values, including:

S_OK
The name has been set successfully.
E_ADS_DSNAME_ERROR_RESOLVING
Cannot resolve the name.
E_ADS_DSNAME_ERROR_NOT_FOUND
Cannot find the name.
E_ADS_DSNAME_ERROR_NOT_UNIQUE
The name is not unique.
E_ADS_DSNAME_ERROR_NO_MAPPING
Cannot map the name.
E_ADS_DSNAME_ERROR_DOMAIN_ONLY
Can resolve the domain, but not the entire path.
E_FAIL
The operation has failed.
E_OUTOFMEMORY
The name cannot be set.

Remarks

This method lets you retrieve the names of multiple objects. However, all the names are of a single format.

When referral chasing is on, this method will not attempt to chase and resolve the path of a specified object that is not residing on the connected server.

Example Code [C++]

The following C/C++ code snippet illustrates how to translate a distinguished names that is compliant with RFC 1779 to the GUID format. The machine name of the directory server is "myServer".

IADsNameTranslate *pNto;
HRESULT hr;
hr = CoCreateInstance(CLSID_NameTranslate,
                      NULL,
                      CLSCTX_INPROC_SERVER,
                      IID_IADsNameTranslate,
                      (void**)&pNto);
if(FAILED(hr)) { exit 1;}
 
hr = pNto->Init(ADS_NAME_INITTYPE_SERVER,
                  L"myServer");
if (FAILED(hr)) { exit 1;}
 
LPWSTR str[1] = { L"CN=jim,CN=Users,DC=myDomain,DC=Microsoft,DC=COM",
                  L"CN=rob,CN=Users,DC=myDomain,DC=Microsoft,DC=COM"};
DWORD dwNum = sizeof(str)/sizeof(LPWSTR);
 
VARIANT varStr;
VariantInit(&varStr);
 
hr = ADsBuildVarArrayStr(str,dwNum,&varStr);
 
hr =pNto->SetEx(ADS_NAME_TYPE_1779, varStr);
if(FAILED(hr)) {exit 1;}
VariantClear(&varStr);
 
hr = pNto->GetEx(ADS_NAME_TYPE_GUID, &varStr);
if(FAILED(hr)) {exit 1;}
 
LONG lstart, lend;
SAFEARRAY *sa = V_ARRAY(&varStr);
VARIANT varItem;
VariantInit(&varItem);
printf("Names in the translated format:\n");
for (long idx = lstart; idx <= lend; idx++) 
{
    hr = SafeArrayGetElement(sa, &idx, &varItem);
    printf("   %S\n", V_BSTR(&varItem));
    VariantClear(&varItem);
}
VariantClear(&varStr);
pNto->Release();

Example Code [Visual Basic]

The following code snippet illustrates how to convert multiple names from the RFC 1779 type to the GUID type. The machine name of the directory server is "myServer" .

Dim nto As new NameTranslate
Dim result As Variant
Dim ns(1) As String
 
nto.Init ADS_NAME_INITTTYPE_SERVER, "myServer"
 
ns(0)="CN=rob,CN=users,DC=myDom,DC=myCom,DC=COM,O=Internet"
ns(1)="CN=jim,CN=users,DC=myDom,DC=myCom,DC=COM,O=Internet"
 
nto.SetEx ADS_NAME_TYPE_1779, ns
nto.GetEx ADS_NAME_TYPE_GUID, result
MsgBox "name(0): " & result(0) & " name(1): " & result(1)

Example Code [VBScript]

The following VBScript/ASP code snippet translates two distinguished names that are compliant with RFC 1779 to the GUID format. The machine name of the directory server is "myServer".

<%@ Language=VBScript %>
<html>
<body>
<%
  Dim nto
  const ADS_NAME_INITTYPE_SERVER = 2
  const ADS_NAME_TYPE_1779 = 1
  const ADS_NAME_TYPE_NT4 = 3
 
  server = "myServer"
  user   = "jsmith"
  dom    = "Microsoft"
  passwd = "top secret" 
 
  Set nto = Server.CreateObject("NameTranslate")
  nto.InitEx ADS_NAME_INITTYPE_SERVER, server, user, dom, passwd
 
  ns(0)="CN=rob,CN=users,DC=myDom,DC=myCom,DC=COM,O=Internet"
  ns(1)="CN=jim,CN=users,DC=myDom,DC=myCom,DC=COM,O=Internet"
 
  nto.SetEx ADS_NAME_TYPE_1779, ns
  result = nto.GetEx(ADS_NAME_TYPE_GUID)
 
  Response.Write "<p>Names in the translated format: " & result(0) & ", " & result(1)
 
%>
</body>
</html>

Requirements

  Windows NT/2000: Requires Windows 2000 (or Windows NT 4.0 with DSClient).
  Windows 95/98: Requires Windows 95 or later (with DSClient).
  Header: Declared in Iads.h.

See Also

IADsNameTranslate, IADsNameTranslate::SetEx, ADS_NAME_TYPE_ENUM