Update: UltraVNC 1.4.3.6 and UltraVNC SC 1.4.3.6: viewtopic.php?t=37885
Important: Please update to latest version before to create a reply, a topic or an issue: viewtopic.php?t=37864

Join us on social networks and share our announcements:
- Website: https://uvnc.com/
- GitHub: https://github.com/ultravnc
- Mastodon: https://mastodon.social/@ultravnc
- Facebook: https://www.facebook.com/ultravnc1
- X/Twitter: https://twitter.com/ultravnc1
- Reddit community: https://www.reddit.com/r/ultravnc
- OpenHub: https://openhub.net/p/ultravnc

Start_viewer under Delphi Now Working

Post Reply
xrxca
8
8
Posts: 11
Joined: 2004-11-15 20:59

Start_viewer under Delphi Now Working

Post by xrxca »

Oh so close, having built a tiny test program in delphi to start the Viewer, the viewer starts, connects, and runs fine, but I never get any of the messages I expect based on the pchelpware.cpp source code. (WM_SYSCOMMAND with WM_USER+13 in the wParam) I've traced every message going to my program, and I never get the message that the pchelpware_viewer gets (I traced it's messages and it the messages stand out pretty obviously)
As a result I'm unable to restart the viewer listen process when it stops.

Too bad there wasn't a bit more info in the debug output, like just what file it's looking for hen it says it cant find a file, or what it's trying to access when it says access denied.

(Edited to drop a bunch of the questions as I've got it working)
Last edited by xrxca on 2007-03-11 00:29, edited 1 time in total.
xrxca
8
8
Posts: 11
Joined: 2004-11-15 20:59

Re: Start_viewer under Delphi (almost)

Post by xrxca »

OK, turns out it's the window classname that's the key, as soon as I overrode the default classname of my main form with 'PcHelpWare Control Viewer' I started getting the messages I was looking for.

Is there any way to specify the class name the library looks for?

The following is code for a demo of simple listen on port in delphi 6, it works, but is very basic, and I should probably have it create a 'cache' directory as the viewer seems to use it if it's there.
I limited the port used to non privileged ports (>=1024) from habit although since it's Windows I probably didn't have to.

Next stop: try wrapping the whole thing in it's own component using a hidden window with the correct classname to handle the messages so the main program doesn't need to deal with it, just OnConnected and OnStopped events.

TForm named ViewerDemoForm with
2 TButtons: btnStart and btnStop;
and 2 TEdits: editPort and editPwd;

Code: Select all

unit ViewerUnit;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TStartViewer = function(RepeaterID, HostName: PChar;
                          ListenPort, ViewerPort: Integer;
                          Password: PChar; Debug: LongBool;
                          Http: LongBool; BandWidth: Byte;
                          DirectX: LongBool): LongBool; cdecl;
  TViewerDemoForm = class(TForm)
    btnStart: TButton;
    btnStop: TButton;
    editPort: TEdit;
    editPwd: TEdit;
    procedure CreateParams(var Params: TCreateParams); override;
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure btnStopClick(Sender: TObject);
    procedure btnStartClick(Sender: TObject);
    procedure WMSysCommand(var Msg: TWMSysCommand); message WM_SYSCOMMAND;
  private
    StartViewer: TStartViewer;
    DLLHandle: THandle;
  end;

var
  ViewerDemoForm: TViewerDemoForm;

const
    PHW_ClassName = 'PcHelpWare Control Viewer';
    DLLName = '1SCVDLL.dll';
    ViewerExport = 'Start_viewer';
    TitleOffline = 'Viewer Demo';
    TitleListening = 'Viewer Listening';
    TitleConnected = 'Viewer Connected';
    SC_VIEWERSTOPPED = WM_USER + 13;
    SC_VIEWERCONNECTED = WM_USER + 14;

implementation

{$R *.dfm}

procedure TViewerDemoForm.CreateParams(var Params: TCreateParams);
begin
  inherited;
  StrCopy(Params.WinClassName, PHW_ClassName);
end;

procedure TViewerDemoForm.FormCreate(Sender: TObject);
begin
    btnStop.Enabled := False;
    btnStart.Enabled := False;
    DLLHandle := LoadLibrary(DLLName);
    if ( DLLHandle = 0 ) then begin
        ShowMessage('Unable to load library: ' + DLLName);
    end else begin
        @StartViewer := GetProcAddress(DLLHandle, ViewerExport);
        if ( @StartViewer = nil ) then begin
            ShowMessage('Error Finding Export Address: ' + ViewerExport);
            FreeLibrary(DLLHandle);
            DLLHandle := 0;
        end else begin
            btnStart.Enabled := True;
        end;
    end;
end;

procedure TViewerDemoForm.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
    if ( btnStop.Enabled ) then begin
        btnStopClick(Sender);
    end;
    if ( DLLHandle <> 0 ) then begin
        FreeLibrary(DLLHandle);
    end;
end;

procedure TViewerDemoForm.WMSysCommand(var Msg : TWMSysCommand) ;
begin
    case Msg.CmdType of
        SC_VIEWERSTOPPED: begin
                ViewerDemoForm.Caption := TitleOffline;
                btnStart.Enabled := True;
                btnStop.Enabled := False;
            end;
        SC_VIEWERCONNECTED: begin
                ViewerDemoForm.Caption := TitleConnected;
            end;
    else
        inherited;
    end;
end;

procedure TViewerDemoForm.btnStopClick(Sender: TObject);
begin
    StartViewer('', '', 0, 0, '', False, False, 99, False);
end;

procedure TViewerDemoForm.btnStartClick(Sender: TObject);
var
    Port: Integer;
begin
    try
        Port := StrToInt(editPort.Text);
        If ( ( Port < 1024 ) or ( Port > 65534 ) ) then
            raise ERangeError.Create('Invalid Port Number');
    except
        ShowMessage('Invalid Port Specified');
        Exit;
    end;
    if ( editPwd.Text = '' ) then begin
        ShowMessage('No Password Specified');
        Exit;
    end;
    try
        StartViewer('', '', Port, 0, PChar(editPwd.Text), False, False, 1, True);
        ViewerDemoForm.Caption := TitleListening;
        btnStart.Enabled := False;
        btnStop.Enabled := True;
    except
        ShowMessage('Error Starting Viewer');
    end;
end;

end.
Post Reply