pinvoke icon indicating copy to clipboard operation
pinvoke copied to clipboard

Request definitions for devguid.h and usbiodef.h.

Open ghost opened this issue 7 years ago • 10 comments

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?

ghost avatar Jun 13 '18 23:06 ghost

Please review our contributing document for how to add APIs.

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

AArnott avatar Jun 14 '18 00:06 AArnott

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.

ghost avatar Jun 14 '18 03:06 ghost

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

AArnott avatar Jun 14 '18 04:06 AArnott

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.

ghost avatar Jun 18 '18 16:06 ghost

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

qmfrederik avatar Jul 06 '20 20:07 qmfrederik

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 avatar Jul 10 '20 18:07 sgf

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

sgf avatar Jul 10 '20 18:07 sgf

@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.

qmfrederik avatar Jul 10 '20 20:07 qmfrederik

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.

https://github.com/dotnet/pinvoke/issues/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 avatar Jul 10 '20 20:07 sgf

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.

sgf avatar Jul 10 '20 20:07 sgf