Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Accessing Win32 APIs from WinRT app through Win32 Dll

Accessing Win32 APIs from WinRT app through Win32 Dll

Scheduled Pinned Locked Moved C / C++ / MFC
helpjsonquestion
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    msr_codeproject
    wrote on last edited by
    #1

    Hi, I am trying to call Win32 API from Windows Store App. Since Win32 APIs can not be accessed from WinRT, I have written a Win32 Dll and exposed a function. I am trying to call this function from WinRT App. But I am getting 'Access Denied' Error. Dll Code:

    extern "C" __declspec( dllexport )INT32 ScanWlan()
    {
    // Declare and initialize variables.

    HANDLE hClient = NULL;
    DWORD dwError = ERROR_SUCCESS;

    DWORD dwMaxClient = 2;
    DWORD dwCurVersion = 0;
    DWORD dwResult = 0;

    dwResult = WlanOpenHandle(dwMaxClient, NULL, &dwCurVersion, &hClient);
    if (dwResult != ERROR_SUCCESS)
    {
    WlanCloseHandle(hClient, NULL);
    wprintf(L"WlanOpenHandle failed with error: %u\n", dwResult);
    return 1;
    }

    I am able to call this funtion from WinRT App. But 'WlanOpenHandle' function failed with error 5 (ERROR_ACCESS_DENIED). I have done this using administrator login also. But still I am getting the same error. Am I doing the right thing? Can We access Win32 APIs from WinRT Apps through Dlls (at least). Any help? Thank you, Sai

    L 1 Reply Last reply
    0
    • M msr_codeproject

      Hi, I am trying to call Win32 API from Windows Store App. Since Win32 APIs can not be accessed from WinRT, I have written a Win32 Dll and exposed a function. I am trying to call this function from WinRT App. But I am getting 'Access Denied' Error. Dll Code:

      extern "C" __declspec( dllexport )INT32 ScanWlan()
      {
      // Declare and initialize variables.

      HANDLE hClient = NULL;
      DWORD dwError = ERROR_SUCCESS;

      DWORD dwMaxClient = 2;
      DWORD dwCurVersion = 0;
      DWORD dwResult = 0;

      dwResult = WlanOpenHandle(dwMaxClient, NULL, &dwCurVersion, &hClient);
      if (dwResult != ERROR_SUCCESS)
      {
      WlanCloseHandle(hClient, NULL);
      wprintf(L"WlanOpenHandle failed with error: %u\n", dwResult);
      return 1;
      }

      I am able to call this funtion from WinRT App. But 'WlanOpenHandle' function failed with error 5 (ERROR_ACCESS_DENIED). I have done this using administrator login also. But still I am getting the same error. Am I doing the right thing? Can We access Win32 APIs from WinRT Apps through Dlls (at least). Any help? Thank you, Sai

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      The value in dwMaxClient is incorrect. It should be a composite value constructed with the WLAN_API_MAKE_VERSION() macro, as described in the documentation[^].

      Use the best guess

      M 1 Reply Last reply
      0
      • L Lost User

        The value in dwMaxClient is incorrect. It should be a composite value constructed with the WLAN_API_MAKE_VERSION() macro, as described in the documentation[^].

        Use the best guess

        M Offline
        M Offline
        msr_codeproject
        wrote on last edited by
        #3

        Hi Richard MacCutchan, thank you for your reply. I changed my code like this.

        dwResult = WlanOpenHandle(WLAN_API_MAKE_VERSION(2, 0), NULL, &dwCurVersion, &hClient);

        But still its throwing the same error. Basically I'm trying to find Wi-Fi n/w interfaces and trying to get available Wi-Fi access points. If I run this code from a pure Win32 application, I am able to get the interfaces and Wi-Fi access points. But not working from WinRT App. Regards Sai

        M 1 Reply Last reply
        0
        • M msr_codeproject

          Hi Richard MacCutchan, thank you for your reply. I changed my code like this.

          dwResult = WlanOpenHandle(WLAN_API_MAKE_VERSION(2, 0), NULL, &dwCurVersion, &hClient);

          But still its throwing the same error. Basically I'm trying to find Wi-Fi n/w interfaces and trying to get available Wi-Fi access points. If I run this code from a pure Win32 application, I am able to get the interfaces and Wi-Fi access points. But not working from WinRT App. Regards Sai

          M Offline
          M Offline
          MicroVirus
          wrote on last edited by
          #4

          If you use a DLL, that DLL is loaded into your WinRT process space and shares the same security context as the WinRT apps. In other words, you cannot 'escape the sandbox' via a DLL. Unfortunately, I have no experience with programming WinRT, so I can not present you with a solution, only an answer as to why this will not work.

          M 1 Reply Last reply
          0
          • M MicroVirus

            If you use a DLL, that DLL is loaded into your WinRT process space and shares the same security context as the WinRT apps. In other words, you cannot 'escape the sandbox' via a DLL. Unfortunately, I have no experience with programming WinRT, so I can not present you with a solution, only an answer as to why this will not work.

            M Offline
            M Offline
            msr_codeproject
            wrote on last edited by
            #5

            Hi Micro Virus, thanks for your reply. I want to know are there any APIs available in WinRT to 1) Find WLAN interaface list (Win32 API - WlanEnumInterfaces) 2) Find Wi-Fi access points (Win32 API - WlanGetAvailableNetworkList) Basically I am trying to write an WinRT application to do all these. Any help? Regards, Sai

            M 1 Reply Last reply
            0
            • M msr_codeproject

              Hi Micro Virus, thanks for your reply. I want to know are there any APIs available in WinRT to 1) Find WLAN interaface list (Win32 API - WlanEnumInterfaces) 2) Find Wi-Fi access points (Win32 API - WlanGetAvailableNetworkList) Basically I am trying to write an WinRT application to do all these. Any help? Regards, Sai

              M Offline
              M Offline
              MicroVirus
              wrote on last edited by
              #6

              A quick search delivered this: http://msdn.microsoft.com/en-us/library/windows/apps/br207308.aspx[^] Might be promising? But, as I said in my previous post, I do not have experience with Win RT apps myself and do not have a clear answer for you. Best regards, Richard

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups