Skip to content
This repository has been archived by the owner on Jul 26, 2023. It is now read-only.

Request definitions for devguid.h and usbiodef.h. #393

Closed
ghost opened this issue Jun 13, 2018 · 10 comments
Closed

Request definitions for devguid.h and usbiodef.h. #393

ghost opened this issue Jun 13, 2018 · 10 comments

Comments

@ghost
Copy link

ghost commented Jun 13, 2018

This goes along with my other issue, #392. Is there a way to automatically generate these definitions, or should I manually fill in the ones I am going to use? Where should they go?

@AArnott
Copy link
Collaborator

AArnott commented Jun 14, 2018

Please review our contributing document for how to add APIs.

We welcome code contributions to add the APIs you're missing.

@ghost
Copy link
Author

ghost commented Jun 14, 2018

I don't mind doing some work myself but it seems like converting these headers will be a huge amount of work. I am surprised there is no tool that will do this in an automated fashion. There is the MSDN article program, but it can't handle whole files nor does it produce anything like what is in this repository.

@AArnott
Copy link
Collaborator

AArnott commented Jun 14, 2018

We discuss various code generation tools in #56. Short version: no tool is good enough.

@ghost
Copy link
Author

ghost commented Jun 18, 2018

How should the following structure be converted? The tool converts the latter element to a string.

typedef struct _USB_ROOT_HUB_NAME {
  ULONG ActualLength;
  WCHAR RootHubName[1];
} USB_ROOT_HUB_NAME, *PUSB_ROOT_HUB_NAME;
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct USB_ROOT_HUB_NAME
{
    public uint ActualLength;
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 1)]
    public string RootHubName;
}

The structure is allocated as a variable size with the extra length belonging to the character array. The IOCTL in question is called twice; first to get the proper length.

When used with the IOCT the generated structure works but I must adjust SizeConst. Which types are used to specify a dynamic element? I feel I've asked but going over the other issue I didn't find any good leads.

@qmfrederik
Copy link
Contributor

A first set of constants from devguid.h was added as part of #464 -- see SetupApi.DeviceSetupClass

@sgf
Copy link

sgf commented Jul 10, 2020

Since both C++ and C# are Turing complete, then there must be rules to follow between them. For example: IntPtr or SafeHandle, there must be certain rules for choosing which one. Since the rules can be judged manually, such rules can be described through tools (such as scripts). The SharpGen tool mentioned above has certain deficiencies. But as I understand it, this may require parsing C++ Ast. But such tools are not impossible. For some situations, I think the tool can provide some options for users to choose. This is similar to fine-tuning on the basis of automation, or specific preferences for certain C++ libraries or projects to customize settings.

@sgf
Copy link

sgf commented Jul 10, 2020

It is ridiculous to maintain a large number of libraries by humans.

@qmfrederik
Copy link
Contributor

@sgf You may be interested in https://github.com/microsoft/ClangSharp. It includes a ClangSharpPInvokeGenerator utility. Last time I checked, the project authors wanted to make sure ClangSharp can process the Win32 API.

If you plan to use that tool to auto-generate the bindings for devguid.h and usbiodef.h, and create PR based on the output of that tool, you could do so. Otherwise, I'm afraid the discussion is a bit off topic for this issue.

@sgf
Copy link

sgf commented Jul 10, 2020

If you plan to use that tool to auto-generate the bindings for devguid.h and usbiodef.h, and create PR based on the output of that tool, you could do so. Otherwise, I'm afraid the discussion is a bit off topic for this issue.

#455
Actually I raised the issue alone, but it was closed. I considered it before commenting, but there seem no open issues can be to discuss.

@sgf
Copy link

sgf commented Jul 10, 2020

Otherwise, I'm afraid the discussion is a bit off topic for this issue.

Maybe you are right, forget it, I gave up the discussion.

@AArnott AArnott closed this as completed Jul 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants