DLL Call causes Exception on PPC 2002

Posted on 2003-10-30
Last Modified: 2013-12-27
I'm trying to call an API in VB. This is how the API is defined


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.
Question by:kmargaba
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Expert Comment

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

LVL 23

Accepted Solution

chensu earned 500 total points
ID: 9654801
The exception 0x800000002 is the data type misalignment exception. There is probably a bug in the DLL.

Author Comment

ID: 9655188
I'm using VB.NET 2003
Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

LVL 48

Expert Comment

ID: 9657491
Can you add the Dll as a reference.  It may not be a valid Dll..

Author Comment

ID: 9657867
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    
#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

// 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 isSupplicantRunning();
UINT StopSupplicant();
UINT StartSupplicant();


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.
      NdisPhysicalMediumDSL,            // includes ADSL and UADSL (G.Lite)
      NdisPhysicalMediumMax            // Not a real physical type, defined as an upper-bound

LVL 23

Expert Comment

ID: 9658281
You'd better ask the vendor to debug it.

Author Comment

ID: 9681308
The vendor did provide me a solution. It needed a different data type in VB. The String had to be converted to unicode using


Thanks to everyone who responded

Featured Post

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Progress means simplifying, not complicating. Bruno Munari Preface How to detect the name of the internal storage or an SD-card on Windows Mobile device from the desktop application? I got this question, when I was working on a PC applicati…
You should read OS supplied guidelines before developing. I can't stress that enough. The guidelines will help you understand the reasons mobile app developers do what they do.  Apple is very particular when they review appstore submissions.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Suggested Courses

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question