Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Abstract away reserved parameters in Win32 functions and COM methods #821

Open
halildurmus opened this issue Feb 25, 2024 · 0 comments
Open
Assignees
Labels
feature New feature or request p: generator Issue with package:generator
Milestone

Comments

@halildurmus
Copy link
Owner

In certain Win32 functions and COM methods, some parameters are designated as reserved, indicating that a NULL or nullptr must be passed as an argument, depending on the parameter type.

To enhance the developer experience, these reserved parameters can be abstracted away by the generator, allowing NULL or nullptr to be passed implicitly.

Consider the CoInitializeEx function as an example, currently projected as:

int CoInitializeEx(Pointer pvReserved, int dwCoInit) =>
    _CoInitializeEx(pvReserved, dwCoInit);

final _CoInitializeEx = _ole32.lookupFunction<
    Int32 Function(Pointer pvReserved, Int32 dwCoInit),
    int Function(Pointer pvReserved, int dwCoInit)>('CoInitializeEx');

The first parameter is marked as reserved, with a type of Pointer, indicating that the caller must pass nullptr as an argument:

CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);

Here's the proposed projection for this function, abstracting away the reserved parameter and implicitly passing nullptr:

int CoInitializeEx(int dwCoInit) => _CoInitializeEx(nullptr, dwCoInit);

final _CoInitializeEx = _ole32.lookupFunction<
    HRESULT Function(Pointer pvReserved, Uint32 dwCoInit),
    int Function(Pointer pvReserved, int dwCoInit)>('CoInitializeEx');

With this adjustment, the function can now be called simply as:

CoInitializeEx(COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
@halildurmus halildurmus added the feature New feature or request label Feb 25, 2024
@halildurmus halildurmus added this to the 6.0.0 milestone Feb 25, 2024
@halildurmus halildurmus self-assigned this Feb 25, 2024
@halildurmus halildurmus added the p: generator Issue with package:generator label Feb 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request p: generator Issue with package:generator
Projects
None yet
Development

No branches or pull requests

1 participant