locked
Load the compiled source based on Operating System version RRS feed

  • Question

  • I am using WinHttp functions for internet download in a VC++ application.

    When I need to stop lengthy, time taking download for some reason, WinHttpWebSocketClose function is used.

    But that function is supported from Win8 and later OS only.

    So my application will throw an error "WinHttpWebSocketClose is not found in Winhttp.dll" in Win7 & older OS while launching the application.

    I would like to know, can we have some code or function which can be loaded based on OS version, otherwise skip that, within the same application(not as a separate module such as dll)?


    Thanks & Regards


    • Edited by rp_suman Friday, April 19, 2019 12:47 PM
    Friday, April 19, 2019 12:43 PM

All replies

  • You can load and call the function dynamically (LoadLibrary-GetProcAddress)
    Friday, April 19, 2019 12:54 PM
  • You also don't need to do any version check for this either.

    The GetProcAddress function will only succeed if the module handle passed in is valid and the function exists in the DLL. So the pointer to this function will be NULL prior to Windows 8 and a valid pointer to the function from Windows 8 onwards.


    This is a signature. Any samples given are not meant to have error checking or show best practices. They are meant to just illustrate a point. I may also give inefficient code or introduce some problems to discourage copy/paste coding. This is because the major point of my posts is to aid in the learning process.

    Friday, April 19, 2019 5:13 PM
  • Finally, you mention "Win7 & older OS".

    So to be safe you should define _WIN32_WINNT for the oldest version of Windows that you intend to support.

    Any function that was introduced in a later version should be used with LoadLibrary/GetProcAddress.

    And if you intend to support XP you should use the toolset that creates XP compatible binaries.

    Friday, April 19, 2019 5:30 PM
  • Hi,

    Have you got any updates? If your case has been solved, please help to mark answers. If not, just feel free to contact us.

    Your understanding and cooperation will be grateful.

    Best Regards,

    Jeanine Zhang

    Friday, April 26, 2019 5:26 AM