Comments (5)
Looking at HANDLE
, I see it already has a static Null
property and an instance IsNull
property.
Now, HANDLE has an IntPtr
field, and your subject line suggests you want this for nint
typedef structs. But nint
isn't necessarily a handle or pointer, so 'null' isn't a concept that directly applies to it.
Are there structs that are backed by nint
that should rather be treated like handles (thus backing with IntPtr
)? Can you name some so I can look into it?
Yes, yes, I know that syntactically IntPtr
and nint
is nearly identical nowadays. But IMO it's useful to maintain the semantic distinction.
from cswin32.
I think I am repeating myself without realizing I think we looked into it in #610.
Examples:
HIMC
HKL
I think we closed it previously because we wanted to be sure something was a handle vs just a pointer. So anything that was annotated as a handle already has the IsNull property.
from cswin32.
Yes, yes, I know that syntactically
IntPtr
andnint
is nearly identical nowadays. But IMO it's useful to maintain the semantic distinction.
This came up in the #csharp-lang-design channel in https://aka.ms/dotnet-discord. When some of us were making this point about a semantic distinction, one of the language design team members said:
No, it's literally not a meaningful distinction. It will be normalized for display. It's like int vs Int32.
(https://discord.com/channels/732297728826277939/732297994699014164/1104796983761322105)
from cswin32.
Thanks for sharing, @jnm2. I guess I'll just have to accept that.
Still, if we can tell from the metadata that a one typedef struct represents a pointer and another doesn't, I think it's fair to use that as an indicator to add IsNull
in one case and not in another.
After all, a handle could legitimately be 0 and still be valid, while a pointer couldn't be 0 and valid. So adding IsNull
in both cases could lead to misuse as code assumes IsNull
means it isn't valid, but for an opaque handle type, that isn't true.
from cswin32.
Duplicate of #610.
from cswin32.
Related Issues (20)
- Regression with `ReadFile` and `WriteFile` for `SafeHandle` HOT 1
- when wideCharOnly is true (default) specifying explicit ascii prefixed functions in NativeMethods.txt will result in it silently ignored
- IncludeAssets=all advice causes problems with NuGet packages HOT 7
- Why is `SHGetStockIconInfo` function is not supported by generator? HOT 1
- PROCESS_MITIGATION_REDIRECTION_TRUST_POLICY (I assume most PROCESS_MITIGATION_*) structs not fully generated HOT 2
- Using cswin32 projected types in class libraries results in CS0051 Inconsistent accessibility HOT 3
- CS8785 due to missing `System.Text.Encodings.Web` assembly in Dev16.11 HOT 4
- Size calculation with VariableLengthInlineArrays / More docs HOT 4
- GetModuleHandle with null parameter. HOT 2
- `FindFirstFileExFromApp` generate `void*` at `lpFindFileData` HOT 1
- How to create instance for `IDesktopWallpaper` COM interface HOT 3
- Add EntryPoint #865 IsElevationRequired HOT 1
- CS8785 when adding a locally built copy of Windows.Win32.winmd HOT 4
- structs with VariableLengthInlineArray and SizeOf(0) HOT 4
- CsWin32 generates `SafeHandle` parameter for `LPPROC_THREAD_ATTRIBUTE_LIST` in `CreateRemoteThreadEx` HOT 6
- SafeHandle overload should be generated for functions with `out` parameters HOT 5
- SetupDiGetDeviceInterfaceDetail() throws MashalDirectiveException "Pointers cannot reference marshaled structures" HOT 7
- COM Out arguments in DXGI/D3D11 are suddenly unmanaged HOT 4
- Publish WPF Desktop App not possible HOT 15
- IShellItemImageFactory.GetImage should return HRESULT HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cswin32.