Skip to content

Outsource Windows API definitions (extern) to CsWin32 #4327

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

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

YoshiRulz
Copy link
Member

@YoshiRulz YoshiRulz commented May 21, 2025

https://github.com/microsoft/CsWin32

Pre-merge checklist:

@YoshiRulz YoshiRulz added this to the 2.10.2 milestone May 21, 2025
@YoshiRulz YoshiRulz changed the title Replace many extern declarations w/ CsWin32 Outsource Windows API extern declarations to CsWin32 May 22, 2025
@YoshiRulz YoshiRulz changed the title Outsource Windows API extern declarations to CsWin32 Outsource Windows API definitions (extern) to CsWin32 May 22, 2025
@YoshiRulz
Copy link
Member Author

Struggling w/ AVI, namely this array cast:

public static unsafe nint AVISaveOptions(IAVIStream[] ppavi, ref AVICOMPRESSOPTIONS opts, HWND owner)
{
fixed (AVICOMPRESSOPTIONS* popts = &opts)
{
return AVISaveOptions(owner, uiFlags: 0, nStreams: 1, ppavi, &popts);
}
}

public static unsafe int AVISaveOptions(IntPtr stream, ref AVICOMPRESSOPTIONS opts, IntPtr owner)
=> unchecked((int) AVIWriterImports.AVISaveOptions((IAVIStream[]) (void*) stream, ref opts, new(owner)));

(was:)
private static unsafe int AVISaveOptions(IntPtr stream, ref AVIWriterImports.AVICOMPRESSOPTIONS opts, IntPtr owner)
{
fixed (AVIWriterImports.AVICOMPRESSOPTIONS* _popts = &opts)
{
var pStream = &stream;
var popts = _popts;
var ppopts = &popts;
return AVIWriterImports.AVISaveOptions(owner, 0, 1, pStream, ppopts);
}
}

@kalimag
Copy link
Contributor

kalimag commented May 23, 2025

public static unsafe int AVISaveOptions(IntPtr stream, ref AVICOMPRESSOPTIONS opts, IntPtr owner)
=> unchecked((int) AVIWriterImports.AVISaveOptions((IAVIStream[]) (void*) stream, ref opts, new(owner)));

Presumably that should be new [] { stream }? stream is a pointer to a single stream, and AVISaveOptions expects a pointer to an array of pointers. But it also requires changing from raw IntPtrs to the generated IAVI* types all the way up the chain.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants