Tag Archives: VISUAL STUDIO 2019

7ZIP EXAMPLE AUTOMATION

#67 7zipExample Automation Application In C#

Example Video

While creating a download page for a website I came across the problem where the browser would open a .PDF file instead of downloading it to the desktop of my PC when using the JavaScript window.location.href = "url/path/file.pdf"; function. A quick easy solution is to archive the .PDF document as a .ZIP file or .7z etc. Now when the function is called the file will be downloaded.

Using a quick C# WinForms application I was able to automate the process. Here I have included a small demo project which may be useful on windows machines.

The Main function is as below:

Example code of the main function.

A new process is started and Arguments are sent to the 7za.exe console application.

7za.exe can also be used in the CMD console as well as with scripting languages such as PowerShell or Batch.

C# WINDOWS FORMS EMAIL

#54 C# WINDOWS FORMS EMAIL TEST

Form C# Email Example

A simple C# WinForms desktop application to send a text email/send an attachment email.

This application uses no special class. The default mail classes are used namely:

using System.Net.Mail;

using System.Net.Mime;

The email text is sent in HTML format:

var mailMessage = new MailMessage{                     From = new MailAddress(Vars._mailFrom),//email            Subject = "C# WinForms Test Mail",                     Body = "<h1>Hello</h1>" + "<h2>C# WinForms Test Mail</h2>",                     IsBodyHtml = true,};

STEAM SHUTDOWN

#50 STEAM SHUTDOWN

Trey icon controls.

For years consumers have been asking for steam to add a feature to all them to shutdown their computers after downloading games or after a certain period of time.

This is very useful especially for students who have limited capped internet access due to financial reasons… etc… especially in this day and age where the average game can be roughly up to 120GB!! in size… downloading is a long and tedious task especially in 3rd world country’s…

Enter the C# tray app SteamShutdown. This lightweight app allows users to shutdown, hibernate or put the PC to sleep once all downloads have completed.

The app was designed with the logic being:

  1. Setup downloads at 12am.
  2. Choose an option shutdown, hibernate or sleep.
  3. Go to bed without worrying about bandwidth costs and electricity costs 🙂

TRACCAR CONTROL PANEL

#49 TRACCAR CONTROL PANEL CONCEPT

simple Traccar control panel concept

When managing multiple servers it’s always a good idea to have a centralised control panel monitoring/logging all the services running. In this example concept I have a WPF(Windows Presentation Foundation) C# page. This works well with 4K screens as well as lower resolutions.

The panel allows control and logging/messaging features.

E.G

  • Controlling start, stop, restart.
  • Logging events, errors results and user activity.
  • Sending email notifications when an event occurs.
  • Auto start and ease of use at start up.

VARS, DECLARING CONSTANTS

#37 Using Variables, Declaring Constants

Variables are tools which help programmers temporarily store data for a certain amount of time. Constants are tools which help programmers to define artifacts that are not allowed to change or make changes.

To understand variables we have to first take a look at memory addressing in brief. All computers contain a MCU and a certain amount of temporary memory called RAM In addition may devices also contains a permanent storage memory called ROM. The MCU executes the program and in doing so it utilizes the RAM to fetch binary code to be executed as well as the data associated with it.

RAM uses addresses which allow us to point to blocks of memory stored within itself.

When programming in C++ we define variables to store those variables. Below are two examples:

VariableType VariableName;
e.g int number;

VariableType VariableName = InitialValue;
e.g int number = 0;

The variable type attribute tells the compiler the nature of data the variable can store.

Below is an example of declaring and initializing multiple variables of a type.

int first = 0, second = 1, result = 16;

Data stored in variables is stored in RAM. This data will be lost once the application terminates unless the program is told to save the data to a storage medium such as a hard disk.

If variables are declared outside the scope of the function function() instead of with in it, these variables will be considered global variables.

Variable types:
bool
char
unsigned short int
short int
unsigned long int
long int
unsigned long long
long long
int(16 bit)
int(32 bit)
unsigned int(16 bit)
unsigned int(32 bit)
float
double

C++ allows us to substitute variable types to something that the programmer may find a bit more convenient . The keyword typedef can be used for this functionality. Below is an example where the programmer wants to call an unsigned int a descriptive STRICTLY_POSITIVE_INTEGER.

typedef unsigned int STRICTLY_POSITIVE_INTEGER;
STRICTLY_POSITIVE_INTEGER exampleNumber = 6570;

Constants are like variables in C++ except their value can’t be changed. Constants also occupy space in memory just like variables however this space cannot be overwritten.

Constants in C++ can be:

  • Literal constants.
  • Declared constants using the const keyword.
  • Constant expressions using the constexpr keyword.
  • Enumerated constants using the enum keyword.
  • Defined constants that are not recommended and deprecated.

Enumerations comprise a set of constants called enumerators. This is used when you need a type of variable whose values are restricted to a certain set defined by the programmer..

Below is an example of using Enumerations:

Defining constants using #define
#define pi 3.14
#define is a preprocessor macro. So once defined all mentions of pi henceforth will be replaced by 3.14 This is a text replacement.

GETTING STARTED C++

#34 GETTING STARTED C++

Download visual studio 2019 from here. Once you have installed it be certain to install the C++ components. Once completed start visual studio and select the C++ console application option. Double click on the source files folder and then write your code.

Select The C++ Components

Here is a first C++ application example I have written. All it does is print the text Hello World and displayed some simple arithmetic in the cmd console.

Useful links can be found here

A SHORT HISTORY OF C++

#33 A SHORT HISTORY OF C++

C++ was developed by Bjarne Stroustrup in 1979 it was designed to be an object-oriented language. C++ implements features such as inheritance, abstraction, polymorphism and encapsulation.

Bjarne Stroustrup

C++ is an intermediate-level programming language. It allows high-level and low-level programming. Although there’s a whole bunch of newer languages, C++ is still relevant where accurate control of application’s resource consumption and performance is needed. Before 1998 C++ was being accepted and adopted on so many different platforms that many interoperability problems and porting issues surfaced. Therefore in 1998 the first standard version of C++ was ratified by the ISO Committee in ISO/IEC 14882:1998

INI READER/WRITER C#

#23 INI READER/WRITER C#

Simple INI Reader/Writer

INI files are mostly used in C++ and Delphi programming these days. Microsoft’s .Net framework focuses on XML-based config files not INI files. However it is still possible to read and write to INI files using C#. In this example I have created a very simple INI reader. It allows you to read/write to the config file ini_reader_writer_20xx-xx-xx.ini .

There are plenty  NuGet packages, such as INI Parser. Which allow easy implementation into our projects. You could also write your own class which gives us more control but is overkill for an example. Example an INI file handling class using C#, P/Invoke and Win32.

USING A DLL IN C#

#21 USING A DLL IN C#

A very simple example of how a DLL can be used.

In this simple example I create a very simple DLL(Dynamic-link library) in C#. the library has to functions the first function is the Calculate method which allows us initiate a simple addition of the numbers in each numerical box.The second function is a logger to keep track of the addition problems we solve. The WriteLine method also shows us how we can write to and delete files in by calling methods from the dll_example_class_library.dll we compiled.

A simple method called Calculate just adds two numbers together using the dll_example_class_library.dll DLL’s help to keep code more organised and also allow us to change functionality of programs without recompiling the EXE .

After the DLL is compiled we can add it to our project by: right clicking Refrences, clicking add reference, clicking browse and selecting our DLL

In order for us to use the methods in our class it has to first be initiated. Once initiated we can start using the methods in our logic.