C++ example

 

Download

Download binaries here .

Download sources here .


Source Code

#include <windows.h>
#include <stdio.h>

#define ISL_LIGHT_DESK_EXE "ISLLightDesk.exe"
#define ISL_LIGHT_DESK_COMMAND_LINE "--get-code --username demo --password demo --notification-message %d --notification-thread %d --auto-close"
#define ISL_LIGHT_CLIENT_EXE "ISLLightClient.exe"
#define ISL_LIGHT_CLIENT_COMMAND_LINE "--connect %d --notification-message %d --notification-thread %d --auto-close"

void dump_notification_message(bool client, WPARAM wParam, LPARAM lParam) {
 printf("%s message (wparam 0x%x lparam 0x%x)\n", client?"Client":"Desk", wParam, lParam);
if (wParam == 0)
   printf("\tunconnected\n");
if (wParam & 1)
   printf("\tconnecting with session code %d\n", lParam);
if (wParam & 2)
   printf("\tconnected\n");
if (wParam & 4)
   printf("\tstreaming\n");
if (wParam & 8)
   printf("\treceiving strem\n");  
if (wParam & 0x10)
   printf("\tserver ID 0x%x\n", lParam);
if (wParam & 0x20)
   printf("\tsession ID 0x%x\n", lParam);  
if (wParam & 0x8000)
   printf("\terror getting the code\n");
}

int main(int argc, char **argv)
{
 MSG msg;
 // example doesnt have any windows
 // create message queue        
 PeekMessage(&msg, 0, 0, 0, PM_NOREMOVE);
 int count = 0;

 // start desk
 char arg_buff[2048];
 char desk_exe[256];
 char client_exe[256];

 sprintf(arg_buff, ISL_LIGHT_DESK_COMMAND_LINE, WM_USER+2, GetCurrentThreadId());
 if (argc >= 3) {
         strcpy(desk_exe, argv[1]);
         strcpy(client_exe, argv[2]);
 }
 else {
         strcpy(desk_exe, ISL_LIGHT_DESK_EXE);
         strcpy(client_exe, ISL_LIGHT_CLIENT_EXE);
 }
 printf("starting desk command line: %s\n",arg_buff);
 ShellExecute(NULL, NULL, desk_exe, arg_buff, NULL, SW_SHOW);

 // Main message loop:
 while (GetMessage(&msg, NULL, 0, 0))
 {
         if (msg.message == (WM_USER+2) || msg.message == (WM_USER+1)) { //notification message
                 bool client = msg.message == (WM_USER+1);
                 dump_notification_message(client, msg.wParam, msg.lParam);
                 if (!client && msg.wParam == 1) {
                         sprintf(arg_buff, ISL_LIGHT_CLIENT_COMMAND_LINE, msg.lParam, WM_USER+1, GetCurrentThreadId());
                         printf("starting client command line: %s\n",arg_buff);
                         ShellExecute(NULL, NULL, client_exe, arg_buff, NULL, SW_SHOW);                                
                 }

                 if (msg.wParam == 0) {
                         count --;
                         if (count <= 0)
                                 break;
                 }
                 if (msg.wParam == 1) { // assume connecting will succeed
                   count ++;
                 }
         } else {
                 TranslateMessage(&msg);
                 DispatchMessage(&msg);
         }
 }
}

Was this article helpful?