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

Cannot convert type 'ObjCRuntime.NativeHandle' to 'void*' #13867

Closed
mattleibow opened this issue Jan 24, 2022 · 2 comments · Fixed by #13929
Closed

Cannot convert type 'ObjCRuntime.NativeHandle' to 'void*' #13867

mattleibow opened this issue Jan 24, 2022 · 2 comments · Fixed by #13929
Labels
need-info Waiting for more information before the bug can be investigated
Milestone

Comments

@mattleibow
Copy link
Contributor

mattleibow commented Jan 24, 2022

Steps to Reproduce

IntPtr handle = (IntPtr)1;

// working
void* t1 = (void*)handle;

// error
void* t2 = (void*)(ObjCRuntime.NativeHandle)handle;

Related missing method: IntPTr.ToInt64()

Expected Behavior

The code compiles.

Actual Behavior

error CS0030: Cannot convert type 'ObjCRuntime.NativeHandle' to 'void*' 

Environment

Build Logs

Example Project (If Possible)

@rolfbjarne
Copy link
Member

You can cast to IntPtr before casting to void *:

void *t2 = (void*) (IntPtr) handle;

Also, what's the use-case scenario here? Why do you need a void *?

@rolfbjarne rolfbjarne added the need-info Waiting for more information before the bug can be investigated label Jan 25, 2022
@rolfbjarne rolfbjarne added this to the .NET 6 milestone Jan 25, 2022
@mattleibow
Copy link
Contributor Author

My use case was that I have a C++ API that wanted the handle to a Metal texture. I could use IntPtr on that, but right now my generator outputs void*. This is not a hard technical requirement, but not having to do anything is way better than doing something :)

rolfbjarne added a commit to rolfbjarne/xamarin-macios that referenced this issue Jan 27, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Apr 26, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
need-info Waiting for more information before the bug can be investigated
Projects
None yet
2 participants