Couldn't find shorter than this. For some reason, C# really doesn't like converting char* to byte* d
Couldn't find shorter than this. For some reason, C# really doesn't like converting char* to byte* directly.
9 Replies
I'm not sure it will work. It does compile, but I'm worried it might only use the element at the given address rather than the collection.
Ah crap, I forgot about the conversion to UTF8. Might implode.
Wait does GetBytes not work?
Seems like it is just the thing you want.
Doesn't work

the def of ApplicationName

Encoding.UTF8.GetBytes()
can take a string and return a byte array.
If you still need that as a pointer, you can probably use fixed
after that.
Maybe this?
It looks like the compiler prevents you to assign ApplicationName outside of a fixed
block.
You'll probably have to play with that.
If the byte pointer doesn't work, you can probably make a dummy fixed
block and do ApplicationName = Encoding.UTF8.GetBytes("AppName");
directly inside.It doesn't even recognize this as a variable?

🤔
In the OpenXR example, they just use a usual C++ strcpy for this
https://github.com/KhronosGroup/OpenXR-SDK-Source/blob/f680f8d1fd51c0524d6742c4c3657038cc4a860a/src/tests/hello_xr/openxr_program.cpp#L232
GitHub
OpenXR-SDK-Source/openxr_program.cpp at f680f8d1fd51c0524d6742c4c36...
Sources for OpenXR loader, basic API layers, and example code. - OpenXR-SDK-Source/openxr_program.cpp at f680f8d1fd51c0524d6742c4c3657038cc4a860a · KhronosGroup/OpenXR-SDK-Source
Yeah, that's a C standard function for copying characters of a string from an address to another. You'd just assign a value to a string in C#, but the issue here is the
fixed
keyword.
Looking up the issue right now.I think this is because
ApplicationName
is actually directly part of the containing struct, it isn't a pointer that can be assigned
Such an assignment would require a full copy