xsharp.eu • Let's get this started
Page 1 of 3

Let's get this started

Posted: Thu Nov 15, 2018 12:53 pm
by ThomasVenus
Hi Folks,
after a long time of just looking at X# (even as a Fox subscriber since last the last conference) I finally started
to have a close look. :)
This will for sure cost a lot of time but i think it is worth the effort.

Just now I'm stuck with the followin little problem.
In VO these two lines brings up the default browser and shows the image of a ip-camera:
cCommandstring := "http://123.456.789.000:xxx/cgi-bin/CGIProxy.fcgi?cmd=snapPicture2&usr=xxx&pwd=xxxx"
ShellExecute(0, psz("open"), psz(cCommandString), NULL_PSZ , ;
NULL_PSZ , ;
SW_SHOWMAXIMIZED )
How can this be done in X#?
The final goal would be to store the image as jpg-file instead of just diplaying it.

Looking foward to a good time with X#

greetings
Thomas

Let's get this started

Posted: Thu Nov 15, 2018 2:34 pm
by FFF
Thomas,
System.Diagnostics.Process.Start( "C:Program FilesMozilla Firefoxfirefox.exe", "google.com") opens Google.
etc.

Karl

Let's get this started

Posted: Thu Nov 15, 2018 4:28 pm
by Chris
Hi Thomas,

First of all, the exact same code should compile and run fine in X#, by simply referencing the Win32 SDK dll in your app. Secondly, you can use the "more .Net" version of the same thing that Karl provided. And thirdly, you can use one of the dedicated web related classes that are offered in the .Net framework for using http, ftp, mail etc in a very powerful OOP way. Unfortunately I have very little experience with them, somebody else may chip in with more detailed advice using those.

Chris

Let's get this started

Posted: Thu Nov 15, 2018 4:30 pm
by Chris
Hi Thomas,

First of all, the exact same code should compile and run fine in X#, by simply referencing the Win32 SDK dll in your app. Secondly, you can use the "more .Net" version of the same thing that Karl provided. And thirdly, you can use one of the dedicated web related classes that are offered in the .Net framework for using http, ftp, mail etc in a very powerful OOP way. Unfortunately I have very little experience with them, somebody else may chip in with more detailed advice using those.

Chris

Let's get this started

Posted: Thu Nov 15, 2018 6:31 pm
by FFF
Chris,
i copied Thomas' lines in the Start of a newly created VO-MDI app,
like
VAR cCommandstring := "http://123.456.789.000:xxx/cgi-bin/CGIProxy.fcgi?cmd=snapPicture2&usr=xxx&pwd=xxxx"
ShellExecute(0,String2Psz("open"), String2Psz(cCommandString), NULL_String , ;
NULL_String , ;
1 )
first got warnings that the PSZ could provide leaks, replaced them with the suggestet String2PSZ, but then got strange error as
error XS0103: The name 'Xs$Return' does not exist in the current context 3,1 Start.prg MdiApp1
Line 3 being the Function Start() one.
??

Have the Win32Library referenced, how would i add the Win32SDK (as it is not listed in the dialog?

Karl

Let's get this started

Posted: Thu Nov 15, 2018 6:54 pm
by SHirsch
Hi Thomas,

For VO this may help (not tested in X# yet):

Code: Select all

oHttp := CHttp{}
oHttp:ConnectRemote("http://123.456.789.000:xxx", sUser, sPsw) 
oHttp:GetFile("cgi-bin/CGIProxy.fcgi?cmd=snapPicture2&usr=xxx&pwd=xxxx", sDestFile, FALSE) 
oHttp:CloseRemote()
In your case 'sUser' and 'sPsw' could be empty. Some error handling should be implemented ( I removed this for better readability).


Stefan

Let's get this started

Posted: Thu Nov 15, 2018 9:24 pm
by lumberjack
Hi Thomas,
ThomasVenus wrote:Hi Folks,
In VO these two lines brings up the default browser and shows the image of a ip-camera:
cCommandstring := "http://123.456.789.000:xxx/cgi-bin/CGIProxy.fcgi?cmd=snapPicture2&usr=xxx&pwd=xxxx"
ShellExecute(0, psz("open"), psz(cCommandString), NULL_PSZ , ;
NULL_PSZ , ;
SW_SHOWMAXIMIZED )
How can this be done in X#?
The final goal would be to store the image as jpg-file instead of just diplaying it.
Please have a look at System.Net.WebClient class of .net
Think you will find everything there that you need.
Regards,

Let's get this started

Posted: Thu Nov 15, 2018 9:31 pm
by lumberjack
Hi Thomas,
Not near my laptop with example of http, but here is hopefully something to get you going. It is reading the directory structure of a ftp site:

Code: Select all

METHOD UpgradeCheck() AS VOID
	LOCAL wc AS WebClient
	LOCAL nc AS NetworkCredential
	LOCAL fwr, fwd AS WebRequest
	LOCAL sr AS StreamReader
	LOCAL enumerator AS IEnumerator
	LOCAL aDirectory, aStr AS STRING[]
	LOCAL aFolders AS Stack<STRING>
	LOCAL s, sName, sFolder, sTmp, sApp, sEnv AS STRING
	LOCAL nIndex AS INT

	nc := NetworkCredential{"eval", "demo"}
	wc := WebClient{}
	wc:Credentials := nc
	wc:BaseAddress := SELF:oIni:GetString("__servers", SELF:cEnvironment)

	TRY
		SELF:aAppFolders := Stack<STRING>{}
		SELF:aFiles := Stack<STRING>{}
		aFolders := Stack<STRING>{}
		sFolder := ""
		SELF:slbAction:Text := "Checking application folder layout..."
		REPEAT
			fwr := WebRequest.Create(wc:BaseAddress + sFolder)
			fwr:Credentials := nc
			fwr:@@Method := WebRequestMethods.Ftp.ListDirectoryDetails
			sr := StreamReader{fwr:GetResponse():GetResponseStream()}
			aDirectory := sr:ReadToEnd():Split((CRLF):ToCharArray(), StringSplitOptions.RemoveEmptyEntries)
HTH,

Let's get this started

Posted: Thu Nov 15, 2018 10:03 pm
by Chris
Hi Karl,
FFF wrote:Chris,
i copied Thomas' lines in the Start of a newly created VO-MDI app,
like
VAR cCommandstring := "http://123.456.789.000:xxx/cgi-bin/CGIProxy.fcgi?cmd=snapPicture2&usr=xxx&pwd=xxxx"
ShellExecute(0,String2Psz("open"), String2Psz(cCommandString), NULL_String , ;
NULL_String , ;
1 )
first got warnings that the PSZ could provide leaks, replaced them with the suggestet String2PSZ, but then got strange error as
error XS0103: The name 'Xs$Return' does not exist in the current context 3,1 Start.prg MdiApp1
Line 3 being the Function Start() one.
??

Have the Win32Library referenced, how would i add the Win32SDK (as it is not listed in the dialog?

Karl
Yes, that's what I meant, to reference the Win32Library. About the error, I did not get it in my tests, can you please show the complete code you used?

Let's get this started

Posted: Thu Nov 15, 2018 10:13 pm
by FFF
New Vo-Mdi Sample, then:

Code: Select all

#include "VOGUIClasses.vh"

FUNCTION Start( asCmdLine AS STRING[] ) AS INT
	
	LOCAL nExitCode AS INT
	
	LOCAL oMainWindow AS StandardShellWindow
	LOCAL oApp AS App
	
	RDDSetDefault( "DBFCDX" )
	
	nExitCode := 0
	
	oApp := App{}
	oMainWindow := StandardShellWindow{oApp}
	oMainWindow:Show(SHOWCENTERED)                            
VAR	cCommandstring := "http://123.456.789.000:xxx/cgi-bin/CGIProxy.fcgi?cmd=snapPicture2&usr=xxx&pwd=xxxx"
ShellExecute(0,String2Psz("open"), String2Psz(cCommandString), NULL_String , ;
NULL_String , ;
1 )  
	oApp:Exec()
		
RETURN nExitCode