Using curl in a Windows Universal App
<p>I want to use curl in a Windows Universal App (x64).</p>

<p>I managed to get it working, but I had to use a workaround that seems hackish, and I want to confirm that it is needed. </p>

<p><strong>TL;DR</strong> - I had to add an <code>#include &lt;winsock2.h&gt;</code> statement before the <code>#include &lt;curl\curl.h&gt;</code> statement, to get it to work. I want to know if it’s truly needed on UWP.</p>

<p>I built curl with openssl by following the curl install guide <a href="https://curl.haxx.se/docs/install.html]" rel="nofollow">here</a>. I created a blank universal app in Visual Studio 2015 update 3, and added curl and openssl binaries and includes in the appropriate places. Then added a <code>#include &lt;curl\curl.h&gt;</code> at the top of the file and got the following error:</p>

<p><code>error C4430: missing type specifier - int assumed. Note: C++ does not support default-int</code> for the line <code>typedef SOCKET curl_socket_t;</code> in <code>curl.h</code>.</p>

<p>At the top of <code>curl.h</code> I saw that the following preprocessor macros prevent the inclusion of <code>winsock2.h</code> which defines <code>SOCKET</code>:</p>

<pre><code>#if !(defined(_WINSOCKAPI_) || defined(_WINSOCK_H) || \
      defined(__LWIP_OPT_H__) || defined(LWIP_HDR_OPT_H))
/* The check above prevents the winsock2 inclusion if winsock.h already was
   included, since they can't co-exist without problems */
    #include &lt;winsock2.h&gt;
    #include &lt;ws2tcpip.h&gt;
#endif
</code></pre>

<p>Removing the <code>defined(_WINSOCKAPI_)</code> condition restores the statement and everything compiles fine, meaning that somewhere <code>winsock.h</code> is included and that on UWP it does not defined <code>SOCKET</code>.</p>

<p>Indeed, looking at <code>winsock.h</code> I can see that the <code>typedef</code> which defines <code>SOCKET</code> is wrapped with </p>

<pre><code>#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
</code></pre>

<p>which does not hold for a universal app.</p>

<p>However, in <code>winsock2.h</code> there’s an equivalent <code>typedef</code> for <code>SOCKET</code> which is not dropped by the preprocessor.</p>

<p>Adding <code>#include &lt;winsock2.h&gt;</code> before the <code>#include &lt;curl\curl.h&gt;</code> statement makes everything work, but I suspect this is not the best way to solve this issue.</p>

<p>So my question is, is this the proper way to use curl on UWP or has anyone found a better solution?</p>

<p>Thanks!</p>