Accessing Win32 APIs from WinRT app through Win32 Dll
-
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
-
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
-
The value in
dwMaxClient
is incorrect. It should be a composite value constructed with theWLAN_API_MAKE_VERSION()
macro, as described in the documentation[^].Use the best guess
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
-
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
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.
-
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.
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
-
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
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