<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" version="2.0"><channel><atom:id>tag:blogger.com,1999:blog-2564727807675329457</atom:id><lastBuildDate>Mon, 28 Nov 2011 00:30:04 +0000</lastBuildDate><category>stronglib sockets winsock2.h windows</category><category>stronglib iriepascal foundation</category><title>Web Programming in C</title><description>The StrongLib Libraries are being created to make it easy to write web programs using the C programming language. This blog will follow the development of these libraries.</description><link>http://stronglib.blogspot.com/</link><managingEditor>noreply@blogger.com (Stuart King)</managingEditor><generator>Blogger</generator><openSearch:totalResults>2</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/WebProgrammingInC" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="webprogramminginc" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2564727807675329457.post-7956620764394785229</guid><pubDate>Sat, 02 Oct 2010 01:25:00 +0000</pubDate><atom:updated>2010-10-01T20:26:14.941-05:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">stronglib sockets winsock2.h windows</category><title>Safely including "winsock2.h" and "windows.h" at the same time.</title><description>Today, I learned that including "windows.h" and "winsock2.h" at the same time can cause compile-time errors. As soon as I included "winsock2.h" the compiler started complaining about some symbols being redefined.&lt;br /&gt;
&lt;br /&gt;
It turns out that&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;"windows.h" includes "winsock.h" and&lt;/li&gt;
&lt;li&gt;"winsock.h" and "winsock2.h" contain definitions of some of the same symbols.&lt;/li&gt;
&lt;/ul&gt;So if you include both "windows.h" and "winsock2.h" some symbols may be redefined. I say "may be redefined" because there are ways to prevent this.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Solution #1&lt;/b&gt;&lt;br /&gt;
The first solution I considered was to make sure "winsock2.h" is included before "windows.h".&lt;br /&gt;
&lt;br /&gt;
This works because "winsock2.h" defines _WINSOCKAPI_ which prevents the compiler from seeing the contents of "winsock.h" ("winsock.h" is guarded by the following):&lt;br /&gt;
&lt;br /&gt;
#ifndef _WINSOCKAPI_&lt;br /&gt;
#define _WINSOCKAPI_&lt;br /&gt;
&lt;br /&gt;
...&lt;br /&gt;
Contents of winsock.h&lt;br /&gt;
...&lt;br /&gt;
&lt;br /&gt;
#endif&amp;nbsp; /* _WINSOCKAPI_ */&lt;br /&gt;
&lt;br /&gt;
So if _WINSOCKAPI_ is already defined, the entire file is skipped.&lt;br /&gt;
&lt;br /&gt;
I didn't really like this solution because I don't like relying on header files being included in any particular order (and it's just too much hassle).&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Solution #2&lt;/b&gt;&lt;br /&gt;
The second solution, which I discovered while searching on the Internet, is to define WIN32_LEAN_AND_MEAN before including "windows.h".&lt;br /&gt;
&lt;br /&gt;
This works because defining WIN32_LEAN_AND_MEAN prevents "windows.h" from including several header files (including "winsock.h").&lt;br /&gt;
&lt;br /&gt;
I almost used this solution, but I was concerned that it was doing more than I really need. It was preventing "windows.h" from including a number of header files, not just the one I wanted.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Solution #3&lt;/b&gt;&lt;br /&gt;
The solution I decided to use was to define _WINSOCKAPI_ before including "windows.h".&lt;br /&gt;
&lt;br /&gt;
This works for the same reason Solutions #1 works, it prevents the compiler from seeing the contents of "winsock.h".&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Not Perfect &lt;/b&gt;&lt;br /&gt;
Solution #3 is not quite perfect because I still have to make sure to define _WINSOCKAPI_ before including "windows.h".&lt;br /&gt;
&lt;br /&gt;
The perfect solution I think would be for Microsoft to modify "windows.h" so that the inclusion of "winsock.h" is conditional on a symbol being undefined. For example:&lt;br /&gt;
&lt;br /&gt;
#ifndef WIN32_NO_WINSOCK_H&lt;br /&gt;
#include #include &amp;lt;winsock.h&amp;gt;&lt;br /&gt;
#endif&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2564727807675329457-7956620764394785229?l=stronglib.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://stronglib.blogspot.com/2010/10/safely-including-winsock2h-and-windowsh.html</link><author>noreply@blogger.com (Stuart King)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-2564727807675329457.post-8981589621509518726</guid><pubDate>Tue, 20 Oct 2009 19:43:00 +0000</pubDate><atom:updated>2009-10-20T16:43:23.471-05:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">stronglib iriepascal foundation</category><title>Introducing StrongLib</title><description>&lt;span style="font-size: x-large;"&gt;Introduction&lt;/span&gt;&lt;br /&gt;
This is the first post for "Web Programming in C",  so now is a perfect time to answer some questions about this blog, for example: What is StrongLib? Why is it being created? Why should you care?&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-size: large;"&gt;What is StrongLib?&lt;/span&gt;&lt;br /&gt;
OK, easy question first. StrongLib is the name I've come up with for  what will hopfully be a series of C libraries that will make it easy to write web programs in C. What kinds of web programs? Well, to start, two kinds:&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Web Server applications. The kinds of applications, that PHP and ASP are currently used for.&lt;/li&gt;
&lt;li&gt;Desktop applications that consume services from the  web.&lt;/li&gt;
&lt;/ul&gt;&lt;span style="font-size: large;"&gt;Why Create StrongLib?&lt;/span&gt;&lt;br /&gt;
I have been building the next release of  &lt;a href="http://www.irietools.com/iriepascal/"&gt;Irie Pascal&lt;/a&gt;, which is going to be focussed on web programming, and I decided that it makes sense to create a seperate library to handle all of the web programming details, and then create the next release of Irie Pascal on top of that library.&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-size: large;"&gt;StrongLib Foundation&lt;/span&gt;&lt;br /&gt;
The first StrongLib library is the foundation library, StrongLib Foundation. So far the design goals for this library are:&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Provide a low-to-mid level API for common web operations (e.g. with functions for processing Unicode, and using sockets.&lt;/li&gt;
&lt;li&gt;Make it easier to write portable code for all of the  operating systems supported by Irie Pascal, namely Windows, Linux, FreeBSD, and Solaris.  I am not tring to create some some big complicated cross-platform library that takes over your application. I just want to  eliminate some of the really unnecessary differences between OS APIs (the different but functionally equivalent APIs for thread creation for example).&lt;br /&gt;
&lt;/li&gt;
&lt;/ul&gt;&lt;span style="font-size: large;"&gt;Learning how to use Blogger &lt;/span&gt;&lt;br /&gt;
This is my first  blog on Blogger (I was using Wordpress before), so this first post is also kind of an experiment.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2564727807675329457-8981589621509518726?l=stronglib.blogspot.com' alt='' /&gt;&lt;/div&gt;</description><link>http://stronglib.blogspot.com/2009/10/introducing-stronglib.html</link><author>noreply@blogger.com (Stuart King)</author><thr:total>2</thr:total></item></channel></rss>

