DLL Calling Example

This example writes the text hello world! into a field by calling the SendMessage DLL function from user32.dll.

DLL Declaration:

// VB .NET code
<Dll("user32.dll")> Public Interface IUserDll32Functions
  Function SendMessageW( _
    ByVal obj As TestObject,ByVal message As Integer,ByVal wParam As Integer,ByVal lParam As String) As Integer
End Interface
// C# code
[Dll("user32.dll")]
public interface IUserDll32Functions {
  int SendMessageW(TestObject obj, int message, int wParam, string lParam);
}
The following code shows how to call the declared DLL function in the AUT:
// VB .NET code
Public Sub Main()
  Dim user32Functions As IUserDll32Functions = DllCall.CreateInProcessDllCall(Of IUserDll32Functions)()
  Dim textField = _desktop.Window().TextField()
  user32Functions.SendMessageW(textField, WindowsMessages.WM_SETTEXT, 0, "my text")
End Sub
// C# code
public void main()
{
  IUserDll32Functions user32Functions = DllCall.CreateInProcessDllCall<IUserDll32Functions>();
  TextField textField = _desktop.Window().TextField();
  user32Functions.SendMessageW(textField, (int) WindowsMessages.WM_SETTEXT, 0, "my text");
}
Note: You can only call DLL functions in the AUT if the first parameter of the DLL function has the C data type HWND.
The following code shows how to call the declared DLL functions in the process of the Open Agent:
// VB .NET code
Public Sub Main()
  Dim user32Functions As IUserDll32Functions = DllCall.CreateAgentDllCall(Of IUserDll32Functions)()
  Dim textField = _desktop.Window().TextField()
  user32Functions.SendMessageW(textField, WindowsMessages.WM_SETTEXT, 0, "my text")
End Sub
// C# code
public void main()
{
  IUserDll32Functions user32Functions = DllCall.CreateAgentDllCall<IUserDll32Functions>();
  TextField textField = _desktop.Window().TextField();
  user32Functions.SendMessageW(textField, (int) WindowsMessages.WM_SETTEXT, 0, "my text");
}
Note: The example code uses the WindowsMessages class that contains useful constants for usage with DLL functions that relate to Windows messaging.