Link to home
Start Free TrialLog in
Avatar of kmargaba
kmargaba

asked on

DLL Call causes Exception on PPC 2002

I'm trying to call an API in VB. This is how the API is defined

UNIT AddWep(ULONG 1, BOOL 2, TCHAR *3);

Here's how I declared it in VB
  <DllImport("80211API.DLL", CallingConvention:=CallingConvention.Winapi, CharSet:=CharSet.Unicode)> _
    Public Function AddWep(ByVal KeyNew As UInt32, ByVal DefltKey As Boolean, ByVal Key As Char()) As Integer

    End Function

Here's how I'm calling it in VB

 Dim iRet As Integer
        Dim WepStat As Long
        Dim SSId As String
        Dim WepKeyNum As Integer
        Dim OldKy As String
        Dim NewKy As String
        Dim iNMode As Integer
        Dim iChannel As Integer

        NewKy = "0xf80211be0804dcb2485a13579f"

        WepKeyNum = 1
        'NewKy = "29966ba6d64febf42ca2a91603102140bbeaef9f5fd45fde4c0ffc0c93"
        NewKy = "0xf80211be0804dcb2485a13579f"

        iRet = RadioConnect()

        iRet = AddWep(Convert.ToUInt32(WepKeyNum), Convert.ToBoolean(0), NewKy.ToCharArray())
        MsgBox("Add WEP returned " & iRet.ToString)

This is throwing a Native Exception
Exception Code: 0x800000002
Exception ADdress: 0x008dbd2c

Any idea what I'm doing wrong?. I have tried many different things but nothing works.

Thanks again in advance for the help.
Avatar of cindy_k
cindy_k
Flag of United States of America image

Just to be clear, are you using VB.NET or VBCE 3.0 ?

Thanks!
Cynthia.
ASKER CERTIFIED SOLUTION
Avatar of chensu
chensu
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kmargaba
kmargaba

ASKER

I'm using VB.NET 2003
Avatar of Mikal613
Can you add the Dll as a reference.  It may not be a valid Dll..
It is a DLL Provided by a vendor.  It was written by someone inhouse (by the vendor). Most of the other functions that I have used, works. This is the only function that doesn't. I don't have the source code for the DLL, but I have the header file which is listed below.

//  API_Calls.h Header file for 802.11 API's
//      This file is used for both Win32 and WinCE version(s) of the 802.11 API
//  
///////////////////////////////////////////////////////////////////////////////

#ifndef _API_CALLS_
#define _API_CALLS_

///////////////////////////////////////////////////////////////////////////////
// Basic Sizes and Defines and Errors
///////////////////////////////////////////////////////////////////////////////
#define MAC_ADDR_LEN      6
#define SSID_LEN            32

#define ERR_ON_CREATE_FILE 0xC0000001      
#define ERR_ON_OPEN_DEVICE 0xC0000002
#define ERR_CONNECT_FAILED 0xC0000003
#define ERR_QUERY_FAILED 0xC0000004

///////////////////////////////////////////////////////////////////////////////
// Additional Response Defines
///////////////////////////////////////////////////////////////////////////////

// Network Physical Medium Types - Returned from GetPhysicalMedium or GetMediaSupported
#define NDIS_PHYSICAL_MEDIUM_WLAN                  0      // NdisPhysicalMediumWirelessLan - MSDN: Packets are transferred over a wireless LAN network.
#define NDIS_PHYSICAL_MEDIUM_CABLE_MODEM      1      // NdisPhysicalMediumCableModem - MSDN: Packets are transferred over a DOCSIS-based cable network.
#define NDIS_PHYSICAL_MEDIUM_PHONE_LINE            2      // NdisPhysicalMediumPhoneLine - MSDN: Packets are transferred over standard phone lines.
#define NDIS_PHYSICAL_MEDIUM_POWER_LINE            3      // NdisPhysicalMediumPowerLine - MSDN: Packets are transferred over wiring that is connected to a power distribution system.  
#define NDIS_PHYSICAL_MEDIUM_DSL                  4      // NdisPhysicalMediumDSL - MSDN: Packets are transferred over a Digital Subscriber Line (DSL) network.
#define NDIS_PHYSICAL_MEDIUM_802_3                  5   // NdisMedium802_3 - MDSN: Ethernet (802.3)
#define NDIS_PHYSICAL_MEDIUM_802_5                  6   // NdisMedium802_5 - MDSN: Token Ring (802.5)
#define NDIS_PHYSICAL_MEDIUM_WAN                  7   // NdisMediumWan - MDSN: WAN (Wide Area Network)
#define NDIS_PHYSICAL_MEDIUM_WWAN                  8   // NdisMediumWirelessWan - MDSN: Various types of NdisWirelessXXX media
#define NDIS_PHYSICAL_MEDIUM_IRDA                  9   // NdisMediumIrda - MDSN: Infrared (IrDA)  
#define NDIS_PHYSICAL_MEDIUM_UNKNOWN         10      // Unknown Medium Type for this API    
   
// Network Types - NO NOT CONFUSE WITH INFRASTRUCTURE TYPE
#define NDIS_NET_TYPE_FH                              0      // Ndis802_11FH,
#define NDIS_NET_TYPE_DS                              1      // Ndis802_11DS,
#define NDIS_NET_TYPE_UNDEFINED                        2      // Ndis802_11NetworkTypeMax    // not a real type, defined as an upper bound    
 
// TX Power level
#define NDIS_POWER_LEVEL_63                  0      // 63 mW
#define NDIS_POWER_LEVEL_30                  1      // 30 mW
#define NDIS_POWER_LEVEL_15                  2      // 15 mW
#define NDIS_POWER_LEVEL_5                  3      // 5 mW
#define NDIS_POWER_LEVEL_1                  4      // 1 mW
#define NDIS_POWER_LEVEL_UNKNOWN      5      // Unknown!

// TX Rates
//#define _1_MEGABIT      10
//#define _2_MEGABIT      20
//#define _5_5_MEGABIT    55
//#define _11_MEGABIT     110
#define _1_MEGABIT              1
#define _2_MEGABIT              2
#define _AUTO_1_2            3
#define _5_5_MEGABIT        4
#define _11_MEGABIT              5
#define _FULLY_AUTO              6

// antenna modes
#define ANT_PRIMARY            1
#define ANT_SECONDARY      2
#define ANT_DIVERSITY      0

// Network type
#define NDIS_NET_MODE_IBSS                  0      // Ad-Hoc (802.11)
#define NDIS_NET_MODE_ESS                  1      // Infrastructure
#define NDIS_NET_AUTO_UNKNOWN            2      // Auto
#define NDIS_NET_MODE_UNKNOWN            3      // Anything Else/Unknown Error

// association
#define NDIS_RADIO_ASSOCIATED            0      // the radio is associated with a network
#define NDIS_RADIO_SCANNING                  1      // the radio is looking for a network to associate with

// Wep Status
#define NDIS_RADIO_WEP_ENABLED             0      // Wep is currently enabled
#define NDIS_RADIO_WEP_DISABLED             1      // Wep is currently disabled
#define NDIS_RADIO_WEP_NOT_SUPPORTED 2      // wep is not supported
#define NDIS_RADIO_WEP_ABSENT             3      // wep key is absent

// Authentication Mode
#define NDIS_RADIO_AUTH_MODE_OPEN            0
#define NDIS_RADIO_AUTH_MODE_SHARED            1
#define NDIS_RADIO_AUTH_MODE_AUTO            2
#define NDIS_RADIO_AUTH_MODE_ERROR            3

// power mode
#define NDIS_RADIO_POWER_MODE_CAM            0      // Continious Access Mode (eg, Always On)
#define NDIS_RADIO_POWER_MODE_PSP            1      // Power Saving Mode
#define NDIS_RADIO_POWER_UNKNOWN            2      // We don't know what mode it is.

// statistics
typedef struct WLAN_802_11_NDIS_STATISTICS
{
      __int64 TransmittedFragmentCount;                  // number of data and management fragments that have been transmitted
      __int64 MulticastTransmittedFrameCount;      // number of frames that the NIC has transmitted by multicast or broadcase
      __int64 FailedCount;                                    // number of frames that failed
      __int64 RetryCount;                                    // number of frames that the NIC retransmitted after one or more retransmission attempts
      __int64 MultipleRetryCount;                        // number of frames successfully retransmitted after a retry
      __int64 RTSSuccessCount;                              // Number of times the NIC received a CTS in response to an RTS                              
      __int64 RTSFailureCount;                              // Number of times that the NIC did not receive a CTS in response to an RTS
      __int64 ACKFailureCount;                              // Number of times the NIC expected an ACK that was not received
      __int64 FrameDuplicateCount;                        // Number of duplicate frames received
      __int64 ReceivedFragmentCount;                  // Number of data and management frames received
      __int64 MulticastReceivedFrameCount;            // Number of frames received to multicast or broadcast
      __int64 FCSErrorCount;                              // Number of frames that contained FCS errors
} WLAN_802_11_NDIS_STATISTICS, *PWLAN_802_11_NDIS_STATISTICS;

///////////////////////////////////////////////////////////////////////////////
// This API is your new best friend.  It is
// compatible with the Mono 700 and Color 700.
//
// An extension of the original Orinoco API, this API
// tries to make the original functions behave as
// in the original API.  It also adds a handful of new
// features.
//
// Functions are denoted as needing connection to
// the radio, or not needing connection to the radio.
//
// In the event that you call a function that needs
// a connection to the radio, it will go ahead and
// make that connection for you, and then clean it
// up again as soon as it is done with it.
//
// However, if you plan on using the functions that
// require a connection a lot, please use RadioConnect()
// when your application starts, and RadioDisconnect()
// when your application exits.  This will keep your
// application preformance as high as possible.
///////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////
// New Exports Available in this release
///////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////
// RadioConnect() - connect to the available radio
// Use this function if you plan on using
// a lot of API calls that talk directly
// to the radio.
/////////////////////////////////////////////////
UINT RadioConnect();            
/////////////////////////////////////////////////
// RadioDisconnect() - Clean up connection from
//   Connect function.
//
// Call when your application exits.
/////////////////////////////////////////////////
UINT RadioDisconnect();

UINT GetMac(TCHAR *);                        // get the radio's mac address - Requires Connecction
UINT GetBSSID(TCHAR *);                        // get the current associated AP's mac address
UINT GetSSID(TCHAR *);                        // get radio's SSID - Requires Connection

UINT GetDiversity(USHORT *);
UINT SetDiversity(USHORT);
UINT SetTXRate(UCHAR);
UINT isSupplicantRunning();
UINT StopSupplicant();
UINT StartSupplicant();

//!---
UINT SetSSID(TCHAR *);

UINT GetLinkSpeed(int &);                  // get current link speed
UINT GetMedia(ULONG &);                        // get media
UINT GetMedium(ULONG &);                  // get medium
UINT GetNetworkType(ULONG &);            // get NetworkType In Use (DS/FH) - Use GetNetworkMode for ESS/IBSS/PIBSS
UINT GetTXPower(ULONG &);                  // get the TX Power (in mW)

UINT GetNetworkMode(ULONG &);            // get the network mode: IBSS, ESS
UINT SetNetworkMode(ULONG);                  // set the network mode: IBSS, ESS

//!---
UINT AddWep(ULONG, BOOL, TCHAR *);            // set a wep key

UINT GetRSSI(ULONG &);                        // get the radio RSSI
UINT GetAssociationStatus(ULONG &);      // is the radio associated?  See defines above
UINT GetNicStats(WLAN_802_11_NDIS_STATISTICS &);      // Get radio stastics - Not a required function!
UINT GetWepStatus(ULONG &);                  // is wep enabled?

UINT GetAuthenticationMode(ULONG &);// get the authentication mode
UINT SetAuthenticationMode(ULONG);
UINT SetChannel(USHORT);                        // set the desired channel for Ad-Hoc Mode

UINT EnableWep(BOOL);

UINT GetPowerMode(ULONG &);                  // Get the current power mode
UINT SetPowerMode(ULONG mode);            // set the current power mode

UINT isOrinoco();                              // returns TRUE if we are attached to the orinoco radio, otherwise returns FALSE

//!---
//UINT EncryptWepKeyForRegistry(CString * szDest, CString * szSource);      // encrypts a wep key for registry storage
UINT EncryptWepKeyForRegistry(TCHAR * szDest, TCHAR * szSource);

UINT SetRTSThreshold(USHORT &);            // set the RTS Threshold of the radio
UINT GetRTSThreshold(USHORT &);            // get the RTS Threshold of the radio

//!---
UINT ConfigureProfile(TCHAR *);            // pass in a CString with the name of the profile you want to setup, and this function will do it.

UINT StartScanList();                        // this will start the scan list functionality of the system

///////////////////////////////////////////////////////////////////////////////
// Things that will probably not exist in this file in the future.
///////////////////////////////////////////////////////////////////////////////
//
//      Optional OIDs
//
#define OID_GEN_PHYSICAL_MEDIUM                        0x00010202

//
// Physical Medium Type definitions. Used with OID_GEN_PHYSICAL_MEDIUM.
//
typedef enum _NDIS_PHYSICAL_MEDIUM
{
      NdisPhysicalMediumReserved0,
      NdisPhysicalMediumWirelessLan,
      NdisPhysicalMediumCableModem,
      NdisPhysicalMediumPhoneLine,
      NdisPhysicalMediumPowerLine,
      NdisPhysicalMediumDSL,            // includes ADSL and UADSL (G.Lite)
      NdisPhysicalMediumMax            // Not a real physical type, defined as an upper-bound
} NDIS_PHYSICAL_MEDIUM, *PNDIS_PHYSICAL_MEDIUM;

#endif
You'd better ask the vendor to debug it.
The vendor did provide me a solution. It needed a different data type in VB. The String had to be converted to unicode using

System.Text.Encoding.Unicode.GetBytes(strWep)

Thanks to everyone who responded