Pocket Control PC - PC v1.1 ReadMe 4. For Developpers |  |
The source is in Visual Basic .NET and is based on .Net Framework. I developped the application on a computer with .Net Framework 1.1, .Net Framework SDK installed. The source of the whole application is found in the .vb files. I compile the source using the vbc.exe with the command prompt. On my PC, vbc.exe was found at C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\vbc.exe. To compile: Open a command prompt, and type something like the following in one line:
"C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\vbc.exe" /out:"C:\Documents and Settings\Kingherc\My Documents\[NETProjects]\ Pocket Control PC - PC\Pocket Control PC - PC.exe" /r:System.Windows.Forms.dll /r:System.dll,System.Drawing.Design.dll, System.Drawing.dll,Microsoft.VisualBasic.dll /imports:System,System.Net.Sockets, System.Net,System.Threading,System.Text,System.IO,System.Drawing ,System.Runtime.InteropServices,Microsoft.Win32 /target:winexe /main:Main /win32icon:"C:\Documents and Settings\Kingherc\My Documents\[NETProjects]\ Pocket Control PC - PC\Images\AppIcon.ico" /res:"C:\Documents and Settings\Kingherc\My Documents\ [NETProjects]\Pocket Control PC - PC \Main.Resources" /recurse:"C:\Documents and Settings\Kingherc\My Documents\[NETProjects]\Pocket Control PC - PC\SubSource\*.vb" "C:\Documents and Settings\Kingherc\My Documents\[NETProjects]\ Pocket Control PC - PC\Main.vb"
Where "C:\Documents and Settings\Kingherc\My Documents\[NETProjects]\Pocket Control PC - PC\" was the directory where I stored and developped the source.
Furthermore, as you see, some resources are embedded in the executable. Resources are .resources files containing any resource you might use inside an application. These must be created first. If not, the above lines will fail to execute because of a FileNotFound error. To create them, we create an executable of the CreateResources.vb with vbc.exe and then execute it. So, to create the executable of the CreateResources, open a command prompt and type something like the following in one line:
"C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\vbc.exe" /out:"C:\Documents and Settings\Kingherc\My Documents\[NETProjects]\Pocket Control PC - PC \MakeResource.exe" /r:System.Windows.Forms.dll /r:System.dll, System.Drawing.Design.dll,System.Drawing.dll,Microsoft.VisualBasic.dll /imports:System.Text, System.IO,System.Runtime.InteropServices,Microsoft.Win32 /target :winexe "C:\Documents and Settings\Kingherc\My Documents \[NETProjects]\Pocket Control PC - PC\CreateResources.vb"
Where "C:\Documents and Settings\Kingherc\My Documents\[NETProjects]\Pocket Control PC - Smartphone\" was the directory where I stored the source.
The executable "MakeResource.exe" will be created. Execute it to create the .resources file. Note that the resources are files contained in the source directory. So, if they do not exist, or you misplaced them or you renamed them, the execution will fail. When the .resources file is created, you can continue with the compliling as described above for Pocket Control PC - PC.exe.
Finally, an .exe file will be created. This can be now run on any device or PC having .NET Framework installed.
For now, the program consists only from one form 'Main'. The first function for the program is the Listening process. When the user clicks Begin Listening, a tmrListenLoop is enabled. The program activates a TcpListener and listens for a connection. When the connection is found, the timer is disabled, many controls are enabled and disabled, and finally a TcpClient and a NetworkStream are created. Commands are text strings transferred between the client and the host via the networkstream. Each time you want to transfer a command of yours use cOut(ByVal strTransfer As String) function. Each time you want to write a log entry, use Out(ByVal str As String) function.
The form contains many other controls, source sections and elements that require much explanation. An advanced developper could surely find his way in the form's source as it's well organised. So, I do not explain these for now (as I'd have to make a small guide). The most important part which I'll explain are the commands, around which the whole program revolves.
As I said, commands are text strings exchanged through a networkstream. So, each command is a string. Through a block of 'If's the program recognises a command and executes it. This block of 'If's can be found in the region "Functions for transferring and executing messages" and in the function "TranslateCommand". You can add your If statement for a command of yours and its execution code. For example, if you want a command to blink the screen, you can make the client send a command with the text 'BlinkScreen' (you can modify the client program's source for this or use the client program's menu Menu > Send Message > Custom). Then, you can add an If statement to the Ifs block like this:
If Not strCommand.IndexOf("BlinkScreen") = -1 Then
'Code for blinking the screen somehow
End If
To send commands, you just have to use the function cOut(ByVal strTransfer As String, Optional ByVal DoNotValidate As Boolean = False) from anywhere in the code. strTransfer is your command. The boolean value is optional. If true, the client program ignores whether the connection had been validated or not and executes the command.
|