Ir al contenido principal

C++ Platform::String^ object to const wchar_t* conversion

In Windows Store applications, for example when you want to make a shared library, it is necessary to make use of common types like Platform::String. All the public types must be types from Windows Runtime to make it possible a cross language usage of your libraries (C++, JavaScript, C#, VB).

But when you want to use the C++ standard types like wchar_t or std::wstring, you're going to need a temporary conversion from Windows Runtime types to C++ Standard types.

You can access the string value of a Platform::String^ object by using the Data() method like this:

Platform::String^ ps3DModel(L"Gear");
std::wstring _3DModel = ps3DModel->Data();


Now, you can use the _3DModel std::wstring like another C++ standard string by using his own methods. Also, you could have converted to a "const wchar_t type":


const wchar_t * _3DModel = ps3DModel->Data();

The problem is when you want to make any changes into the ps3DModel Platform::String object since this is inmutable. What you mus to do is make a copy of the string into a std::wstring object and them modify it according to your needs. Later, when you must save the changes into the Platform::String object, you must create as a new "ref new Platform::String^". But better, let's see this with a small example:


// We create the Platform::String object
Platform::String^ ps3DModel(L"Gear");

// Now, we copy the string into a new wstring object
std::wstring _3DModel = ps3DModel->Data();

// Here we make some changes
_3DModel = L"_GEAR_";

// An finally, we put the changes into the original 'ps3DModel' object
ps3DModel = ref new Platform::String(_3DModel.c_str());

Comentarios

Entradas populares de este blog

Como usar el TL431 (muy facil)

En este artículo, no vamos a entrar en el funcionamiento interno de este IC, ni tampoco en sus características técnicas, puesto que para esos fines ya existe su hoja de datos correspondiente. Más bien, lo que pretendo aquí es dejar constancia de como podemos utilizar este IC desde un punto de vista práctico, útil y sobre todo de una manera sencilla, con el objetivo de que cualquiera pueda utilizarlo. Si has llegado hasta aquí, probablemente ya sabes que por internet hay mucha información sobre este IC, pero también bastante confusa o excesivamente técnica, sin mostrar tan siquiera un ejemplo de funcionamiento, o como calcular sus pasivos. Pues se acabó, a partir de hoy y después de leer este post, ya te quedará claro como utilizar el TL431 para obtener una tensión de referencia estable y precisa. Vamos al grano y que mejor que empezar aclarando que el TL431 NO ES EXACTAMENTE UN ZENER como se empeñan en decir en muchos sitios, es verdad que se le conoce como el Zener Progra...

I designed a PCB Holder

If you're one of those people who like electronics, then you know how frustrating it can be when you need to hold a PCB for soldering a component. Download Link: https://www.thingiverse.com/thing:1103401 That was my case when I decided to make a stand PCB. First I was looking at what was available in the market (Weller by example), in order to have some reference on which to base my design. Finally, I decided on a type of support that allows to turn the PCB in order to be able to have easy access to both sides of it. The hardest part was to design the clamping mechanism. In the end I think I found a good solution, based on three springs that allow the PCB firmly secure but at the same time release with little effort, to rotate if necessary. Here you can download all files you need to make my PCB Holder: https://www.thingiverse.com/thing:1103401

El Robin Hood de los procesos pobres (Vamos de escalada)

Pues sí, has leído bien, hoy nos vamos de escalada, pero ojo! No nos vamos a las montañas, nos vamos al interior, al kernel del sistema operativo Windows 10 en esta ocasión, aunque es aplicable a otras versiones con algunos mínimos cambios. Hoy la cosa va de EoP (Elevation of Privilege), escalada de privilegios en el sistema. Vamos a ver cómo hacer de Robin Hood para "mangarle" el “Access Token” al usuario "NT AUTHORITY\SYSTEM" a través de la estructura _EPROCESS del proceso “System” para dárselo al pobre CMD.EXE. ¿Con qué fin? Pues darle poder absoluto sobre el sistema a un usuario limitado, por ejemplo para que pueda utilizar la calculadora, o el notepad sin limitaciones :) Venga vale, que es broma, que en realidad será para utilizarlo en una shellcode y un driver de dispositivo firmado por alguien :) Antes  de  comenzar  hay  que  dejar  claro  que  vamos  a  necesitar  algunas herramientas para realizar este proce...