You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Documentation Improvements around Customizing generated code #606
The documentation does not outline exactly how to split the NativeMethods.txt into multiple files. It just says that it is possible.
Additionally, the documentation lists possible ways to customize generated code, but again doesn't list the appropriate settings for the NativeMethods.json.
For the NativeMethods.txt, do you just name them like *.NativeMethods.txt or do the files need to be named all NativeMethods.txt but in separate directories?
Edit:
Looking at the code and reading it more carefully, it does look like they have to be in separate directories, would you consider adding support for multiple files if named in the style of *.NativeMethods.txt? I guess support for additional files named that way, or project root would be great.
We don't recommend splitting NativeMethods.txt up. At least, I haven't come across any scenario where it would be beneficial. I heard someone suggest a couple weeks ago that perhaps one in each feature directory of a library would make sense, where the APIs used by that feature would be listed. But that's not really sustainable because there is no enforcement, and it would be a lot of extra bookkeeping on the part of the consumer to try to avoid using APIs that weren't asked for in their local file.
The reason we support multiple files is for Shared Project scenarios, where legitimately shared code requires p/invokes and should carry its own NativeMethods.txt file so that anyone who consumes the Shared Project will automatically generate the APIs it needs.
But yes, we could document it better.
The nativemethods.json isn't documented much except to include the $schema field, which is all you need in VS to get Intellisense in the file with docs that teach you what is available and what it does. Have you found that to be insufficient?
Thanks, that all makes sense. Possibly append the multiple NativeMethods.txt section with your recommendation above?
In Winforms, the idea was to have a NativeMethods.txt file in each interop dll directory. I imagine the txt file will end up being several thousands of lines long if it was centralized. Is the idea of breaking the files up per import library not a good idea?
the idea was to have a NativeMethods.txt file in each interop dll directory
Would you still have a whole directory per each interop dll if CsWin32 was generating most of the code? Ideally, you have little or no interop to write yourself, unless you're writing a higher level set of classes.
Activity
elachlan commentedon Jul 19, 2022
For the
NativeMethods.txt, do you just name them like*.NativeMethods.txtor do the files need to be named allNativeMethods.txtbut in separate directories?Edit:
Looking at the code and reading it more carefully, it does look like they have to be in separate directories, would you consider adding support for multiple files if named in the style of
*.NativeMethods.txt? I guess support for additional files named that way, or project root would be great.AArnott commentedon Jul 19, 2022
We don't recommend splitting NativeMethods.txt up. At least, I haven't come across any scenario where it would be beneficial. I heard someone suggest a couple weeks ago that perhaps one in each feature directory of a library would make sense, where the APIs used by that feature would be listed. But that's not really sustainable because there is no enforcement, and it would be a lot of extra bookkeeping on the part of the consumer to try to avoid using APIs that weren't asked for in their local file.
The reason we support multiple files is for Shared Project scenarios, where legitimately shared code requires p/invokes and should carry its own NativeMethods.txt file so that anyone who consumes the Shared Project will automatically generate the APIs it needs.
But yes, we could document it better.
The nativemethods.json isn't documented much except to include the
$schemafield, which is all you need in VS to get Intellisense in the file with docs that teach you what is available and what it does. Have you found that to be insufficient?elachlan commentedon Jul 19, 2022
Thanks, that all makes sense. Possibly append the multiple
NativeMethods.txtsection with your recommendation above?In Winforms, the idea was to have a NativeMethods.txt file in each interop dll directory. I imagine the txt file will end up being several thousands of lines long if it was centralized. Is the idea of breaking the files up per import library not a good idea?
AArnott commentedon Jul 20, 2022
Would you still have a whole directory per each interop dll if CsWin32 was generating most of the code? Ideally, you have little or no interop to write yourself, unless you're writing a higher level set of classes.
elachlan commentedon Jul 20, 2022
The winforms team looks like it will go with a single
NativeMethods.txt.That being said, In Winforms
IHandleis used on forms/controls/etc to provide access to the objects Handle. Winforms then has code like this:I brought this up in #602. It was suggested there was an alternative way using a struct.
I suspect the winforms team will want to keep this structure. So the per interop dll folders might end up staying.
If CsWin32 provided a similar interface and methods, then I'd image the folders wouldn't be needed.
AArnott commentedon Jul 20, 2022
Thanks. We are still reviewing the IHandle proposal. Not sure what CsWin32 will do to help with that yet.
Beef up NativeMethods.txt documentation