1

So I have a Visual Studio 2013 Update 4 solution with 2 projects inside, one target Windows 8.1, other Windows Phone 8.1 configured to build static lib.

Project is open sourced, so here is the solution for reference: https://github.com/gideros/gideros/tree/master/winrt

What I need to do, is to make it use networking code, which uses winsockets. Since this is a library project, there was no Linker section in project properties, so I simply included

#include <WinSock2.h>
#pragma comment(lib, "Ws2_32.lib")

Both projects built without errors and when library included in Windows Phone app, it worked exactly as expected, but in Windows app networking part was not working, but also no errors or crashes.

I ran it through App Certification program and it said:

Error Found: The supported APIs test detected the following errors:
API WSACleanup in ws2_32.dll is not supported for this application type. 

and lots of other references to ws2_32 library

I started searching on internet, and there were lots of posts stating that you can't use winsocket on Windows 8.1, you have to use Microsoft's winrt socket implementation etc.

But then I stumbled on this blog announcing that it is now (since VS 2013 Update 3) possible to use winsock on both Windows 8.1 and Windows Phone 8.1

http://blogs.windows.com/buildingapps/2014/10/13/winsock-and-more-open-source-for-your-windows-store-apps/

Quoting:

We’re happy to announce that starting with the release of Visual Studio 2013 Update 3 (download) in August, the Windows App Certification Kit (WACK) allows use of WinSock APIs in your Windows Store apps. And since WinSock was already allowed to pass certification on Windows Phone, this work completes the story. Now WinSock is available universally across Windows 8.1, Windows Phone 8.1, and universal apps.

As I had VS 2013 Update 4, it should have already worked. So I checked App certification version (it was 3.3), and it stated it had update available, so I downloaded Windows SDK for Windows 8.1 from:

https://dev.windows.com/en-us/develop/app-certification-kit

And now I can't even build the project, because it says that all Ws2_32.lib parts are missing for Windows 8.1 target. (while Windows Phone 8.1 still builds and works as expected)

So is it even possible to use winsockets on Windows 8.1 apps? And if yes, what am I missing?

Update 1:

It seems to be possible, but the problem is with my set up.

When I check the header files where my project points, then they are:

for Windows phone its

Program Files (x86)/Windows Phone Kits/8.1/Include/winsock2.h

for Windows it

Program Files (x86)/Windows Kits/8.1/Include/um/WinSock2.h

And when I check the file that is for Windows, then it has a preprocessor defined:

#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)

And it does not go into this if statement, thus for compiler this file is basically empty

I even tried to uninstall Windows 8.1 SDK, which did not change anything.

Then I manually removed files from Program Files folder and installed a new one from

https://dev.windows.com/en-us/develop/app-certification-kit

still I have the same header. So where do I get latest Windows 8.1 SDK with proper winsock2 header file?

Update 2:

So I removed everything and re-installed clean VS 2013 Express Update 4 and again same result, it all builds without errors, but networking does not work on Windows 8.1 app, while it perfectly works on Windows Phone 8.1.

It is like Windows 8.1 have only empty stubs, that do nothing.

I've been asking in Windows developer forum and one of the Microsoft representatives stated that, quoting:

If you have VS 2013 Update 4 properly installed, then you will have gotten an updated Windows 8.1 SDK. In that version of winsock2.h, only the ASCII versions of most of the WinSock APIs are excluded from Windows Store. You have to use UNICODE exclusively for Windows 8 Store apps.

Unfortunately I have no idea what that means and how should I proceed. If that means defining UNICODE macro then it is already defined.

Update 3:

I've managed to debug the winsocket code and everything is running as expected there, server is listening on the port. But nothing can connect to it. It's like it is running in sandboxed mode

Update 4:

Running netstat and wireshark all seems to work correctly and see server and I can even connect to it from other computer. But I can't connect from the same computer.

And it seems that MS forbids Windows apps to communicate with desktop apps on the same machine

I have no idea why, anyone can provide any insights?

How can a Metro app in Windows 8 communicate with a backend desktop app on the same machine?

The last question is

If VS 2013 Update 4 bundles winsock2 header that builds with WACK 3.3 that does not allow winsockets, while Windows 8.1 SDK update has WACK3.4 that allows socket API, but bundles older winsock2 header which does not build.

How to get WACK3.4 with correct winsock2 setup?

Community
  • 1
  • 1
Artūrs Sosins
  • 579
  • 5
  • 21
  • The problem is that I can use it on Phone app and it works and Certification did not have problems with that, it is all allowed. I have problems with Windows 8.1 app, not a phone app – Artūrs Sosins Apr 18 '15 at 12:44
  • It is, if you are going to submit it to Windows Store but again, it is not the problem, problem is that I can't build Windows 8.1 project with ws2_32.lib while Windows Phone 8.1 project works – Artūrs Sosins Apr 18 '15 at 12:49
  • I'm sorry I have no information about such restrictions, but it should at least build without errors, right? – Artūrs Sosins Apr 18 '15 at 12:51
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/75586/discussion-between-artrs-sosins-and-hans-passant). – Artūrs Sosins Apr 18 '15 at 13:38
  • WinSock has been supported in Windows Phone since 8.0, and is supported in Windows 8.1 also. The WACK won't fail you for using WinSock. – Peter Torr - MSFT Apr 18 '15 at 18:05

2 Answers2

1

WinSock is supported on Windows and Windows Phone, and is allowed using WACK 3.4. It works for me using both #pragma comment(lib, "ws2_32.lib") and by adding ws2_32.lib directly to the project settings.

It looks like there is something wrong with the way you are building the project after the upgrade; can you post the errors you got after the upgrade?

Peter Torr - MSFT
  • 11,824
  • 3
  • 18
  • 51
  • Baically the winsock functions do not exist, even though winsock2.h was included I opened winsock2.h file and it seems it does not go into macro #if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) so whole file is like empty to compiler – Artūrs Sosins Apr 18 '15 at 21:11
  • You are probably picking up the headers from the old SDK. What directory is the header file being loaded from? Check your project include path settings. – Peter Torr - MSFT Apr 18 '15 at 23:38
  • OK now you can build, you need to debug what is going on. Do you check the return values of all the WinSock functions in your code? Have you tried stepping through with the debugger? Any places where you have `#ifdef`s that might be excluding code on Windows? – Peter Torr - MSFT Apr 19 '15 at 14:50
  • Unfortunately debugging is quite difficult as I said, this is a solution for static library, which will be used by some other projects, is there a way to debug static library projects in VS? I tried disabling JMC and set Zi for Debug info, but I don't get PDB files generated, nor static lib seem to contain it by itself. So I'm clueless on how to debug such thing. Also call me naive, but I kind of expected it to work out of the box, since the same code works for Windows Desktop programs, QT programs and even Windows Phone, that's why I still think something is wrong :) – Artūrs Sosins Apr 19 '15 at 15:47
  • Another thing that confuses me is that VS 2013 Update 4 bundles winsock2 header that builds with WACK 3.3 that does not allow it, while Windows 8.1 SDK update has WACK3.4 that allows socket API, but bundles older winsock2 header which does not build. How does that makes sense? :) – Artūrs Sosins Apr 19 '15 at 15:51
  • Ok, it seems all socket stuff actually work, it is only not possible to connect from the same machine (which the tests actually did), I have no idea why, but it seems Microsoft forbids it. So only need to get wack 3.4 with proper socket set up – Artūrs Sosins Apr 19 '15 at 17:23
0

So basically sockets do work, but there are couple of cases to be aware of.

There is a network isolation, which does not allow to connect to Windows Store apps from same machine (as I did in my tests and thought networking does not work).

But if you can connect from remote machine, everything works as expected.

More info on that:

https://msdn.microsoft.com/en-us/library/windows/desktop/dd374089%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396

But you still won't be able to pass WACK (which is not needed to submit to store, but still)

Problem is that VS 2013 Update 4 bundles winsock2 header that builds and works and it has WACK 3.3 software that does not allow winsockets.

While Windows 8.1 SDK update has WACK3.4 that allows socket API, but bundles older winsock2 header which does not build and work.

As you don't need to run WACK to submit app, mostly it won't be a problem, but as I needed to check if there are any other specific libraries I use, that can be prohibited, then I had to only install single (App certification) component from Windows 8.1 SDK from here:

https://dev.windows.com/en-us/develop/downloads

And I have WACK 3.4 and proper winsockets now

Still too bad about network isolation, that basically kills the purpose of what I was porting in the first place. Making all the work basically in vain.

Artūrs Sosins
  • 579
  • 5
  • 21
  • 1
    Sorry it didn't work out for you; I don't know the specifics but I believe there is a security concern with loopback addresses in Store apps. I've not seen the case where VS has a mismatched SDK / WACK but then all my machines have a lot of cruft on them :-). I will pass along just in case. – Peter Torr - MSFT Apr 19 '15 at 20:01