Skip to content

Commit

Permalink
feat: add Dispatcher class
Browse files Browse the repository at this point in the history
  • Loading branch information
halildurmus committed Oct 19, 2024
1 parent 2222ea2 commit 7a1ac40
Show file tree
Hide file tree
Showing 7 changed files with 263 additions and 155 deletions.
53 changes: 53 additions & 0 deletions examples/dispatcher.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Demonstrates the use of Dispatcher for calling methods on COM automation
// objects.

import 'dart:ffi';

import 'package:ffi/ffi.dart';
import 'package:win32/win32.dart';

void main() {
// Initialize COM.
CoInitializeEx(
nullptr,
COINIT.COINIT_APARTMENTTHREADED | COINIT.COINIT_DISABLE_OLE1DDE,
);

// Create a Dispatcher instance for the "Shell.Application" COM object.
final dispatcher = Dispatcher.fromProgID('Shell.Application');

// Example: Call the "MinimizeAll" method on the "Shell.Application" object
// to minimize all open windows.
print('Minimizing all windows via "Shell.Application" Automation object');
dispatcher.invoke('MinimizeAll');

// Example: Call the "Explore" method on the "Shell.Application" object with
// a parameter to open the Windows Explorer starting at the "C:\" directory.
print(r'Launching the Windows Explorer, starting at the "C:\" directory');
final folderLocation = BSTR.fromString(r'C:\');

// Allocate and initialize a VARIANT structure to hold the parameter.
final exploreParam = calloc<VARIANT>();
VariantInit(exploreParam);
exploreParam.ref
..vt = VARENUM.VT_BSTR
..bstrVal = folderLocation.ptr;
final exploreParams = calloc<DISPPARAMS>();
exploreParams.ref
..cArgs = 1 // Number of arguments.
..rgvarg = exploreParam; // Pointer to the argument list.

// Invoke the "Explore" method with the specified parameters.
dispatcher.invoke('Explore', exploreParams);

// Free the allocated memory for DISPPARAMS.
free(exploreParams);

// Clear the VARIANT structure to free the associated BSTR memory.
VariantClear(exploreParam);
free(exploreParam);

// Clean up the Dispatcher instance.
dispatcher.dispose();
print('Done.');
}
142 changes: 0 additions & 142 deletions examples/idispatch.dart

This file was deleted.

3 changes: 2 additions & 1 deletion packages/win32/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

All notable changes to this project will be documented in this file.

## 5.6.2-wip
## 5.7.0-wip

- Add `UnregisterDeviceNotification` API (#916)
- Add `DEV_BROADCAST_VOLUME` struct
- Add `DRIVE_UNKNOWN`, `DRIVE_NO_ROOT_DIR`, `DRIVE_REMOVABLE`, `DRIVE_FIXED`,
`DRIVE_REMOTE`, `DRIVE_CDROM`, and `DRIVE_RAMDISK` constants
- Add `Dispatcher` class (#917)

## [5.6.1] - 2024-10-18

Expand Down
22 changes: 11 additions & 11 deletions packages/win32/example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,21 +141,21 @@ visit [pub.dev] to explore packages that depend on it.

## COM APIs

| Example | Description |
| ------------------- | -------------------------------------------------------------- |
| [com_context.dart] | Shows interaction of Dart isolates and COM apartments |
| [com_demo.dart] | Demonstrates COM object creation, casting, and calling methods |
| [guid.dart] | Creates a globally unique identifier (GUID) |
| [idispatch.dart] | Demonstrates the use of `IDispatch` |
| [uiautomation.dart] | Demonstrates calling Windows UI Automation APIs |
| [winhttp.dart] | Demonstrates using WinHTTP APIs to make HTTP requests |
| [wmi_perf.dart] | Uses WMI to retrieve performance counters |
| [wmi_wql.dart] | Uses WMI to retrieve information using WQL |
| Example | Description |
| ------------------- | ------------------------------------------------------------------------ |
| [com_context.dart] | Shows interaction of Dart isolates and COM apartments |
| [com_demo.dart] | Demonstrates COM object creation, casting, and calling methods |
| [dispatcher.dart] | Demonstrates calling methods on COM automation objects with `Dispatcher` |
| [guid.dart] | Creates a globally unique identifier (GUID) |
| [uiautomation.dart] | Demonstrates calling Windows UI Automation APIs |
| [winhttp.dart] | Demonstrates using WinHTTP APIs to make HTTP requests |
| [wmi_perf.dart] | Uses WMI to retrieve performance counters |
| [wmi_wql.dart] | Uses WMI to retrieve information using WQL |

[com_context.dart]: https://github.com/halildurmus/win32/blob/main/examples/com_context.dart
[com_demo.dart]: https://github.com/halildurmus/win32/blob/main/examples/com_demo.dart
[dispatcher.dart]: https://github.com/halildurmus/win32/blob/main/examples/dispatcher.dart
[guid.dart]: https://github.com/halildurmus/win32/blob/main/examples/guid.dart
[idispatch.dart]: https://github.com/halildurmus/win32/blob/main/examples/idispatch.dart
[uiautomation.dart]: https://github.com/halildurmus/win32/blob/main/examples/uiautomation.dart
[winhttp.dart]: https://github.com/halildurmus/win32/blob/main/examples/winhttp.dart
[wmi_perf.dart]: https://github.com/halildurmus/win32/blob/main/examples/wmi_perf.dart
Expand Down
Loading

0 comments on commit 7a1ac40

Please sign in to comment.