<?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>Misterdom's World &#187; visualstudio</title>
	<atom:link href="http://www.guinard.org/~misterdom/tag/visualstudio/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.guinard.org/~misterdom</link>
	<description>My Computing Logbook</description>
	<lastBuildDate>Fri, 25 Jun 2010 14:12:52 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Giving some REST to your C++ code: embedding the SHTTPD server.</title>
		<link>http://www.guinard.org/~misterdom/2008/10/27/giving-some-rest-to-your-c-code-embedding-the-shttp-server/</link>
		<comments>http://www.guinard.org/~misterdom/2008/10/27/giving-some-rest-to-your-c-code-embedding-the-shttp-server/#comments</comments>
		<pubDate>Mon, 27 Oct 2008 14:28:33 +0000</pubDate>
		<dc:creator>misterdom</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[Dev Logbook]]></category>
		<category><![CDATA[Plogg and Smart Meters]]></category>
		<category><![CDATA[Visual Studio .Net]]></category>
		<category><![CDATA[HTTP]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[visualstudio]]></category>
		<category><![CDATA[webserver]]></category>

		<guid isPermaLink="false">http://www.guinard.org/~misterdom/?p=21</guid>
		<description><![CDATA[Wanting to turn the Ploggs, into more RESTful devices, I needed to add a web server (HTTP) to the C++ code managing the Ploggs.
After comparing and trying a number of lightweight web servers (Apache was not an option for this kind of small app) I picked SHTTPD, mainly because:

 It was one of the few [...]]]></description>
			<content:encoded><![CDATA[<p>Wanting to turn the <a href="?cat=4">Ploggs</a>, into more RESTful devices, I needed to add a web server (HTTP) to the C++ code managing the Ploggs.</p>
<p>After comparing and trying a number of lightweight web servers (Apache was not an option for this kind of small app) I picked <a href="http://shttpd.sourceforge.net/">SHTTPD</a>, mainly because:</p>
<ol>
<li> It was one of the few I managed to embed in my C++ code (I&#8217;m not a C expert&#8230;)</li>
<li> It offered the possibility of registering call back methods when a particular URL is called, which makes it a quite good candidate for a REST interface.</li>
</ol>
<p>Here is how I did proceed to integrate it to my Microsoft Visual C++ project:</p>
<ol>
<li>Compile the project (the core, not the example), this should create a <code>shttpd.lib</code> file. (<a href="?p=17">This post might in case you do not succeed this step </a>).</li>
<li>Copy the shttpd.lib, shttpd.h to your src folder (the one of your Visual Studio project).</li>
<li>Download <a href="http://shttpd.sourceforge.net/shttpd.pem">shttpd.pem</a> and copy it to your src folder as well.</li>
<li>Add the <code>shttpd.h</code> file to your project.</li>
<li>Add the following lib references to your project: <code>shttpd.lib ws2_32.lib</code>, see <a href="?p=15">to get details on how to add it.</a></li>
<li>Add the code to start and setup the server. Snippets can be found in the example folder of the SHTTPD distrib. That in my case:</li>
</ol>
<p><code><br />
// TestSHTTPD.cpp : Defines the entry point for the console application.<br />
#include<br />
#include<br />
#include<br />
#include<br />
#include </code></p>
<p>#include &#8220;stdafx.h&#8221;<br />
#include &#8220;shttpd.h&#8221;</p>
<p>#define ALIAS_URI &#8220;/my_c&#8221;<br />
#define ALIAS_DIR &#8220;c:\\&#8221;</p>
<p>static void show_index(struct shttpd_arg *arg) {<br />
shttpd_printf(arg, &#8220;%s&#8221;,<br />
&#8220;HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n&#8221;<br />
&#8220;Welcome to embedded example of SHTTPD&#8221;);<br />
arg-&gt;flags |= SHTTPD_END_OF_OUTPUT;<br />
}</p>
<p>int _tmain(int argc, char* argv[])<br />
{<br />
/*<br />
* Initialize SHTTPD context.<br />
* Attach folder c:\ to the URL /my_c  (for windows), and<br />
* /etc/ to URL /my_etc (for UNIX). These are Apache-like aliases.<br />
* Set WWW root to current directory.<br />
* Start listening on ports 8080 and 8081<br />
*/<br />
int	data = 1234567;<br />
struct shttpd_ctx	*ctx;<br />
ctx = shttpd_init(argc, argv);<br />
shttpd_set_option(ctx, &#8220;ssl_cert&#8221;, &#8220;shttpd.pem&#8221;);<br />
shttpd_set_option(ctx, &#8220;aliases&#8221;, ALIAS_URI &#8220;=&#8221; ALIAS_DIR);<br />
shttpd_set_option(ctx, &#8220;ports&#8221;, &#8220;8080,8081s&#8221;);</p>
<p>/* Register an index page under two URIs */<br />
shttpd_register_uri(ctx, &#8220;/&#8221;, &amp;show_index, (void *) &amp;data);<br />
shttpd_register_uri(ctx, &#8220;/abc.html&#8221;, &amp;show_index, (void *) &amp;data);</p>
<p>/* Serve connections infinitely until someone kills us */<br />
for (;;)<br />
shttpd_poll(ctx, 1000);</p>
<p>/* Probably unreached, because we will be killed by a signal */<br />
shttpd_fini(ctx);</p>
<p>return 0;<br />
}</p>
<p>You should now be able to use the web server within your application.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.guinard.org/~misterdom/2008/10/27/giving-some-rest-to-your-c-code-embedding-the-shttp-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using a dll library from one Visual Studio Express 2008 project in another</title>
		<link>http://www.guinard.org/~misterdom/2008/10/23/using-a-dll-library-from-one-visual-studio-express-2008-project-in-another/</link>
		<comments>http://www.guinard.org/~misterdom/2008/10/23/using-a-dll-library-from-one-visual-studio-express-2008-project-in-another/#comments</comments>
		<pubDate>Thu, 23 Oct 2008 08:07:08 +0000</pubDate>
		<dc:creator>misterdom</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[Dev Logbook]]></category>
		<category><![CDATA[Visual Studio .Net]]></category>
		<category><![CDATA[dll]]></category>
		<category><![CDATA[linker]]></category>
		<category><![CDATA[visualstudio]]></category>

		<guid isPermaLink="false">http://www.guinard.org/~misterdom/?p=15</guid>
		<description><![CDATA[Coming from the Java world I would describe dlls as sort of jar files. A dll represents the component part of an application, that is: not the end-user part but rather the re-usable part of a Windows app. The so-called API of a dll is the .h file. That means the .h file contains all [...]]]></description>
			<content:encoded><![CDATA[<p>Coming from the Java world I would describe dlls as sort of jar files. A dll represents the component part of an application, that is: not the end-user part but rather the re-usable part of a Windows app. The so-called API of a dll is the .h file. That means the .h file contains all the methods, or functions that one can call on the dll.</p>
<p>To use the dll of Visual Studio (Express 2008) project A in project B we do what microsoft calls an implicit linking (<a href="http://msdn.microsoft.com/en-us/library/d14wsce5(VS.80).aspx">http://msdn.microsoft.com/en-us/library/d14wsce5(VS.80).aspx</a>). In more concrete terms here are the steps to follow:</p>
<p>1) Generate the dll of project A. When you do this, the linker (after-compiler thingy) creates both a dll and a lib file.<br />
2) Copy the dll and the lib file to project B, namely to a place accessible by the compiler and the linker, a place that&#8217;s on the classpath to use the Java terminology.<br />
3) Right-click on the project B in Visual Studio and select Configuration Properties -&gt; Linker -&gt; Input -&gt; Additional Dependencies<br />
4) There you can select the .lib counterpart of the dll (e.g. swill.lib in my case).</p>
<div id="attachment_14" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.guinard.org/~misterdom/wp-content/uploads/2008/10/implicit_link.jpg"><img class="size-medium wp-image-14" title="implicit_link" src="http://www.guinard.org/~misterdom/wp-content/uploads/2008/10/implicit_link-300x187.jpg" alt="Add additional dependencies" width="300" height="187" /></a><p class="wp-caption-text">Add additional dependencies</p></div>
<p>5) Add the header file (.h) of the dll to your project.</p>
<p>That&#8217;s it you should now be able to use the dll of A from project B, at least it worked fine for me.<br />
Btw, being mainly a Java developer, I&#8217;m rather new to C++ so if that&#8217;s a silly way of doing it please do comment the post.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.guinard.org/~misterdom/2008/10/23/using-a-dll-library-from-one-visual-studio-express-2008-project-in-another/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
