Hola estoy intentando crear un escritorio del siguiente modo:
#include <iostream>
using namespace std;
#include "Windows.h"
#pragma comment(lib, "Rpcrt4")
#define RAND_DESK_NAME 0x000040
template <class TCHAR>
class MakeNewDesktop
{
public:
MakeNewDesktop();
bool generateUUID(LPVOID buffer, DWORD sz);
bool setDeskName(TCHAR *name);
void SwitchToNew();
void SwitchToDefault() const;
private:
bool Create();
public:
private:
TCHAR DeskName[40];
int randName;
bool b_ok;
UUID bUuid;
RPC_WSTR rstrUUID;
HDESK hDeskNew;
HDESK hDeskOld;
protected:
};
template <class TCHAR>
MakeNewDesktop<TCHAR>::MakeNewDesktop() : randName(0), rstrUUID(nullptr), hDeskNew(nullptr),
hDeskOld(nullptr), b_ok(false)
{
}
template <class TCHAR>
bool MakeNewDesktop<TCHAR>::generateUUID(LPVOID buffer, DWORD sz)
{
// vamos a Generar El Indentificador Universal unico
if (UuidCreate(&bUuid) == RPC_S_OK) b_ok = true;
else return false;
if (b_ok != false && UuidToStringW(&bUuid, &rstrUUID) == RPC_S_OK)
{
// copiamos el numero de caracteres que requiere el buffer
lstrcpynW(LPWSTR(buffer), LPCWSTR(rstrUUID), sz);
return true;
}
return false;
}
template <class TCHAR>
bool MakeNewDesktop<TCHAR>::setDeskName(TCHAR* name)
{
if (name == NULL || ua_lstrlenW(name) > 40) return false;
else lstrcpynW(DeskName, name, lstrlenW(name) + 1);
return true;
}
template <class TCHAR>
bool MakeNewDesktop<TCHAR>::Create()
{
b_ok = false;
if (randName != false || DeskName == FALSE)
generateUUID(DeskName, 40);
if (DeskName != NULL && hDeskNew == NULL)
{
hDeskOld = GetThreadDesktop(GetCurrentThreadId()); // obtenemos el manejdor de el escritorio actual
hDeskNew = CreateDesktopW(DeskName, NULL, NULL, 0, GENERIC_ALL, NULL); // creamos el nuevo
if (hDeskOld != NULL && hDeskNew != NULL)
{
WCHAR explore[MAX_PATH];
ExpandEnvironmentStringsW(L"%windir%\\explorer.exe", explore, MAX_PATH - 1);
STARTUPINFOW startup_info = { 0 };
PROCESS_INFORMATION process_info = { 0 };
if (SetThreadDesktop(hDeskNew))
{
startup_info.cb = sizeof(startup_info);
startup_info.lpDesktop = DeskName;
CreateProcessW(explore, NULL, NULL, NULL, FALSE, 0, NULL, NULL, &startup_info, &process_info);
SetThreadDesktop(hDeskOld);
}
}
b_ok = true;
}
return b_ok;
}
template <class TCHAR>
void MakeNewDesktop<TCHAR>::SwitchToNew()
{
if ((Create() != NULL))
{
SetThreadDesktop(hDeskNew);
SwitchDesktop(hDeskNew);
}
}
template <class TCHAR>
void MakeNewDesktop<TCHAR>::SwitchToDefault() const
{
SwitchDesktop(hDeskOld);
CloseHandle(hDeskNew);
}
typedef MakeNewDesktop<wchar_t> MakeDeskW;
int main()
{
MakeDeskW newDesk;
newDesk.setDeskName(L"Selene-PC");
newDesk.SwitchToNew();
Sleep(9000);
newDesk.SwitchToDefault();
return 0;
}
Sin embargo siempre me devuelve los mismos errores:
||=== Build: Debug in desktop (compiler: GNU GCC Compiler) ===|
C:\Users\ \Desktop\desktop\main.cpp|5|warning: ignoring #pragma comment [-Wunknown-pragmas]|
C:\Users\ \Desktop\desktop\main.cpp|39|warning: identifier 'nullptr' is a keyword in C++11 [-Wc++0x-compat]|
C:\Users\ \Desktop\desktop\main.cpp|30|error: 'RPC_WSTR' does not name a type|
C:\Users\ \Desktop\desktop\main.cpp||In constructor 'MakeNewDesktop::MakeNewDesktop()':|
C:\Users\ \Desktop\desktop\main.cpp|39|error: class 'MakeNewDesktop' does not have any field named 'rstrUUID'|
C:\Users\ \Desktop\desktop\main.cpp|39|error: 'nullptr' was not declared in this scope|
C:\Users\ \Desktop\desktop\main.cpp||In member function 'bool MakeNewDesktop::generateUUID(LPVOID, DWORD)':|
C:\Users\ \Desktop\desktop\main.cpp|52|error: 'rstrUUID' was not declared in this scope|
C:\Users\ \Desktop\desktop\main.cpp||In function 'int main()':|
C:\Users\ \Desktop\desktop\main.cpp|129|warning: deprecated conversion from string constant to 'wchar_t*' [-Wwrite-strings]|
C:\Users\ \Desktop\desktop\main.cpp||In instantiation of 'MakeNewDesktop::MakeNewDesktop() [with TCHAR = wchar_t]':|
C:\Users\ \Desktop\desktop\main.cpp|128|required from here| C:\Users\ \Desktop\desktop\main.cpp|32|warning: 'MakeNewDesktop::hDeskOld' will be initialized after [-Wreorder]|
C:\Users\ \Desktop\desktop\main.cpp|28|warning: 'bool MakeNewDesktop::b_ok' [-Wreorder]|
C:\Users\ \Desktop\desktop\main.cpp|39|warning: when initialized here [-Wreorder]|
C:\Users\ \Desktop\desktop\main.cpp||In instantiation of 'bool MakeNewDesktop::setDeskName(TCHAR*) [with TCHAR = wchar_t]':|
C:\Users\ \Desktop\desktop\main.cpp|129|required from here|
C:\Users\ \Desktop\desktop\main.cpp|65|error: 'ua_lstrlenW' was not declared in this scope|
C:\Users\ \Desktop\desktop\main.cpp||In instantiation of 'void MakeNewDesktop::SwitchToNew() [with TCHAR = wchar_t]':|
C:\Users\ \Desktop\desktop\main.cpp|130|required from here|
C:\Users\ \Desktop\desktop\main.cpp|108|warning: NULL used in arithmetic [-Wpointer-arith]|
||=== Build failed: 5 error(s), 13 warning(s) (0 minute(s), 1 second(s)) ===|
Como podría solucionar esto ya que no entiendo bien puesto que he seguido las indicaciones y debería funcionar.