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

WMI MI_ApplicationFT struct is hard to use #842

Open
riverar opened this issue Mar 18, 2022 · 5 comments
Open

WMI MI_ApplicationFT struct is hard to use #842

riverar opened this issue Mar 18, 2022 · 5 comments
Labels
help wanted Extra attention is needed usability Touch-up to improve the user experience for a language projection

Comments

@riverar
Copy link
Collaborator

riverar commented Mar 18, 2022

Related: microsoft/windows-rs#1572

WMI APIs such as MI_Application_NewSession are header-only. (Nearly all of them are.) That's not a problem per se but in this case, after calling MI_Application_InitializeV1 you get back a function table defined as such:

typedef struct _MI_ApplicationFT
{
    MI_Result (MI_CALL *Close)(
        _Inout_     MI_Application *application);

    MI_Result (MI_CALL *NewSession)(
        _In_     MI_Application *application,
        _In_opt_z_ const MI_Char *protocol,
        _In_opt_z_ const MI_Char *destination,
        _In_opt_ MI_DestinationOptions *options,
        _In_opt_ MI_SessionCallbacks *callbacks,
        _Outptr_opt_result_maybenull_ MI_Instance **extendedError,
        _Out_    MI_Session *session);

    MI_Result (MI_CALL *NewHostedProvider)(
        _In_     MI_Application *application,
        _In_z_     const MI_Char *namespaceName,
        _In_z_     const MI_Char *providerName,
        _In_     MI_MainFunction mi_Main,
        _Outptr_opt_result_maybenull_ MI_Instance **extendedError,
        _Out_    MI_HostedProvider *provider
        );

   // ...
}

Metadata currently houses a table of difficult to use bare IntPtrs.

public struct MI_ApplicationFT
{
	public IntPtr Close;
	public IntPtr NewSession;
	public IntPtr NewHostedProvider;
	public IntPtr NewInstance;
	public IntPtr NewDestinationOptions;
	public IntPtr NewOperationOptions;
	public IntPtr NewSubscriptionDeliveryOptions;
	public IntPtr NewSerializer;
	public IntPtr NewDeserializer;
	public IntPtr NewInstanceFromClass;
	public IntPtr NewClass;
}
@riverar riverar added the usability Touch-up to improve the user experience for a language projection label Mar 18, 2022
@mikebattista
Copy link
Contributor

What change would you like to see here?

@riverar
Copy link
Collaborator Author

riverar commented Mar 21, 2022

@mikebattista I think parsing the typedef blob into a delegate would be ideal. Maybe we can short term do this manually?

@vpopescu
Copy link

Any further thoughts/decisions on this?

@mikebattista
Copy link
Contributor

The scraped C# is below. Seems like yet another case of not honoring the NativeTypeName like #1006 and #983.

    public partial struct MI_ApplicationFT
    {
        [NativeTypeName("MI_Result (*)(MI_Application *) __attribute__((stdcall))")]
        public IntPtr Close;

        [NativeTypeName("MI_Result (*)(MI_Application *, const MI_Char *, const MI_Char *, MI_DestinationOptions *, MI_SessionCallbacks *, MI_Instance **, MI_Session *) __attribute__((stdcall))")]
        public IntPtr NewSession;

        [NativeTypeName("MI_Result (*)(MI_Application *, const MI_Char *, const MI_Char *, MI_MainFunction, MI_Instance **, MI_HostedProvider *) __attribute__((stdcall))")]
        public IntPtr NewHostedProvider;

        [NativeTypeName("MI_Result (*)(MI_Application *, const MI_Char *, const MI_ClassDecl *, MI_Instance **) __attribute__((stdcall))")]
        public IntPtr NewInstance;

        [NativeTypeName("MI_Result (*)(MI_Application *, MI_DestinationOptions *) __attribute__((stdcall))")]
        public IntPtr NewDestinationOptions;

        [NativeTypeName("MI_Result (*)(MI_Application *, MI_Boolean, MI_OperationOptions *) __attribute__((stdcall))")]
        public IntPtr NewOperationOptions;

        [NativeTypeName("MI_Result (*)(MI_Application *, MI_SubscriptionDeliveryType, MI_SubscriptionDeliveryOptions *) __attribute__((stdcall))")]
        public IntPtr NewSubscriptionDeliveryOptions;

        [NativeTypeName("MI_Result (*)(MI_Application *, MI_Uint32, MI_Char *, MI_Serializer *) __attribute__((stdcall))")]
        public IntPtr NewSerializer;

        [NativeTypeName("MI_Result (*)(MI_Application *, MI_Uint32, MI_Char *, MI_Deserializer *) __attribute__((stdcall))")]
        public IntPtr NewDeserializer;

        [NativeTypeName("MI_Result (*)(MI_Application *, const MI_Char *, const MI_Class *, MI_Instance **) __attribute__((stdcall))")]
        public IntPtr NewInstanceFromClass;

        [NativeTypeName("MI_Result (*)(MI_Application *, const MI_ClassDecl *, const MI_Char *, const MI_Char *, MI_Class **) __attribute__((stdcall))")]
        public IntPtr NewClass;
    }

@mikebattista
Copy link
Contributor

Delegates will need to be manually defined as with #796 and #983.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed usability Touch-up to improve the user experience for a language projection
Projects
None yet
Development

No branches or pull requests

3 participants