title: WlanGetAvailableNetworkList fails first call and then succeeds
body: <p>I am trying to call WlanGet Available Network and it fails with error 1168 (ERROR_NOT_FOUND), then rerunning succeeds.  I think it is how I am initiializing the out pointer, but have not been able to make it work, even though I can get the GUID pointer repeatably.  I am building a managed wrapper for my own use, so right now my calling code is an Nunit framework.</p>
  
  <p>Output from failed run:</p>
  
  <pre><code>        ***** zz_Test_Fixture_TDD.NetworkListTester.NetworkListTest
  Guid Pointer = 89327880
  Client Handle and GUID pointers initialized
   handle 1   Guid pointer = 89327880 Avail network pointer = 0
   handle 1   Guid pointer = 89327880 Avail network pointer = 0
  Wlan Get Avail networks Failed by error =1168
  </code></pre>
  
  <p>Output from passing run:</p>
  
  <pre><code>***** zz_Test_Fixture_TDD.NetworkListTester.NetworkListTest
  Guid Pointer = 89008544
  Client Handle and GUID pointers initialized
   handle 17   Guid pointer = 89008544 Avail network pointer = 0
   handle 17   Guid pointer = 89008544 Avail network pointer = 89415752
  Number of Networks Found = 18
  </code></pre>
  
  <p>Here is my code:</p>
  
  <pre><code>    [TestFixture]
              public class NetworkListTester
              {
               IntPtr pclientHandle;
              Guid ThisInterfaceGuid;
              IntPtr pGuid;
  
              [Test]
              public void NetworkListTest()
              {
               pclientHandle = WiFiApi.GetClientHandle();
              ThisInterfaceGuid = WiFiApi.GetCurrentInterfaceGuid(pclientHandle);
              pGuid = WiFiApi.GetCurrentInterfaceGuidPointer(pclientHandle);
              Console.WriteLine("Guid Pointer = " + pGuid);
              Console.WriteLine("Client Handle and GUID pointers initialized");
  
  
              IntPtr pAvailNetWorks = new IntPtr();
  
          uint dwFlags = 3;
          uint error = 99;
          Console.WriteLine(" handle " + pclientHandle + "   Guid pointer = " + pGuid + " Avail network pointer = " + pAvailNetWorks);
          error = WiFiApi.WlanGetAvailableNetworkList(pclientHandle, pGuid, dwFlags, IntPtr.Zero, out pAvailNetWorks);
          Console.WriteLine(" handle " + pclientHandle + "   Guid pointer = " + pGuid + " Avail network pointer = " + pAvailNetWorks);
          if (error != 0)
          {
  
              Console.WriteLine("Wlan Get Avail networks Failed by error =" + error);
  //same impact with or without this retry
  //also added a Thread.Sleep(60000); before the call with no impact
              error = WiFiApi.WlanGetAvailableNetworkList(pclientHandle, pGuid, dwFlags, IntPtr.Zero, out pAvailNetWorks);
  
          }
          else
          {
              //tests intentionally outside of else so they will fail if an error.
          }
          //todo get managed pointer for available networks
          WiFiApi.WLAN_AVAILABLE_NETWORKS_LIST NetworkList = (WiFiApi.WLAN_AVAILABLE_NETWORKS_LIST)Marshal.PtrToStructure(pAvailNetWorks, typeof(WiFiApi.WLAN_AVAILABLE_NETWORKS_LIST));
          Console.WriteLine("Number of Networks Found = " + NetworkList.NumberOfNetworks);
          Assert.Greater(NetworkList.NumberOfNetworks, 0);
          Assert.Less(NetworkList.CurrentNetwork, NetworkList.NumberOfNetworks);
  
  
                  //close handle
          WiFiApi.CloseClientHandle(pclientHandle);
          WiFiApi.WlanFreeMemory(pGuid);
                  WiFiApi.WlanFreeMemory(pAvailNetWorks);
  
              }
  </code></pre>
  
  <p>here is the function I am calling:</p>
  
  <pre><code>        [DllImport("Wlanapi.dll")]
      public static extern uint WlanGetAvailableNetworkList(
                  IntPtr _hClientHandle,
                  IntPtr _InterfaceGuid,
                  UInt32 _dwFlags,
                  IntPtr _pReserved,
                  out IntPtr ppAvailableNetworkList);
  </code></pre>