Programming
22 February 2011 8 Comments

Static and Dynamic Linking of C Runtime Libraries with VS2010

Linking Types

A C or C++ program compiled on Windows almost invariably uses the C Runtime Libary (CRT). This set of functions comes with your default Windows installation and provides some of the most basic operations, read this page for details. Now, remember that the last step of creating an EXE is called linking — the process that combines one or more compiled objects and combines them into a single executable.This post describes how to change your CRT linking method to control the size of your EXE file. There are two ways to link an external library such as a DLL.

  • Static linking: All library routines used in the program are copied into the final EXE file. This means there is no dependency on some file existing at run-time.
  • Dynamic linking: Both the name of a shareable library and the functions you use from that library are placed in the EXE file. When the executable is loaded, the operating system needs to do some extra work to locate this library and map it into your program’s virtual memory.

There is actually a third, “super-dynamic” way of loading DLL’s : calling a loadLibrary() function in your code. This means that you can load different libraries…

Programming
11 February 2011 0 Comments

Upload a File to a PHP Page with C#

How do you upload a file from a C# program to a PHP webpage? Here is a short example.

First we have the C# part that will be sending a file. Using the WebClient object this is quite easily achieved. The code below will upload an image to a PHP script upload.php.

System.Net.WebClient Client = new WebClient();
Client.Headers.Add("Content-Type","binary/octet-stream");
 
byte[] result = Client.UploadFile("http://www.myhost.com/upload.php", "test.gif");
 
string response = System.Text.Encoding.UTF8.GetString(result, 0, result.Length);
Console.WriteLine(response);

I suggest using the binary/octet-stream type because this will also work with things that are not text (images, binary data). The HTTP response generated by the upload.php script will be stored in the response variable and subsequently printed. Be aware that this block can throw an exception, for example when the host / page cannot be found. As for all exceptions: catch them if you have a plan for handling them (i.e. printing an error message in the GUI).

Now for the PHP part.

// The uploaded

Tags: $_FILES, , c sharp, is_uploaded_file, php, uploadfile, webclient
Programming
27 December 2010 1 Comment

Setting Up Borland C Compiler on Windows

While Linux users will in most cases use the GCC compiler, this tool is not available for windows as a standalone binary. Using the Borland C++ Compiler is a good way to start developing  C/C++ applications on Windows.

Unfortunately, setting it up is not as easy as you would expect. In this how-to I will show you how to set up the compiler quickly, so you can hit the ground running. Please notice that anytime the C:\Borland\BCC55\ directory is mentioned, this should be substituted with your own installation directory.

1: Download the Borland Compiler

Borland is no longer hosting this file themselves. The latest version is available from the Embarcadero website: click here. Select C++ Builder XE, then click C++ Compiler 5.5. You will have to register to download, but no activation-code is used. You can enter an invalid e-mail address if you like your privacy. Download the file freecommandLinetools.exe to your harddisk.

Note that, even though the name suggests it only compiles C++, this compiler also supports C!

2: Run the setup program

Run the freecommandLineTools.exe program, and install to any directory. The default is C:\Borland\BCC55\.

3: Change your PATH settings

The PATH…

Tags: bcc32, borland, , compiler, embarcadero, path