Skip to content

Commit d850e7d

Browse files
committed
build wfreerdp as a library with an optional interface
no console in release build (use logs instead) or windowless mode
1 parent 4cedc13 commit d850e7d

4 files changed

Lines changed: 137 additions & 6 deletions

File tree

‎client/Windows/wf_client.c‎

Lines changed: 121 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,9 +1201,16 @@ static BOOL wfreerdp_client_new(freerdp* instance, rdpContext* context)
12011201

12021202
#pragma region Myrtille
12031203

1204-
// no console in release build (use logs instead)
1204+
// no console in release build (use logs instead) or windowless mode
12051205
#if defined(WITH_DEBUG) || defined(_DEBUG)
1206-
wfc->isConsole = wf_create_console();
1206+
if (wfc->context.settings->MyrtilleShowWindow)
1207+
{
1208+
wfc->isConsole = wf_create_console();
1209+
}
1210+
else
1211+
{
1212+
wfc->isConsole = FALSE;
1213+
}
12071214
#else
12081215
wfc->isConsole = FALSE;
12091216
#endif
@@ -1391,3 +1398,115 @@ int RdpClientEntry(RDP_CLIENT_ENTRY_POINTS* pEntryPoints)
13911398

13921399
return 0;
13931400
}
1401+
1402+
#pragma region Myrtille
1403+
1404+
INT WINAPI StartRdpClient()
1405+
{
1406+
int status;
1407+
HANDLE thread;
1408+
wfContext* wfc;
1409+
DWORD dwExitCode;
1410+
rdpContext* context;
1411+
rdpSettings* settings;
1412+
LPWSTR cmd;
1413+
char** argv = NULL;
1414+
RDP_CLIENT_ENTRY_POINTS clientEntryPoints = { 0 };
1415+
int ret = 1;
1416+
int argc = 0, i;
1417+
LPWSTR* args = NULL;
1418+
1419+
//WINPR_UNUSED(hInstance);
1420+
//WINPR_UNUSED(hPrevInstance);
1421+
//WINPR_UNUSED(lpCmdLine);
1422+
//WINPR_UNUSED(nCmdShow);
1423+
1424+
#pragma region Myrtille
1425+
1426+
// if debugging, give time to attach debugger to process
1427+
//Sleep(10000);
1428+
1429+
#pragma endregion
1430+
1431+
RdpClientEntry(&clientEntryPoints);
1432+
1433+
context = freerdp_client_context_new(&clientEntryPoints);
1434+
if (!context)
1435+
return -1;
1436+
1437+
cmd = GetCommandLineW();
1438+
1439+
if (!cmd)
1440+
goto out;
1441+
1442+
args = CommandLineToArgvW(cmd, &argc);
1443+
1444+
if (!args || (argc <= 0))
1445+
goto out;
1446+
1447+
argv = calloc((size_t)argc, sizeof(char*));
1448+
1449+
if (!argv)
1450+
goto out;
1451+
1452+
for (i = 0; i < argc; i++)
1453+
{
1454+
int size = WideCharToMultiByte(CP_UTF8, 0, args[i], -1, NULL, 0, NULL, NULL);
1455+
if (size <= 0)
1456+
goto out;
1457+
argv[i] = calloc((size_t)size, sizeof(char));
1458+
1459+
if (!argv[i])
1460+
goto out;
1461+
1462+
if (WideCharToMultiByte(CP_UTF8, 0, args[i], -1, argv[i], size, NULL, NULL) != size)
1463+
goto out;
1464+
}
1465+
1466+
settings = context->settings;
1467+
wfc = (wfContext*)context;
1468+
1469+
if (!settings || !wfc)
1470+
goto out;
1471+
1472+
status = freerdp_client_settings_parse_command_line(settings, argc, argv, FALSE);
1473+
1474+
if (status)
1475+
{
1476+
freerdp_client_settings_command_line_status_print(settings, status, argc, argv);
1477+
goto out;
1478+
}
1479+
1480+
if (freerdp_client_start(context) != 0)
1481+
goto out;
1482+
1483+
thread = freerdp_client_get_thread(context);
1484+
1485+
if (thread)
1486+
{
1487+
if (WaitForSingleObject(thread, INFINITE) == WAIT_OBJECT_0)
1488+
{
1489+
GetExitCodeThread(thread, &dwExitCode);
1490+
ret = (int)dwExitCode;
1491+
}
1492+
}
1493+
1494+
if (freerdp_client_stop(context) != 0)
1495+
goto out;
1496+
1497+
out:
1498+
freerdp_client_context_free(context);
1499+
1500+
if (argv)
1501+
{
1502+
for (i = 0; i < argc; i++)
1503+
free(argv[i]);
1504+
1505+
free(argv);
1506+
}
1507+
1508+
LocalFree(args);
1509+
return ret;
1510+
}
1511+
1512+
#pragma endregion

‎client/Windows/wf_client.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ extern "C"
149149
#pragma region Myrtille
150150

151151
FREERDP_API DWORD WINAPI wf_client_thread(LPVOID lpParam);
152+
FREERDP_API INT WINAPI StartRdpClient();
152153

153154
#pragma endregion
154155

‎client/Windows/wf_myrtille.cpp‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,10 +220,16 @@ void wf_myrtille_start(wfContext* wfc)
220220
wfc->myrtille = (wfMyrtille*)calloc(1, sizeof(wfMyrtille));
221221
wfMyrtille* myrtille = (wfMyrtille*)wfc->myrtille;
222222

223-
#if !defined(WITH_DEBUG) && !defined(_DEBUG)
224223
// by default, redirect stdout and stderr to nothing (same as linux "/dev/null")
225-
freopen("nul", "w", stdout);
226-
freopen("nul", "w", stderr);
224+
#if defined(WITH_DEBUG) || defined(_DEBUG)
225+
if (!wfc->context.settings->MyrtilleShowWindow)
226+
{
227+
freopen("nul", "w", stdout);
228+
freopen("nul", "w", stderr);
229+
}
230+
#else
231+
freopen("nul", "w", stdout);
232+
freopen("nul", "w", stderr);
227233
#endif
228234

229235
// debug

‎cmake/ConfigOptions.cmake‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,12 @@ endif()
9292

9393
option(WITH_THIRD_PARTY "Build third-party components" OFF)
9494

95-
option(WITH_CLIENT_INTERFACE "Build clients as a library with an interface" OFF)
95+
# <Myrtille>
96+
# build wfreerdp as dll
97+
#option(WITH_CLIENT_INTERFACE "Build clients as a library with an interface" OFF)
98+
option(WITH_CLIENT_INTERFACE "Build clients as a library with an interface" ON)
99+
# </Myrtille>
100+
96101
option(WITH_SERVER_INTERFACE "Build servers as a library with an interface" ON)
97102

98103
option(WITH_DEBUG_ALL "Print all debug messages." OFF)

0 commit comments

Comments
 (0)