- Desktop
- Tools
- PASCAL Programming
- Calling Windows DLLs Example
Calling Windows DLLs Example
This is an example script for the process of calling a Windows dll
//// Sample script for Optuma tool programming//const { windows consts } MB_ICONQUESTION = $20; MB_YESNO = $4; IDYES = 6; VK_SHIFT = $10;
{ declaration of external functions }
function MessageBox(hwnd: pointer; text, caption: AnsiString; msgtype: integer): integer; stdcall; external 'User32.dll' name 'MessageBoxA';
function GetDiskFreeSpace(root: AnsiString; var secPerCluster, bytesPerCluster, freeClusters, totalClusters: integer): boolean; stdcall; external 'Kernel32.dll' name 'GetDiskFreeSpaceA';
function FindWindow(className, windowName: AnsiString): integer; stdcall; external 'User32.dll' name 'FindWindowA';
function GetKeyState(virtKey: integer): smallint; stdcall; external 'User32.dll';
function FreeSpaceInfo(drive: String): string;var a, b, c, d: word;begin if GetDiskFreeSpace(drive, a, b, c, d) then result := Format('%d sections per cluster; %d bytes per cluster; %d free clusters; %d total clusters', [a, b, c, d]) else result := '(could not get drive information)';end;
// DefineTool is where the settings for the Tool are defined// This procedure is called once when the tool is loaded// Normally this procedure does not need to be changedprocedure DefineTool(Tool : TTool);begin Tool.Name := 'dllcall'; Tool.MouseClicks := 1; Tool.Hint := ''; Tool.ToolType := ttDataList;end;
// Init is called to initialise the tool// This procedure is called once when the tool is added to a chartprocedure Init(Tool : TTool);begin if MessageBox(nil, 'Are you sure?', 'Confirmation', MB_ICONQUESTION + MB_YESNO) = IDYES then showmessage('MessageBox: user answered YES') else showmessage('MessageBox: user answered NO');
showmessage('Drive C: free space: ' + FreeSpaceInfo('C:'));
if GetKeyState(VK_SHIFT) < 0 then showmessage('Shift is pressed') else showmessage('Shift is not pressed');end;
// Process is called to calculate and drawn the tool on screen// This procedure is called when new data is received or loaded and// when a selection point is moved by the userprocedure Process(Tool : TTool; ProcessStart : Integer; ProcessEnd : Integer; DataIn : TDataList);begin
end;Forum Discussion
Your privacy choices
We use cookies and similar technologies to make the site work, see how it's used, and improve it. Analytics and advertising cookies only run with your consent — see our Privacy Policy for details.