The following code fragments briefly demonstrate how to call the interfaces from Visual Basic and C/C++.
Example 1: Calling Active Directory Interfaces (Visual Basic)
' How to get and set properties, call methods, and handle errors.
Dim MyObject as IADsXYZ
Dim MyVariable as String
' Set exception handling.
On Error Resume Next
' Assume that MyObject has been bound to an interface
' on an object. How to do this is discussed in the
' next section.
' Get a property.
MyVariable = MyObject.AReadWriteProp
If Err<>0 Then
' Put error handling code here.
EndIf
' Set a property.
MyObject.AReadWriteProp = "A string value."
If Err<>0 Then
' Put error handling code here.
EndIf
' Call a method.
MyObject.AMethod
If Err<>0 Then
' Put error handling code here.
EndIf
Example 1: Calling Active Directory Interfaces (C/C++)
IADsXYZ *pMyObject;
BSTR bstrMyVariable;
HRESULT hr;
//
// Assume that pMyObject has been bound to an interface on an object.
// How to do this is discussed in the next section.
//
// Get a property value.
//
hr = pMyObject->get_AReadWriteProp(&bstrMyVariable);
if (FAILED(hr))
{
// Put error handling code here.
}
SysFreeString(bstrMyVariable);
//
// Set a property value.
//
bstrMyVariable = SysAllocString(TEXT("A string value."));
hr = pMyObject->put_AReadWriteProp(bstrMyVariable);
if (FAILED(hr))
{
// Put error handling code here.
}
//
// Call a method.
//
hr = pMyObject->AMethod();
if (FAILED(hr))
{
// Put error handling code here.
}