<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Microsonic Development &#187; C/C++</title>
	<atom:link href="http://microsonic.org/category/c-plus-plus/feed/" rel="self" type="application/rss+xml" />
	<link>http://microsonic.org</link>
	<description></description>
	<lastBuildDate>Mon, 12 Jul 2010 01:55:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Overloading Classes</title>
		<link>http://microsonic.org/2010/05/29/overloading-classes/</link>
		<comments>http://microsonic.org/2010/05/29/overloading-classes/#comments</comments>
		<pubDate>Sun, 30 May 2010 03:11:07 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[classes]]></category>
		<category><![CDATA[functions]]></category>
		<category><![CDATA[overload]]></category>
		<category><![CDATA[overloading]]></category>

		<guid isPermaLink="false">http://microsonic.org/?p=217</guid>
		<description><![CDATA[In OOP, it is a good practice to sometimes &#8220;overload&#8221; classes if you need to bring in information from the outside. For instance, if you want to include configuration variables in another class, you can &#8220;overload&#8221; that class with those variables. In this tutorial, I will explain how to do that in both PHP and [...]]]></description>
			<content:encoded><![CDATA[<p>In OOP, it is a good practice to sometimes &#8220;overload&#8221; classes if you need to bring in information from the outside. For instance, if you want to include configuration variables in another class, you can &#8220;overload&#8221; that class with those variables. In this tutorial, I will explain how to do that in both PHP and C++.</p>
<p>Please note, before continuing, that I assume you are an intermediate to advanced C++/PHP programmer. Therefore, I will not go into great detail about how variables are set, etc. because you should already know how that works. We will jump right into the code now for an example as it&#8217;s usually the best way to explain these tasks.</p>
<p><strong>PHP</strong></p>
<blockquote><p><code>&lt;?php<br />
/**<br />
 * Class overloading tutorial<br />
 * by Dennis J. McWherter, Jr.<br />
 *<br />
 * (C) 2010 DENNIS J. MCWHERTER JR. All Rights Reserved.<br />
 *<br />
 */</p>
<p>// Create our simple class<br />
class OverloadMe<br />
{<br />
	/**<br />
	 * We would like a global var for the whole class<br />
	 */<br />
	var $var1;</p>
<p>	/**<br />
	 * Constructor<br />
	 */<br />
	function __construct($name){<br />
		$this-&gt;var1 = $name;<br />
	}</p>
<p>	/**<br />
	 * Name function<br />
	 */<br />
	function name(){<br />
		return $this-&gt;var1;<br />
	}<br />
}</p>
<p>// Define the name variable<br />
$yourname = "Dennis";</p>
<p>// We overload the function when we initialize it<br />
$overload = new OverloadMe($yourname);</p>
<p>// Now let's get the output<br />
print "Your name is ".$overload-&gt;name();<br />
?&gt;</code></p></blockquote>
<p>Now, the procedure is very similar in C++, just classes work differently as you already know. I&#8217;ll give the C++ code now and explain it all at the end!</p>
<p><strong>C++</strong><br />
<em>src/main.cpp</em></p>
<blockquote><p><code>/**<br />
 * Class overloading tutorial<br />
 * by Dennis J. McWherter, Jr.<br />
 *<br />
 * (C) 2010 DENNIS J. MCWHERTER JR. All Rights Reserved.<br />
 *<br />
 */</p>
<p>#include &lt;string&gt;<br />
#include "overload.h"</p>
<p>int main(int argc,char* argv[])<br />
{<br />
	std::string name = "Dennis";<br />
	OverloadMe overload(name.c_str());<br />
	overload.name();<br />
	return 0; // exit<br />
}</code></p></blockquote>
<p><em>src/overload.h</em></p>
<blockquote><p>/**<br />
 * Class overloading tutorial<br />
 * by Dennis J. McWherter, Jr.<br />
 *<br />
 * (C) 2010 DENNIS J. MCWHERTER JR. All Rights Reserved.<br />
 *<br />
 */</p>
<p>#ifndef Overload_H<br />
#define Overload_H</p>
<p>// Class definition</p>
<p>class OverloadMe<br />
{<br />
public:<br />
	// Constructor<br />
	OverloadMe(const char* namevar);</p>
<p>	// Name function<br />
	void name();<br />
private:<br />
	// A global var for the class<br />
	const char* var1;<br />
};<br />
#endif
</p></blockquote>
<p><em>src/overload.cpp</em></p>
<blockquote><p><code>/**<br />
 * Class overloading tutorial<br />
 * by Dennis J. McWherter, Jr.<br />
 *<br />
 * (C) 2010 DENNIS J. MCWHERTER JR. All Rights Reserved.<br />
 *<br />
 */</p>
<p>// Make the class work<br />
#include &lt;iostream&gt;<br />
#include &lt;stdio.h&gt;<br />
#include "overload.h"</p>
<p>using namespace std;</p>
<p>OverloadMe::OverloadMe(const char* namevar)<br />
: var1(namevar)<br />
{<br />
}</p>
<p>void OverloadMe::name()<br />
{<br />
	cout&lt;&lt; "Your name is " &lt;&lt; var1 &lt;&lt; endl &lt;&lt; endl &lt;&lt; "Please hit enter to exit" &lt;&lt; endl;<br />
	getchar();<br />
	return;<br />
}</code></p></blockquote>
<p>Now, for Windows users using MSVC++, this code will compile with a simple copy/paste. For *nix and BSD users, I&#8217;ve included a Makefile within the ZIP package for you to use when compiling. Basically, the compiler must compile each item as an object first, then it must compile the objects into the program file rather than compiling the .exe&#8217;s directly.</p>
<p>Well, I hope this is of some use to someone. The examples are fairly simple, but should explain the concept easily. As we can see in the C++ example, we initialize the class to a variable, and simply overload that variable at the time of initialization.</p>
<p>Regards,<br />
Dennis M.</p>
<p><a href='http://microsonic.org/wp-content/uploads/2010/05/Overload_Tutorial.zip'>Overload_Tutorial</a></p>
]]></content:encoded>
			<wfw:commentRss>http://microsonic.org/2010/05/29/overloading-classes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Reference Operators in Functions</title>
		<link>http://microsonic.org/2010/04/04/using-reference-operators-in-functions/</link>
		<comments>http://microsonic.org/2010/04/04/using-reference-operators-in-functions/#comments</comments>
		<pubDate>Mon, 05 Apr 2010 02:03:07 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[C/C++]]></category>

		<guid isPermaLink="false">http://microsonic.org/?p=214</guid>
		<description><![CDATA[Happy Easter everyone! I felt today, being a day off, would be a good day to write something up. I&#8217;ve had a lot of inquiries lately about the use and functionality of reference operators (&#038;) in variables. Well, basically, in common word, they replace the original variable. Of course, as usual, I have written up [...]]]></description>
			<content:encoded><![CDATA[<p>Happy Easter everyone!</p>
<p>I felt today, being a day off, would be a good day to write something up. I&#8217;ve had a lot of inquiries lately about the use and functionality of reference operators (&#038;) in variables. Well, basically, in common word, they replace the original variable. Of course, as usual, I have written up a sample code for you all to use, but first I&#8217;d like to explain a little bit more about these operators.</p>
<p>When defining a function, you always specify the format of function arguments. Take void test(int arg1,char* arg2); for instance. You have defined your function type &#8220;void,&#8221; the name &#8220;test,&#8221; and the arguments &#8220;int arg1&#8243; and &#8220;char* arg2.&#8221; Now, the way these functions are defined, the function will proceed with the values inserted into the function and the function will only apply end values of these variables specifically to this function (unless type other than &#8220;void&#8221; is defined and you return an output; however, this output would still need to be defined in another function to transfer).</p>
<p>However, if you define a function such as: void test(int&#038; arg1,char&#038; arg2); it actually will append the variables that were used to make the input (thus the &#8220;reference&#8221;). So let&#8217;s take a look at some code, shall we?</p>
<blockquote><p><code>/**<br />
 * Reference Operator Tutorial<br />
 *<br />
 * Author: Dennis J. McWherter, Jr.<br />
 * (C) 2010 DENNIS J. MCWHERTER, JR.<br />
 *<br />
 */</p>
<p>#include &lt;iostream&gt;<br />
#include &lt;cstdlib&gt;</p>
<p>using namespace std;</p>
<p>void deconstruct(float&amp; x,float&amp; y)<br />
{<br />
	x/=y;<br />
	y*=x;<br />
	return;<br />
}</p>
<p>void reconstruct(float&amp; x,float&amp; y)<br />
{<br />
	const float z=x;<br />
	x*=y/x;<br />
	y/=z;<br />
	return;<br />
}</p>
<p>int main(int argc,char* argv[])<br />
{<br />
	// Define our main variables we'll be using<br />
	// Allow users to input!<br />
	float a,b;</p>
<p>	cout&lt;&lt; "Enter your first number: ";<br />
	scanf("%f",&amp;a);<br />
	cout&lt;&lt; "Enter your second number: ";<br />
	scanf("%f",&amp;b);<br />
	cout&lt;&lt; endl &lt;&lt; "Output:" &lt;&lt; endl &lt;&lt; endl;</p>
<p>	const float a1=a,b1=b; // Define what our originals were! Please note that this is very recursive<br />
				// and can be done much easier with a function returning a value<br />
				// But that would ruin the entire point of this demonstration! <img src='http://microsonic.org/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> </p>
<p>	// Now we will do our actual functioning<br />
	deconstruct(a,b);<br />
	printf("%f / %f = %f\n",a1,b1,a);<br />
	printf("%f x %f = %f\n\n",b1,a,b);</p>
<p>	// Define our "z" variable for here as well<br />
	const float z=a,w=b;</p>
<p>	// Alright, take everything back to original form<br />
	reconstruct(a,b);<br />
	printf("%f / %f = %f\n",w,z,b);<br />
	printf("%f x %f = %f\n\n",(a1/a1),w,a);<br />
	return 0;<br />
}</code></p></blockquote>
<p>Now, as you can see, the variables are originally defined by user input. However, when taken to each function their values are changed (as can be seen by the printf values). That is what the purpose of a reference operator is. Now to reconstruct, we can use the same variables with opposite operations. The &#8220;const&#8221; defined in front of some variables protect them from being &#8220;referenced&#8221; (precursed with &#038;) so their values will not change after they are defined. And as you can see in the final printf statement, (a1/a1) = 1 which is essentially what happens in the final steps of reconstruct().</p>
<p>As I mentioned, it is very recursive to do it this way (it would be best to simply print an output), but then that would defeat the purpose of this post. Also, for those of you wondering why I used printf(); instead of cout: there is no particular reason. Printf(); in this case (and honestly in most) is simply cleaner and quicker. The thing to remember, however, about printf(); is each function type (in this case %f) has a specific variable type that it can output. %f allows us to print float variables. For a more detailed list, visit http://www.cplusplus.com/reference/clibrary/cstdio/scanf/</p>
<p>Below, you can download the script and a compiled *nix version.</p>
<p>Regards,<br />
Dennis M.</p>
<p><a href='http://microsonic.org/wp-content/uploads/2010/04/reference_operators.tar.gz'>Reference Operators Script</a></p>
]]></content:encoded>
			<wfw:commentRss>http://microsonic.org/2010/04/04/using-reference-operators-in-functions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Multi-Argument Parsing</title>
		<link>http://microsonic.org/2010/03/15/multi-argument-parsing/</link>
		<comments>http://microsonic.org/2010/03/15/multi-argument-parsing/#comments</comments>
		<pubDate>Mon, 15 Mar 2010 06:52:37 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[argc]]></category>
		<category><![CDATA[arguments]]></category>
		<category><![CDATA[argv]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[command]]></category>
		<category><![CDATA[for]]></category>
		<category><![CDATA[help]]></category>
		<category><![CDATA[line]]></category>
		<category><![CDATA[loop]]></category>
		<category><![CDATA[parse]]></category>
		<category><![CDATA[parsing]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://microsonic.org/?p=205</guid>
		<description><![CDATA[Well, it has been some time since my last post since I have been (and still am) very busy, but I felt I needed to update! I wrote a quick script for you guys to help in any programming endeavors you may be having parsing your command line arguments in any command line program. This [...]]]></description>
			<content:encoded><![CDATA[<p>Well, it has been some time since my last post since I have been (and still am) very busy, but I felt I needed to update! I wrote a quick script for you guys to help in any programming endeavors you may be having parsing your command line arguments in any command line program. This example merely shows how to simply print all the arguments given to a specified program, however, you can use this type of loop to do whatever you wish!</p>
<blockquote><p><code>/**<br />
 * Process Command Line Args<br />
 * Level: Easy<br />
 * Author: Dennis J. McWherter, Jr.<br />
 *<br />
 */</p>
<p>#include &lt;iostream&gt;</p>
<p>using namespace std; // I'll save myself some std::&lt;&gt; pain this time XD</p>
<p>void echo(char* str,int no)<br />
{<br />
	int x = strlen(str);<br />
	cout&lt;&lt; "Argument Number "&lt;&lt; no &lt;&lt; ": ";<br />
	for(int i=0;i&lt;x;i++){<br />
		cout&lt;&lt; str[i];<br />
	}<br />
	cout&lt;&lt; endl;<br />
}</p>
<p>int main(int argc,char* argv[])<br />
{<br />
	for(int i=1;i&lt;argc;i++){<br />
		echo(argv[i],i);<br />
	}<br />
	cout&lt;&lt; endl&lt;&lt; "Command line: "&lt;&lt; argv[0] &lt;&lt; endl;<br />
	return 0;<br />
}</code></p></blockquote>
<p>As you can see, the first function is a loop which is given a char* array (it loops through each array value to print out the full string) and an integer position. The int allows the script to know which argument number it is processing (not that it is imperative in this case). In the int main(); function, this void echo(); function is called in another for(); loop. This loop begins at array position 1 (the array starts at position 0, however, arguments begin at 1; 0 is the program/command line name). Therefore, for each argument listed the program loops until it reaches it has no further arguments to parse.</p>
<p>There is your quick lesson today in processing multiple arguments in the command line! This should help many of you looking for a quick and easy solution to do this! The example code is provided below for download.</p>
<p>Regards,<br />
Dennis M.</p>
<p><a href='http://microsonic.org/wp-content/uploads/2010/03/argument_parse.tar.gz'>Parse Multiple Arguments</a></p>
]]></content:encoded>
			<wfw:commentRss>http://microsonic.org/2010/03/15/multi-argument-parsing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Windows Programming: Creating/Using DLL&#8217;s</title>
		<link>http://microsonic.org/2009/09/08/windows-programming-creatingusing-dlls/</link>
		<comments>http://microsonic.org/2009/09/08/windows-programming-creatingusing-dlls/#comments</comments>
		<pubDate>Wed, 09 Sep 2009 02:50:18 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[Italiano]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[dll]]></category>
		<category><![CDATA[dynamic]]></category>
		<category><![CDATA[library]]></category>
		<category><![CDATA[link]]></category>
		<category><![CDATA[microsoft]]></category>
		<category><![CDATA[vc++]]></category>
		<category><![CDATA[vcpp]]></category>
		<category><![CDATA[visual]]></category>

		<guid isPermaLink="false">http://microsonic.org/?p=191</guid>
		<description><![CDATA[In the world of programming, there are MANY different types. Unfortunately, programming for some systems is different than others, but it&#8217;s things like that which keep the world turning. Today, we will discuss what exactly is a Dynamic Link Library (DLL) and how to use them to keep our programming easier and more organized. I [...]]]></description>
			<content:encoded><![CDATA[<p>In the world of programming, there are MANY different types. Unfortunately, programming for some systems is different than others, but it&#8217;s things like that which keep the world turning. Today, we will discuss what exactly is a Dynamic Link Library (DLL) and how to use them to keep our programming easier and more organized. I will also include an Italian translation of this tutorial in the download source below! (Un traduzione del questo tutorial è in il download link per richiesta)</p>
<p>We&#8217;ll begin with what a DLL is and what it&#8217;s purpose is. A DLL is a wonderful tool to keep your programs organized by creating a DLL per set of functions. Also, it helps developers keep their closed source functions closed source, but also allows (with proper documentation/instructions on doing so) other users to use their work. Below we will give a few simple examples on how it all works!</p>
<p>To create the DLL we will be using Microsoft&#8217;s Visual C++. This is a free IDE compiler. I use it for any sort of Windows programming that I may do and will include the solution file in the download. Of course, I prefer GNU&#8217;s GCC which is also free, but the Windows ports of the compiler are not as good as the standard linux version.</p>
<p>The first note that I want to make is that if you&#8217;re making this project on your own (and not using my solution file), be sure to go to Project->Your Project&#8217;s Properties->Configuration Properties->General->Configuration Type and change it to &#8220;Dynamic Library (.dll)&#8221; otherwise it will not compile correctly.</p>
<p>Now in this tutorial, I am assuming you already know how to write programs, so this first file is test_dll.cpp. It contains the actual definitions, etc. of our functions:</p>
<blockquote><p><code>/**<br />
 * Test Dynamic Library File<br />
 *<br />
 * (C) 2009 Dennis J. McWherter, Jr. All Rights Reserved.<br />
 *<br />
 */</p>
<p>#define WIN32_LEAN_AND_MEAN // No need for the extra stuff.<br />
							// Non includere i file cui non hanno un scopo<br />
#include &lt;windows.h&gt;<br />
#include &lt;iostream&gt;<br />
#include "test_dll.h" // Our header file<br />
					  // Il nostro header file</p>
<p>using namespace std;</p>
<p>// Initiate the DLL (For programs)<br />
// Iniziare il DLL (per i programmi)<br />
BOOL APIENTRY DllMain(HINSTANCE dllHinst, DWORD reason, LPVOID lpvReserved){<br />
	// Use a switch to tell the program how to cycle the processes<br />
	// Usare un switch per fare il programma funziona<br />
	switch(reason){<br />
		case DLL_PROCESS_ATTACH:<br />
		break;<br />
		case DLL_PROCESS_DETACH:<br />
		break;<br />
		case DLL_THREAD_ATTACH:<br />
		break;<br />
		case DLL_THREAD_DETACH:<br />
		break;<br />
	}<br />
	return true;<br />
}</p>
<p>// The functions of our class. These are defined in "test_dll.h"<br />
// Le funzioni del nostro class. Gli questi sono definire in "test_dll.h"</p>
<p>// Constructor<br />
test_dll::test_dll(){}</p>
<p>// Basically a pointless function just to see how we can make them work together XD<br />
// Una funziona senza la usa. è più di un demonstrazione.<br />
char test_dll::func1(char lang){<br />
	return lang;<br />
}</p>
<p>int test_dll::func2(float x,float y,char op){<br />
	// Simple math function!<br />
	// Semplice funziona della matematica<br />
	switch(op){<br />
		case 'a':<br />
			cout&lt;&lt; x &lt;&lt; "+" &lt;&lt; y &lt;&lt; "=" &lt;&lt; x+y;<br />
			return 0;<br />
		break;<br />
		case 's':<br />
			cout&lt;&lt; x &lt;&lt; "-" &lt;&lt; y &lt;&lt; "=" &lt;&lt; x-y;<br />
			return 0;<br />
		break;<br />
		case 'd':<br />
			cout&lt;&lt; x &lt;&lt; "/" &lt;&lt; y &lt;&lt; "=" &lt;&lt; x/y;<br />
			return 0;<br />
		break;<br />
		default:<br />
			cout&lt;&lt; x &lt;&lt; "*" &lt;&lt; y &lt;&lt; "=" &lt;&lt; x*y;<br />
			return 0;<br />
		break;<br />
	}<br />
	return 0;<br />
}<br />
</code></p></blockquote>
<p>Again, a fairly straightforward example. What you do have to notice in this that is different from most programs is that fact that we&#8217;re not really calling a &#8220;Main&#8221; function to be run. We call BOOL WINAPI <strong>DllMain</strong> instead. This next file is the header file. A rather important file overall as it let&#8217;s us know what to export.</p>
<blockquote><p><code><br />
 /**<br />
 * Test Dynamic Library File<br />
 *<br />
 * (C) 2009 Dennis J. McWherter, Jr. All Rights Reserved.<br />
 *<br />
 */</p>
<p>#ifndef HEADER<br />
#define HEADER<br />
	// To keep the code clean we'll define this with a macro but this tells the processor<br />
		// to export whichever function/class it preceeds.<br />
	// Ci definiamo il questo con un macro ma ci vedremmo come lo funziona in più ritardo<br />
#define EXPORT_DLL __declspec(dllexport)</p>
<p>// Now our class - If you export a class, all its functions come with! <img src='http://microsonic.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  else do each function<br />
// Adesso il nostro class! Se exporti un class poi i tutti funzione di lo sono exportare.<br />
	// se individuale ti exporti poi si deve __declspec(dllexport) per ogni<br />
class EXPORT_DLL test_dll{ // = class __declspec(dllexport) test_dll{<br />
public:<br />
	test_dll(); // Constructor/Costruttore<br />
	char func1(char lang); // First function definition/La definizione della prima funziona<br />
	int func2(float x,float y,char op);<br />
};</p>
<p>#endif<br />
</code></p></blockquote>
<p>The comments explain it, but it&#8217;s really worth going over again. EXPORT_DLL is defined just for the purpose that we could potentially have more than a single class to export. This goes both ways for the dllexport and dllimport options, so really, EXPORT_DLL just translates to __declspec(dllexport) which would also work if you replaced EXPORT_DLL. Now, compile that code and VC++ should provide you with a .dll file and a .lib file with whatever name you gave the project (in our case: &#8220;DLL_Tutorial.lib/.dll&#8221;).</p>
<p>Now, you cannot run DLL files by themselves; you need a client program (.exe) which is what we&#8217;re getting to now. For the sake of brevity, we will just make this a simple console program which runs the proper functions. Now, create a new project and make sure you copy the &#8220;DLL_Tutorial.lib&#8221; file into the source directory. You need the .lib file to compile the client program, but you only need the .dll to run the program.</p>
<p>So here is the client main file. A console program of course to keep things simple <img src='http://microsonic.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  We&#8217;ll call this test_client.cpp</p>
<blockquote><p><code>/**<br />
 * Test Dynamic Library File<br />
 *<br />
 * (C) 2009 Dennis J. McWherter, Jr. All Rights Reserved.<br />
 *<br />
 */</p>
<p>#include &lt;iostream&gt;<br />
#include &lt;string&gt;<br />
#include "test_client.h"</p>
<p>using namespace std;</p>
<p>int main(){<br />
	// Create object to class<br />
	// Creare l'oggetto a class<br />
	test_dll test;</p>
<p>	// Init var<br />
	string num1,num2,addition,subtraction,division,multiplication,ans,operation;<br />
	float x,y;<br />
	char choice[5], op[5]; // Allow more chars just in case - otherwise we'll break the script <img src='http://microsonic.org/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /><br />
						   // Permettere dei più caratteri così non ci romperiamo il script! <img src='http://microsonic.org/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /><br />
	cout&lt;&lt; "Please select a language\r\n\r\nEnglish - en\r\nItaliano - it\r\n \r\nSelect: ";<br />
	cin&gt;&gt;choice;<br />
	switch(test.func1(choice[0])){<br />
		case 'i':<br />
			num1 = "Numero 1: ";<br />
			num2 = "Numero 2: ";<br />
			addition = "Per piacere selezi i tuoi numeri per aggiungiere";<br />
			subtraction = "Per piacere selezi i tuoi numeri per sottrarre";<br />
			division = "Per piacere selezi i tuoi numeri per dividere";<br />
			multiplication = "Per piacere selezi i tuoi numeri per moltiplicare";<br />
			ans = "La tua risposta: ";<br />
			operation = "\r\nPer piacere selezi il tuo operazione:\r\na - Aggiungiere\r\ns - Sottrarre\r\nd - Divisione\r\nm - Moltiplicazione\r\n\r\nSelection: ";<br />
		break;<br />
		default:<br />
			num1 = "Number 1: ";<br />
			num2 = "Number 2: ";<br />
			addition = "Please select your numbers to add";<br />
			subtraction = "Please select your numbers to subtract";<br />
			division = "Please select your numbers to divide";<br />
			multiplication = "Please select your numbers to multiply";<br />
			ans = "Your answer: ";<br />
			operation = "\r\nPlease select your option:\r\na - Addition\r\ns - subtraction\r\nd - Division\r\nm - Multiplication\r\n\r\nSelection: ";<br />
		break;<br />
	}</p>
<p>	cout&lt;&lt; operation;<br />
	cin&gt;&gt;op;<br />
	cout&lt;&lt; endl &lt;&lt; endl &lt;&lt; num1;<br />
	cin&gt;&gt;x;<br />
	cout&lt;&lt; endl &lt;&lt; num2;<br />
	cin&gt;&gt;y;</p>
<p>	test.func2(x,y,op[0]);</p>
<p>	cout&lt;&lt; endl &lt;&lt; endl &lt;&lt; "Type in anything to exit...";<br />
	cin&gt;&gt;op;</p>
<p>	return 0;<br />
}</code></p></blockquote>
<p>Naturally, the header file that follows is test_client.h</p>
<blockquote><p><code>/**<br />
 * Test Dynamic Library File<br />
 *<br />
 * (C) 2009 Dennis J. McWherter, Jr. All Rights Reserved.<br />
 *<br />
 */</p>
<p>#ifndef TEST_HEADER<br />
#define TEST_HEADER<br />
#define DLL_IMPORT __declspec(dllimport) // Same concept as export<br />
									     // Il stesso concepto come export</p>
<p>// Define the class</p>
<p>// What is the purpose of redefining? That's all you need to do is redefine structure <img src='http://microsonic.org/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /><br />
	// and not function <img src='http://microsonic.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
// Perchè ti deve ridefinire la class? Perché solo lo struttura si deve essere definire!<br />
	// e no funziona <img src='http://microsonic.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
class DLL_IMPORT test_dll{<br />
public:<br />
	test_dll(); // Constructor/Costruttore<br />
	char func1(char lang); // First function definition/La definizione della prima funziona<br />
	int func2(float x,float y,char op);<br />
};</p>
<p>#endif</code></p></blockquote>
<p>Within these two files, they are essentially creating a calculator. Since I wrote this program in dual languages, I added SIMPLE (meaning hard-coded) dual language support into the program. Also, this gives a reason for the first function, just to see how one can use multiple functions from a DLL just as if they were in the source.</p>
<p>If anyone has further questions or is receiving errors, feel free to let me know and I will be glad to help! Now make sure, however, that everything is set right as well. I ran into an error compiling the client the first time because my project subsystem (found in project properties->linker->System) was set to WINDOWS rather than CONSOLE so it was looking for the WINMAIN where there was none. So just a word of caution to anyone trying this without my source and you are receiving a WINMAIN compilation error.</p>
<p>So the land of DLL&#8217;s really aren&#8217;t as complex as it seems. It&#8217;s simply a closed source utility which helps other developers in WINDOWS programs.</p>
<p>Regards,<br />
Dennis M.</p>
<p><a href='http://microsonic.org/2009/09/08/windows-programming-creatingusing-dlls/dll_tutorial/' rel='attachment wp-att-192'>DLL Tutorial Source Code and Binaries</a></p>
]]></content:encoded>
			<wfw:commentRss>http://microsonic.org/2009/09/08/windows-programming-creatingusing-dlls/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Converting a String to a Vector</title>
		<link>http://microsonic.org/2009/08/24/converting-a-string-to-a-vector/</link>
		<comments>http://microsonic.org/2009/08/24/converting-a-string-to-a-vector/#comments</comments>
		<pubDate>Tue, 25 Aug 2009 03:52:40 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[Italiano]]></category>
		<category><![CDATA[Other]]></category>

		<guid isPermaLink="false">http://microsonic.org/?p=187</guid>
		<description><![CDATA[It has been a long while since I&#8217;ve posted a C or C++ tutorial, but here comes another one! I try to help with programming tips on various forums across the internet. I am a fluent English and Italian speaker, so naturally I work on forums of both languages. While browsing an Italian forum, I [...]]]></description>
			<content:encoded><![CDATA[<p>It has been a long while since I&#8217;ve posted a C or C++ tutorial, but here comes another one! I try to help with programming tips on various forums across the internet. I am a fluent English and Italian speaker, so naturally I work on forums of both languages. While browsing an Italian forum, I came across an interesting question. How does one convert a C++ string to a vector. I decided I would lend a hand, and it bears repeating on here.</p>
<p>Vectors can be used for various things in C++, but they are for the more advanced programmer really. They are not really necessary if it is not a complex program, but this tutorial could serve useful for many I&#8217;m sure.</p>
<p>I myself was at first puzzled by the question. I had never thought of a reason to do this and so, frankly, I never have. After some thought, it wasn&#8217;t too bad, but still an interesting concept. I&#8217;ll post the code below and then explain further below that. Comments are in both English and Italian. The reason being is what I previously mentioned about the original reason I wrote this code.</p>
<blockquote><p><code>/**<br />
 * String to Vector Tutorial by Dennis M.<br />
 *<br />
 * un tutorial di microsonic.org<br />
 *<br />
 */</p>
<p>// Include files ~ Includere i file<br />
#include &lt;string&gt;<br />
#include &lt;iostream&gt;<br />
#include &lt;vector&gt;</p>
<p>using namespace std;</p>
<p>int main()<br />
{<br />
	// Declare Variables ~ Definire i varibili<br />
	string data = "one - uno";<br />
	vector&lt;string&gt; vect;</p>
<p>	// Insert data into vector ~ Inserire l'informazione in il vector<br />
	vect.push_back(data);<br />
	data = "two - due";<br />
	vect.push_back(data);<br />
	data = "three - tre";<br />
	vect.push_back(data);</p>
<p>	// Loop to view the contents of the vector ~ Loop per vedere i contenti di il vector<br />
	for(unsigned int i=0;i&lt;vect.size();i++){<br />
		cout&lt;&lt; i &lt;&lt; ": " &lt;&lt; vect.at(i) &lt;&lt; endl;<br />
	}</p>
<p>	// Memory Management ~ Ci sicuriamo la memoria!<br />
	vect.clear();</p>
<p>	return 0;<br />
}<br />
</code></p></blockquote>
<p>Now the code is pretty self-explanatory and the comments I think do a pretty good job. The only thing one may be perplexed about is where the functions and pointers come from. If you examine the documentation (header file?) for a vector, all is clearly defined. This example will also print the vector and clear it before it exits.</p>
<p>So I hope this post is of some service to someone and as usual, I have included the source and binaries in the post!</p>
<p><a href='http://microsonic.org/2009/08/24/converting-a-string-to-a-vector/string-vector-tar/' rel='attachment wp-att-188'>String to Vector Tutorial</a></p>
<p>Regards,<br />
Dennis M.</p>
]]></content:encoded>
			<wfw:commentRss>http://microsonic.org/2009/08/24/converting-a-string-to-a-vector/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Importance of Structure and Coding Etiquette</title>
		<link>http://microsonic.org/2009/08/07/importance-of-structure-and-coding-etiquette/</link>
		<comments>http://microsonic.org/2009/08/07/importance-of-structure-and-coding-etiquette/#comments</comments>
		<pubDate>Fri, 07 Aug 2009 16:11:35 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Other]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[etiquette]]></category>
		<category><![CDATA[how]]></category>
		<category><![CDATA[professional]]></category>
		<category><![CDATA[professionalism]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[structure]]></category>
		<category><![CDATA[to]]></category>

		<guid isPermaLink="false">http://microsonic.org/?p=185</guid>
		<description><![CDATA[Well, it&#8217;s been a very long time since I last updated and I&#8217;d like to apologize to all my subscribers for that. I&#8217;ve been very busy, but it seems the work load is going down and I&#8217;ll have more time to continue writing! Now, on with the article. So recently, I have just finished a [...]]]></description>
			<content:encoded><![CDATA[<p>Well, it&#8217;s been a very long time since I last updated and I&#8217;d like to apologize to all my subscribers for that. I&#8217;ve been very busy, but it seems the work load is going down and I&#8217;ll have more time to continue writing! Now, on with the article.</p>
<p>So recently, I have just finished a project where one developer had started and then decided he could not finish the work, so I was hired to finish it. The natural thought to one who is inexperienced is, &#8220;This will be a cakewalk. Most of the programming is already done!&#8221; &#8211; wrong. The first thing that went through my mind was, &#8220;I wonder how bad this really is.&#8221; So, I accept the project (as I had only a few projects at the time) and take a look.</p>
<p>The code was atrocious to say the least. I felt as if this other developer had never learned how to use comments or his tab key/space bar to format. Most of the time on the project was bent around figuring out what the original developer had tried to do. It was a nightmare.</p>
<p>As I started digging through files and files of unnecessary sloppy code, I thought to myself, &#8220;I need to write something about this. This kind of work needs to stop.&#8221; I was not upset because of the amateur programming, nor the fact that it was undocumented and poorly written. What bugs me is the fact that someone paid for that kind of work. It looked like the developer copy/pasted everything from snippets he or she found online. That being said, one must learn the importance of structure and coding etiquette. </p>
<p>Structure is important for general organization. It keeps code neat and clean looking and much easier for anyone, to include yourself, to go back and fix errors/security holes. Most people see structural formatting as a simple aesthetic quality when in reality it is like formatting a letter. The structure keeps things organized and understandable on a more universal level.</p>
<p>Coding etiquette, on the other hand, is something learned over a long period of time. No new developer can simply logon and expect to program to the standards set right now, but at the same time should begin mimicking the styles of major developers. Examining the work of others is one of the best ways for any developer to learn, so studying (yes, just like in school) the work of past developers, and prominent works of today, one can easily understand how to program professionally. A simple example would be to write functions rather than hardcode functions multiple times. Or rather than using raw MySQL functions, create an SQL wrapper to execute the functions.</p>
<p>There are many resources on learning how to program professionally, and be neat, but it&#8217;s up to developers to use the tools. The vast majority of developers, I would say, hold to the standards. However, for those who do not, they are just ripping off their client in the long-run.</p>
<p>Regards,<br />
Dennis M.</p>
]]></content:encoded>
			<wfw:commentRss>http://microsonic.org/2009/08/07/importance-of-structure-and-coding-etiquette/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Importance of a Portfolio</title>
		<link>http://microsonic.org/2009/06/10/importance-of-a-portfolio/</link>
		<comments>http://microsonic.org/2009/06/10/importance-of-a-portfolio/#comments</comments>
		<pubDate>Wed, 10 Jun 2009 22:59:31 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[News]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[designers]]></category>
		<category><![CDATA[freelancers]]></category>
		<category><![CDATA[graphics]]></category>
		<category><![CDATA[portfolio]]></category>
		<category><![CDATA[programmers]]></category>
		<category><![CDATA[sellers]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[webmasters]]></category>
		<category><![CDATA[work]]></category>

		<guid isPermaLink="false">http://microsonic.org/?p=173</guid>
		<description><![CDATA[Portfolio. The word sometimes lingers in one&#8217;s mind, but usually is associated with artwork, or a collection of works from your high school English class. But really, an online portfolio (whether it&#8217;s only artwork/graphics or programming) is very important when trying to find interested clients. Generally, most people can only establish their names by doing [...]]]></description>
			<content:encoded><![CDATA[<p>Portfolio. The word sometimes lingers in one&#8217;s mind, but usually is associated with artwork, or a collection of works from your high school English class. But really, an online portfolio (whether it&#8217;s only artwork/graphics or programming) is very important when trying to find interested clients.</p>
<p>Generally, most people can only establish their names by doing quality work at a great price (or in a few cases, great work and advertising at a high price pays off too &#8211; but those are the few giants of the web today). Word of mouth is good, but when you have a website, you should be showing off more than that to your potential clients. When a client visits your site (no matter which way &#8211; browsing, by accident, referal, etc.) their first opinion is your site itself. From there, they are looking for a giant link or button that says &#8220;Portfolio.&#8221;</p>
<p>When the user goes to this link, they don&#8217;t want to see just links, but they want a thumbnail shot of what to expect, a link to a working example, and a description of the purpose of the work. Now I know I do not have all of those things right now (just yet, anyway), but they are well worth it. Since most users see other works I&#8217;ve done (and after speaking to me on MSN) they are always satisfied with what I have to offer, but I am working on my designing skills and a portfolio script which I shall be launching very soon so I can practice what I preach.</p>
<p>So now that everyone understands that a portfolio should be more than just a collection of works you done, everyone can start really presenting themselves effectively. Like I said, soon I will be finishing my portfolio script and perhaps releasing it to the public, so if you are unsure about how to get yours started, that may be a great starting point for you!</p>
<p>Regards,<br />
Dennis M.</p>
]]></content:encoded>
			<wfw:commentRss>http://microsonic.org/2009/06/10/importance-of-a-portfolio/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>The For(); Loop</title>
		<link>http://microsonic.org/2009/05/13/the-for-loop/</link>
		<comments>http://microsonic.org/2009/05/13/the-for-loop/#comments</comments>
		<pubDate>Thu, 14 May 2009 02:54:21 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Other]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cplusplus]]></category>
		<category><![CDATA[for]]></category>
		<category><![CDATA[loop]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://microsonic.org/?p=148</guid>
		<description><![CDATA[Many new programmers are perplexed by the &#8220;for&#8221; loop. However, it is one of the most essential and powerful tools in any developer&#8217;s arsenal. Without it, efficient and clean programming would not be as possible. Early on, most developers seem to stick to the while(); loop. I mean sure, while(); is great for some things, [...]]]></description>
			<content:encoded><![CDATA[<p>Many new programmers are perplexed by the &#8220;for&#8221; loop. However, it is one of the most essential and powerful tools in any developer&#8217;s arsenal. Without it, efficient and clean programming would not be as possible. Early on, most developers seem to stick to the while(); loop. I mean sure, while(); is great for some things, but may not exist in some programming languages and not to mention won&#8217;t work for everything you need.</p>
<p>Let&#8217;s begin by going into the basics about the for(); loop. Well really, a lot depends on the programming language (I will provide both PHP and C++ examples in the source file). But more or less, the for(); loop is simply iteration. It will run until its defined limit is hit providing whatever results you wish. We&#8217;re going to do this in more standard languages (e.g.: C/C++ and Java) instead of PHP for mass compatibility. Just note, if you&#8217;re looking to do this for php, you do not need to define the type of variable, and your variable will just start with the &#8220;$&#8221; symbol. So for example, PHP would be for($i=0;&#8230;;&#8230;){}. </p>
<p>Now we&#8217;re going to write a sample program and break it down:</p>
<blockquote><p><code>for(int i=0;i&lt;=5;i++){<br />
  std::cout&lt;&lt; "This is line number "&lt;&lt; i &lt;&lt; std::endl;<br />
}</code></p></blockquote>
<p>Now as most of you may have noticed, this is a C++ example, but will effectively explain how the loop works for ALL programming languages!</p>
<p><strong>int i=0;</strong> &#8211; This simply defines the variable and starting place (0 in this case). In PHP you would simply use $i=0; and so on for the rest of the statements.<br />
<strong>i<=5</strong> &#8211; This tells the loop when to stop (This <em><=</em> symbol means less than or equal to). When i>5, the loop will stop and proceed on to the rest of the code.<br />
<strong>i++</strong> &#8211; This tells what the loop should do after every time it is run. In this case, we&#8217;re using i++ which means to add 1 each time around.</p>
<p>Now those are the basics to the loop. What lies within is just simply the code to be executed, which could of course have conditionals and such within it as well (e.g.: if(), etc.). So now we&#8217;ll move on to a more complex example.</p>
<blockquote><p><code>unsigned int choices=5;<br />
char* choice = new char[choices];<br />
for(int i=0;i&lt;=choices;i++){<br />
  std::cout&lt;&lt;"Please enter a value: ";<br />
  std::cin&gt;&gt;choice[i];</p>
<p>  if(!choice[i]){<br />
    std::cout&lt;&lt;"No value for choice "&lt;&lt; i&lt;&lt; std::endl;<br />
  }<br />
}<br />
for(int i=0;i&lt;=choices;i++){<br />
  std::cout&lt;&lt;"Choice "&lt;&lt; i&lt;&lt;" was "&lt;&lt; choice[i] &lt;&lt; std::endl;<br />
}</code></p></blockquote>
<p>This will store an array of choices and then after entering them, they will be printed back!</p>
<p>In the source below, all working examples will be provided!<br />
<a href='http://microsonic.org/2009/05/13/the-for-loop/for_loop-tutorialtar/' rel='attachment wp-att-149'>For(); Loop Tutorial</a></p>
<p>So, that basically wraps everything up! If you need anymore clarification, just let me know.</p>
<p>Regards,<br />
Dennis M.</p>
]]></content:encoded>
			<wfw:commentRss>http://microsonic.org/2009/05/13/the-for-loop/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C++ Programming: Visual Windows</title>
		<link>http://microsonic.org/2009/04/24/c-programming-visual-windows/</link>
		<comments>http://microsonic.org/2009/04/24/c-programming-visual-windows/#comments</comments>
		<pubDate>Sat, 25 Apr 2009 01:36:38 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[9]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[m$]]></category>
		<category><![CDATA[microsoft]]></category>
		<category><![CDATA[ms]]></category>
		<category><![CDATA[studio]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[vc++]]></category>
		<category><![CDATA[visual]]></category>
		<category><![CDATA[visualc++]]></category>
		<category><![CDATA[visualstudio]]></category>
		<category><![CDATA[win32]]></category>
		<category><![CDATA[windows]]></category>
		<category><![CDATA[winlib]]></category>

		<guid isPermaLink="false">http://microsonic.org/?p=113</guid>
		<description><![CDATA[I am primarily a programmer for *nix platforms and some cross compatibility for the DOS command prompt as many of you know. However, I also program Windows in the visual sense (how most end-users envision their product). So I&#8217;m going to write up a quick tutorial for you guys today! I am compiling the example [...]]]></description>
			<content:encoded><![CDATA[<p>I am primarily a programmer for *nix platforms and some cross compatibility for the DOS command prompt as many of you know. However, I also program Windows in the visual sense (how most end-users envision their product). So I&#8217;m going to write up a quick tutorial for you guys today!</p>
<p>I am compiling the example with Microsoft&#8217;s <a title="Microsoft's Visual C++" href="http://www.microsoft.com/express/vc/" target="_blank">Visual C++</a>. I am not normally an advocate for most things made by Microsoft, but in this case there is no doubt that this is the best compiler for compiling Windows programs. The best part about it is (unexpected, I know; it is Microsoft after all) that the compiler is FREE and comes with a very nice and clean GUI.</p>
<p>Now be mindful, the example has small functionality, but it is more or less the basis to ALL Windows programs! As we go through, we&#8217;ll explain the importance of each part. So let&#8217;s begin with the main file so you can see what&#8217;s going on.</p>
<p><strong>main.cpp</strong></p>
<blockquote><p>/**<br />
* Windows Programming Tutorial by Dennis M.<br />
*<br />
* main.cpp<br />
*<br />
*/</p>
<p>// Basic includes <img src='http://microsonic.org/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /><br />
#include &lt;windows.h&gt; // Win32 Lib<br />
#include &#8220;menu.h&#8221; // Our menu &#8211; we&#8217;ll explain this later <img src='http://microsonic.org/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /><br />
// more commonly named &#8220;resource.h,&#8221; but for<br />
// explanation purposes this is easier <img src='http://microsonic.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>// Main WindowProcedure Definition<br />
LRESULT CALLBACK WindowProcedure(HWND,UINT,WPARAM,LPARAM);<br />
const char szClassName[] = &#8220;MicrosonicTestProgram&#8221;; // Our program&#8217;s name</p>
<p>int WINAPI<br />
// Our main class to make the Window<br />
WinMain(HINSTANCE hThisInstance,HINSTANCE hPrevInstance,LPSTR lpszArg,int WindowStyle)<br />
{<br />
// Pointer definitons<br />
HWND hwnd;<br />
MSG msgs;<br />
WNDCLASSEX wcl;</p>
<p>// Standard window properties<br />
wcl.hInstance = hThisInstance;<br />
wcl.lpszClassName = szClassName;<br />
wcl.lpfnWndProc = WindowProcedure;<br />
wcl.style = CS_DBLCLKS;<br />
wcl.cbSize = sizeof(WNDCLASSEX);<br />
wcl.hIcon = LoadIcon(NULL,IDI_APPLICATION);<br />
wcl.hIconSm = LoadIcon(NULL,IDI_APPLICATION);<br />
wcl.hCursor = LoadCursor(NULL,IDC_ARROW);<br />
wcl.lpszMenuName = &#8220;MAIN_MENU&#8221;;<br />
wcl.cbClsExtra = 0;<br />
wcl.cbWndExtra = 0;<br />
wcl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;</p>
<p>if(!RegisterClassEx(&amp;wcl)){<br />
return 0;<br />
}</p>
<p>hwnd = CreateWindowEx(<br />
0,<br />
szClassName,<br />
&#8220;Microsonic.org Test Program&#8221;,<br />
WS_OVERLAPPEDWINDOW,<br />
CW_USEDEFAULT,<br />
CW_USEDEFAULT,<br />
640,<br />
480,<br />
HWND_DESKTOP,<br />
LoadMenu(hThisInstance,&#8221;MAIN_MENU&#8221;),<br />
hThisInstance,<br />
NULL<br />
);</p>
<p>// This is where we see the window.. ShowWindow()&#8230; duh!<br />
ShowWindow(hwnd,WindowStyle);<br />
while(GetMessage(&amp;msgs,NULL,0,0)){<br />
TranslateMessage(&amp;msgs);<br />
DispatchMessage(&amp;msgs);<br />
}<br />
return msgs.wParam;<br />
}</p>
<p>// Here we process all the commands etc.<br />
LRESULT CALLBACK WindowProcedure(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam){<br />
switch(msg){<br />
// Process commands sent to the program<br />
// In this case, from the menu items<br />
case WM_COMMAND:<br />
switch(wParam){<br />
case MM_FILE_NEW:<br />
MessageBox(hwnd,&#8221;MDI is more complex! Another tutorial soon perhaps on it! This is just the basics to Windows programming!\r\nSorry!&#8221;,<br />
&#8220;Feature Not Available&#8221;,MB_OK);<br />
return 0;<br />
break;<br />
case MM_FILE_EXIT:<br />
PostQuitMessage(0);<br />
return 0;<br />
break;<br />
case MM_HELP_ABOUT:<br />
MessageBox(hwnd,&#8221;\tMicrosonic.org test program!\r\n\r\n\tFor more tutorials visit:\r\n\r\n\thttp://microsonic.org! \r\n&#8221;,<br />
&#8220;Microsonic.org Test Program&#8221;,MB_OK);<br />
return 0;<br />
break;<br />
case MM_HELP_VISIT:<br />
ShellExecute(hwnd,&#8221;open&#8221;,&#8221;http://microsonic.org&#8221;,NULL,NULL,0);<br />
return 0;<br />
break;<br />
}<br />
break;<br />
// If they hit the &#8220;X&#8221; button<br />
case WM_DESTROY:<br />
PostQuitMessage(0);<br />
return 0;<br />
break;<br />
// Default loop<br />
default:<br />
return DefWindowProc(hwnd,msg,wParam,lParam);<br />
break;<br />
}<br />
return 0;<br />
}</p></blockquote>
<p>Some basic points I&#8217;d like to touch upon. Since this is just the basics to the Window, I have not included MDI (allowing text, etc. through the new button) but, this is important for the generalization of the program. If you understand how this works, Windows programming becomes very similar to all other sorts of programming with the assistance of the <a title="MSDN Library" href="http://msdn.microsoft.com/en-us/library/60k1461a(VS.80).aspx" target="_blank">MSDN Library</a>. Now, realize that the structure file for the menu is never directly included into any C++ file, but rather automatically linked. Make sure you keep it this way and don&#8217;t make the mistake of including a .rc file. Also, as I peer through the code, it is important to realize that many of the function names are static. For the basics, all Windows programs should look as some sort of variation to this code simply by definition of a Windows program.</p>
<p>Now, let&#8217;s continue to see the header file. This purely holds definitions for the resource file holding the menu structure. If they are not defined, they will not work properly.</p>
<p><strong>menu.h</strong></p>
<blockquote><p>/**<br />
* Windows Programming Tutorial by Dennis M.<br />
*<br />
* menu.h<br />
*<br />
* Contains all our menu definitions<br />
*<br />
*/</p>
<p>// Give values to menu items<br />
#define MM_FILE_NEW 2001<br />
#define MM_FILE_EXIT 2002<br />
#define MM_HELP_ABOUT 3001<br />
#define MM_HELP_VISIT 3002</p></blockquote>
<p>As you can see, each menu item is defined. These numbers are more or less arbitrary, you just want to make sure their definitions don&#8217;t conflict with each other or any other aspect of your program. I personally like to keep menu items grouped together, so I defined the &#8220;File&#8221; items in the <em>2000</em>&#8216;s and the &#8220;Help&#8221; items in the <em>3000</em>&#8216;s.</p>
<p>Finally, the structure of our menu. A resource file that is never really included.</p>
<p><strong>menu.rc</strong></p>
<blockquote><p>/**<br />
* Windows Programming Tutorial by Dennis M.<br />
*<br />
* menu.rc<br />
*<br />
* Resource file which contains the menu structure!<br />
* To edit the file with Free Visual C++<br />
* Right click and &#8220;View Code&#8221;<br />
* Again, more commonly named &#8220;resource.rc&#8221;<br />
*<br />
*/<br />
// Menu definitions<br />
#include &#8220;menu.h&#8221;</p>
<p>// Should be able to get the hang of the menu <img src='http://microsonic.org/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /><br />
MAIN_MENU MENU<br />
BEGIN<br />
POPUP &#8220;&amp;File&#8221;,<br />
BEGIN<br />
// Format: MENUITEM &#8220;Title&#8221;, COMMAND_TO_SEND<br />
MENUITEM &#8220;N&amp;ew&#8221;, MM_FILE_NEW<br />
MENUITEM SEPARATOR<br />
MENUITEM &#8220;E&amp;xit&#8221;, MM_FILE_EXIT<br />
END<br />
POPUP &#8220;&amp;Help&#8221;<br />
BEGIN<br />
MENUITEM &#8220;A&amp;bout&#8221;, MM_HELP_ABOUT<br />
MENUITEM SEPARATOR<br />
MENUITEM &#8220;G&amp;oto Microsonic.org&#8221;, MM_HELP_VISIT<br />
END<br />
END</p></blockquote>
<p>The structure is fairly straight forward, so I can probably leave it without much explanation. The only thing I would like to say is that you should realize how usable menu items are presented.<br />
<strong><em>MENUITEM &#8220;Display Text&#8221;, DEFINED_FUNCTION</em></strong>.<br />
The defined function is what is sent to the main loop of the program and is processed in the &#8220;switch.&#8221; Just remember this when you&#8217;re creating your programs!</p>
<p>As usual, I will provide complete source WITH the VC++9 Project file!</p>
<p>If you choose to make your own project, please make sure you go to the &#8220;General&#8221; tab and create an empty project. Compiler options in other Visual C++ presets do not work properly for many reasons. A major error one could run into (if using another setting) is compiling UNICODE which would break &#8220;const char szClassName[]&#8221; by definiton. You would then have to declare it as _T string.</p>
<p><a rel="attachment wp-att-114" href="http://microsonic.org/2009/04/24/c-programming-visual-windows/microsonicorg-simplewin32/">Simple Win32 API Tutorial</a></p>
<p>Regards,<br />
Dennis M.</p>
]]></content:encoded>
			<wfw:commentRss>http://microsonic.org/2009/04/24/c-programming-visual-windows/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>What is CGI and How Can It Be Useful?</title>
		<link>http://microsonic.org/2009/04/17/what-is-cgi-and-how-can-it-be-useful/</link>
		<comments>http://microsonic.org/2009/04/17/what-is-cgi-and-how-can-it-be-useful/#comments</comments>
		<pubDate>Fri, 17 Apr 2009 21:15:40 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[Other]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[cgi]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[seo]]></category>
		<category><![CDATA[site]]></category>

		<guid isPermaLink="false">http://microsonic.org/?p=97</guid>
		<description><![CDATA[Well, to be honest, in the present day the CGI wrapper is used much less commonly with all the new web programming languages such as: PHP, Ruby, etc. However, CGI, to put it simply, is a kind of C wrapper for websites. The concept sounds confusing and the truth is, it is just like any [...]]]></description>
			<content:encoded><![CDATA[<p>Well, to be honest, in the present day the CGI wrapper is used much less commonly with all the new web programming languages such as: PHP, Ruby, etc. However, CGI, to put it simply, is a kind of C wrapper for websites. The concept sounds confusing and the truth is, it is just like any other programming language.</p>
<p>Let&#8217;s begin discussing the uses of it. The most important use of it today is for hosts that are not PHP (or any other language) enabled. Most hosts allow CGI (even though if programmed wrong can make the system vulnerable) if they don&#8217;t allow PHP or some other advanced server-side scripting. Normally, these files need to be placed in the &#8220;cgi-bin&#8221; to execute. Hosts do this as a sort of precaution, trying to confine the areas of break-ins due to poor programming.</p>
<p>Actually using it is different now. If you&#8217;re writing a Perl script, there is no compilation needed, you write like normal. However, if you are a C programmer, such as myself, and wish to use C, compile the source as <strong>program.cgi</strong>. Now, I&#8217;ve dabbled with Perl and can program in it fairly decently, but I&#8217;d much rather use C. It&#8217;s much easier for me. So, I&#8217;ll provide source examples for both styles here!</p>
<p>Now, let&#8217;s look at an example script:<br />
  The first and most basic script to any sort of programming is &#8220;Hello World&#8221; so I&#8217;ll provide the source for each (and the compiled binaries in the package below for the C-version scripts)</p>
<p><strong>hello_world.pl</strong> (This will run properly as is)</p>
<pre><code>#!/usr/bin/perl
# Hello World CGI Script (Perl Version) by Dennis M.
#
# Remember now, comments in Perl must begin with the '#' character

## Our content type ##
print "Content-type: text/html\n\n";

## Now print the page! ##
print "&lt;html&gt;\n
&lt;head&gt;&lt;title&gt;Hello World! <img src='http://microsonic.org/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> &lt;/title&gt;&lt;/head&gt;\n
&lt;body&gt;\n
&lt;h1&gt;Hello World!&lt;/h1&gt;\n
Hello World Script!\n
&lt;/body&gt;\n
&lt;/html&gt;";</code></pre>
<p>and here is the C source (which, again, needs to be compiled)<br />
<strong>hello_world.c</strong></p>
<pre><code>/**
 * Hello World CGI Script (C Version) by Dennis M.
 *
 * I prefer this (although it needs to be compiled) because
 * I'm a C programmer <img src='http://microsonic.org/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />
 *
 * oh yeah, and because we're compiling it with GCC or whatever
 * you use, we can use normal comments <img src='http://microsonic.org/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />
 *
 */

#include &lt;stdio.h&gt;

int main(){
  // Our content type
  printf("Content-Type: text/html;charset=us-ascii\n\n");

  // Our page!
  // We're going to break it up line by line so you can
  // see what's going on here.
  printf("&lt;html&gt;\n");
  printf("&lt;head&gt;&lt;title&gt;Hello World! <img src='http://microsonic.org/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> &lt;/title&gt;&lt;/head&gt;\n");
  printf("&lt;body&gt;\n");
  printf("&lt;h1&gt;Hello World!&lt;/h1&gt;\n");
  printf("Hello world! C style <img src='http://microsonic.org/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> \n");
  printf("&lt;/body&gt;\n");
  printf("&lt;/html&gt;\n\n");

  // Let's terminate the program now <img src='http://microsonic.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />
  return 0;
}</code></pre>
<p>Now, we won&#8217;t go too deep into the code because simply, they are two completely different languages. But, it&#8217;s important to point out that both send headers (Content-type: text/html). You can Google content-type&#8217;s and figure what does what, but there are many different types. Another commonly used type is Content-type: text/plain. Notice, if this had been the case, no HTML would have been parsed by the server and everything would have been displayed as plain-text!</p>
<p>So that&#8217;s basically it <img src='http://microsonic.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  CGI is just a wrapper to run Perl and C programming on the web!</p>
<p>Here you can download the sources AND binaries:<br />
<a href='http://microsonic.org/2009/04/17/what-is-cgi-and-how-can-it-be-useful/hello_world-cgitar/' rel='attachment wp-att-98'>CGI Tutorial &#8211; Hello World</a></p>
<p>One more tutorial left in the series! Keep sending in the questions so I have a few more topics to write about! <img src='http://microsonic.org/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Regards,<br />
Dennis M.</p>
]]></content:encoded>
			<wfw:commentRss>http://microsonic.org/2009/04/17/what-is-cgi-and-how-can-it-be-useful/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
