convert void* to UIntPtr(windows runtime type)
-
Monday, April 23, 2012 6:29 PM
Hi,
I am developing a WinRT c++ component.
I have a buffer of type void* and i want get this buffer to a C# metro app.
so i want to change the this void* buffer to windows runtime type UIntPtr.
how to do this...any sample code really helps.
thanks,
Bhash
All Replies
-
Monday, April 23, 2012 9:38 PM
*reinterpret_cast<Platform::UIntPtr*>(&myVoidPtr);
The documentation says UIntPtr is a ValueType, so I have to assume that this will work. I can't make any promises though. Even if it works now, the documentation doesn't says anything about it, so it may not in the future.It's a good think they aren't checking wait chains to prevent blocking the UI thread for an asynchronous task.
- Proposed As Answer by brentAtBrainium Monday, April 23, 2012 9:38 PM
- Marked As Answer by Jesse JiangMicrosoft Contingent Staff, Moderator Monday, May 07, 2012 2:34 AM
-
Monday, April 23, 2012 11:39 PM
I have tried this code snippet and it does not work.. I am also looking for a way to include a void* pointer within the WinRT component so that I can use it from my C# Metro App. For the first line "*reinterpret_cast<Platform::UIntPtr*>(&myVoidPtr);" , it says "Error: Expected an identifier"
For Line 2 " void* d;" I'm getting Error: signature of member contains native type 'void *'
What error am i making?
Thanks!
public value struct t { *reinterpret_cast<Platform::UIntPtr*>(&myVoidPtr); // Does this work? void* d; // Does this work? uint32 f; };
-
Tuesday, May 01, 2012 5:43 PM
That's just a cast. You can't have a cast by itself, you have to assign it to something:
Platform::UIntPtr result = *reinterpret_cast<Platform::UIntPtr*>(&myVoidPtr);
or, of course, return it from a method:
return *reinterpret_cast<Platform::UIntPtr*>(&myVoidPtr);
Standard C++ stuff, really.
Software Engineer, Brainium Studios LLC


