locked
SocketErrorStatus

    Question

  • Hi,

    Why you define an error code SocketErrorStatus Unknown = 0

    I have some code that want to use in Desktop and Metro applications for check socket error codes, and use 0 as error code seems weird. I will typically write.

    int error = ... 
    if(error)
    {
    // .. check error codes and throw.
    }

    But now i have to add a define just accommodate WinRT

    int error = ...
    #if OS_WINRT
    if(error > -1)
    #else
    if(error)
    #endif
    {
    // ... check error codes and throw
    }

    Friday, May 04, 2012 2:11 PM

Answers

  • Hello,

    We would recommend you to create different DLLs for metro and desktop application.
    First, there is no OS_WINRT macro in Metro.
    Second, there are some WIN32 APIs can not be used in Metro.
    Third, if you want to use some namespace like Windows.Networking, it will need to using the WinRT component. But this component cannot be used for desktop library.

    Best regards,
    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by pepone.onrez Tuesday, May 08, 2012 3:12 PM
    Monday, May 07, 2012 8:36 AM

All replies

  • Hello,

    We would recommend you to create different DLLs for metro and desktop application.
    First, there is no OS_WINRT macro in Metro.
    Second, there are some WIN32 APIs can not be used in Metro.
    Third, if you want to use some namespace like Windows.Networking, it will need to using the WinRT component. But this component cannot be used for desktop library.

    Best regards,
    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by pepone.onrez Tuesday, May 08, 2012 3:12 PM
    Monday, May 07, 2012 8:36 AM
  • Hi

    I actually creating different DLLs, i define OS_WINRT when compiling my library for WinRT, so i can use ifdef/endif to work around the differences, for example i use WinRT namespaces just when building for WinRT, but i prefer to avoid different source files.

    #ifdef OS_WINRT
    using namespace Windows::Networking::Sockets;
    #endif

    i suppose the easy wait for me is to use a Macro for check the error code, so i don't need to duplicate code every where. Anyway thanks for take the time to reply


    Tuesday, May 08, 2012 3:12 PM