C# Win: Wireless Zero Config API

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ShadowLocke
    New Member
    • Jan 2008
    • 116

    #1

    C# Win: Wireless Zero Config API

    Hi all,

    I am trying to tap in to wzcsapi.dll in windows using c#. Im able to call the funtion WZCEnumInterfac es with no problem. The problem I have is when I call the function WZCQueryInterfa ce it gives me an error return code of 2 (File not found) I cant figure out whats going on here..what file is it looking for?


    Code:
    public struct RAW_DATA
            {
                public uint dwDataLen;
                public uint pData;
            }
    
            public struct INTF_ENTRY
            {
                public uint wszGuid;
                public uint wszDescr;
                public UInt32 ulMediaState;
                public UInt32 ulMediaType;
                public UInt32 ulPhysicalMediaType;
                public int nInfraMode;
                public int nAuthMode;
                public int nWepStatus;
                public uint dwCtlFlags;
                public uint dwCapabilities;
                public RAW_DATA rdSSID;
                public RAW_DATA rdBSSID;
                public RAW_DATA rdBSSIDList;
                public RAW_DATA rdStSSIDList;
                public bool bInitialized;
            }
    
            public struct INTF_KEY_ENTRY
            {
                public uint wszGuid;
            }
    
            public struct INTFS_KEY_TABLE
            {
                public uint dwNumIntfs;
                public INTF_KEY_ENTRY pIntfs;
            }
    
            [DllImport("wzcsapi.dll")]
            public static extern uint WZCEnumInterfaces(string pSrvAddr, ref INTFS_KEY_TABLE pIntfs);
    
            [DllImport("wzcsapi.dll")]
            public static extern uint WZCQueryInterface(string pSrvAddr, uint dwInFlags, ref INTF_ENTRY pIntf, ref uint pdwOutFlags);
    
    
            static void Main(string[] args)
            {
                INTFS_KEY_TABLE pIntfs = new INTFS_KEY_TABLE();
                INTF_ENTRY Intf = new INTF_ENTRY();
                uint uiRet;
                uint uiInFlags = 0xFFFFFFFF;
                uint uiOutFlags = 0;
    
                uiRet = WZCEnumInterfaces(null, ref pIntfs);
    
                Intf.wszGuid = pIntfs.pIntfs.wszGuid;
    
                uiRet = WZCQueryInterface(null, uiInFlags, ref Intf, ref uiOutFlags);
    
               //uiRet = 2
            }
  • ShadowLocke
    New Member
    • Jan 2008
    • 116

    #2
    Ah..the file it is looking for is the string that wzsGuid points to. It's the network interface dll file. I was passing the pointer (which is a number) to WZCQueryInterfa ce, and it wanted the string it self.

    Now if I can only figure out why i can get the SSID length but not the SSID it self...

    Comment

    • imkaush
      New Member
      • Sep 2015
      • 1

      #3
      Hi ShadowLocke,

      I am also trying to use Wireless Zero Config API (WZCQueryInterf aceEx and WZCSetInterface Ex) in a WinCE 6 C# project.

      The project builds successfully but I get the following exception:
      Calling WZCQueryInterfa ceEx returns a 'NotSupportedEx ception'

      Here's my code snippet:
      Code:
      public struct RAW_DATA
      {
          public UInt32 dwDataLen;
          public char pData;
      }
      
      public struct INTF_ENTRY_EX
      {
           public string wszGuid;
           public string wszDescr;
           public UInt32 ulMediaState;
           public UInt32 ulMediaType;
           public UInt32 ulPhysicalMediaType;
           public int nInfraMode;
           public int nAuthMode;
           public int nWepStatus;
           public UInt32 dwCtlFlags;     // control flags (see INTFCTL_* defines)
           public UInt32 dwCapabilities; // capabilities flags (see INTFCAP_* defines)
           public RAW_DATA rdSSID;         // encapsulates the SSID raw binary
           public RAW_DATA rdBSSID;        // encapsulates the BSSID raw binary
           public RAW_DATA rdBSSIDList;    // encapsulates one WZC_802_11_CONFIG_LIST structure
           public RAW_DATA rdStSSIDList;   // encapsulates one WZC_802_11_CONFIG_LIST structure
           public RAW_DATA rdCtrlData;     // data for various control actions on the interface  
      #if UNDER_CE
           public bool            bInitialized;   //  To track caller that freeing
           //  the same structure more than one time..
      #endif
           public UInt32 nWPAMCastCipher;
      
           public UInt32 ulVersion;
           public RAW_DATA rdNicCapabilities;  // points to INTF_80211_CAPABILITY.
           public RAW_DATA rdPMKCache;         // points to NDIS_802_11_PMKID.
           public UInt32 PMKCacheFlags;
      }
      public INTF_ENTRY_EX g_IntfEx = new INTF_ENTRY_EX();
      
      [DllImport("wzcsapi.dll")]
           public static extern UInt32 WZCSetInterfaceEx(
                                    string pSrvAddr,
                                    UInt32 dwInFlags,
                                    ref INTF_ENTRY_EX pIntfEx,
                                    ref UInt32 pdwOutFlags);
      [DllImport("wzcsapi.dll")]
      public static extern UInt32 WZCQueryInterfaceEx(
                                    string pSrvAddr,
                                    UInt32 dwInFlags,
                                    ref INTF_ENTRY_EX pIntfEx,
                                    ref UInt32 pdwOutFlags);
      
      int wifiOnOff(int isOn)
      {
          UInt32 dwError, dwOutFlags =0;
      
          g_IntfEx.wszGuid = "NETRTWLANU1";
      
          WZCQueryInterfaceEx(
                      null,
                      INTF_ALL,
                      ref g_IntfEx,
                      ref dwOutFlags);
      
          // wifi on
      	        if(isOn == 1)
      	        {
      		        g_IntfEx.dwCtlFlags |= INTFCTL_ENABLED;
      	        }
      	        // wifi off
      	        else
      	        {
      		        g_IntfEx.dwCtlFlags &= ~INTFCTL_ENABLED;
      	        }
      
      	        // Apply settings
      	        dwError = WZCSetInterfaceEx(
      		        null, 
      		        INTF_ALL_FLAGS | INTF_PREFLIST,
      		        ref g_IntfEx,
      		        ref dwOutFlags);
      
      	        if( dwError != ERROR_SUCCESS )
      	        {
      		        goto WIFI_ONOFF_FAIL;
      	        }
      
      	        return 1;
              WIFI_ONOFF_FAIL:
      
      	        return 0;
      }

      Comment

      • madankarmukta
        Contributor
        • Apr 2008
        • 308

        #4
        @ShadowLocke ,

        Can you please put the code here , the place where you are calling these functions - WZCQueryInterfa ceEx and WZCSetInterface Ex.

        Best Regards.

        Comment

        Working...