473,770 Members | 2,129 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Declare a varied-length array of structures and use marshalling

1 New Member
Hi, everyone,

I'm writing a program to discover wireless network
using Windows Native Wifi API & VB.net.
I have to declare the windows API in my VB.net program.
The original windows declaration is as below.

The problem is in "struct _WLAN_AVAILABLE _NETWORK_LIST",
it declared "WLAN_AVAILABLE _NETWORK Network[1];".
I think which means a Network[] array of struct WLAN_AVAILABLE_ NETWORK.
But how about the size of the Network[] array?
Is it "1" or more? what does "1" mean?
If I give it the size of 1, then I can get the first network back,
but if I give it more than 1, for example, 10,
then I got an error of "AccessViolatio nException".

The full message is "Service cannot be started. System.AccessVi olationExceptio n:
Attempted to read or write protected memory.
This is often an indication that other memory is corrupt."

Actually, the size of the Network[] array is decided by
dwNumberOfItems at run time, which means the size of the
Network[] array is varied-length not fixed, and in most situations
, the size should be more than 1.

I've searched the solution on the internet, and found some similar situations.
They said we should use IntPtr to get the address of the structure array and
then use Marshal class(Marshal.c opy(), Marshal.PtrToSt ructure()....) to get the array,
instead of declared it as a structure array, but they didn't post a sample Marshalling code.

I've tried to code, but still got "AccessViolatio nException" at Marshalling.
Anyone knows how to solve the problem?
Could you write a sample code for me in VB.net or C# without unsafe code?

Thanks so much. I appreciate your help.

Windows Native Wifi declarations:
'-----function-----
DWORD WINAPI WlanGetAvailabl eNetworkList(
HANDLE hClientHandle,
const GUID* pInterfaceGuid,
DWORD dwFlags,
PVOID pReserved,
PWLAN_AVAILABLE _NETWORK_LIST* ppAvailableNetw orkList
);

'-----structure-----
typedef struct _WLAN_AVAILABLE _NETWORK_LIST {
DWORD dwNumberOfItems ; '===>the actual size of array
DWORD dwIndex;
WLAN_AVAILABLE_ NETWORK Network[1]; '===>how to declare the array? should I give it fixed size of 1 or change it to an IntPtr
} WLAN_AVAILABLE_ NETWORK_LIST, *PWLAN_AVAILABL E_NETWORK_LIST;

typedef struct _WLAN_AVAILABLE _NETWORK {
WCHAR strProfileName[256];
DOT11_SSID dot11Ssid;
DOT11_BSS_TYPE dot11BssType;
ULONG uNumberOfBssids ;
BOOL bNetworkConnect able;
WLAN_REASON_COD E wlanNotConnecta bleReason;
ULONG uNumberOfPhyTyp es;
DOT11_PHY_TYPE dot11PhyTypes[8];
BOOL bMorePhyTypes;
WLAN_SIGNAL_QUA LITY wlanSignalQuali ty;
BOOL bSecurityEnable d;
DOT11_AUTH_ALGO RITHM dot11DefaultAut hAlgorithm;
DOT11_CIPHER_AL GORITHM dot11DefaultCip herAlgorithm;
DWORD dwFlags;
DWORD dwReserved;
} WLAN_AVAILABLE_ NETWORK, *PWLAN_AVAILABL E_NETWORK;

typedef struct _DOT11_SSID {
ULONG uSSIDLength;
UCHAR ucSSID[32];
} DOT11_SSID, *PDOT11_SSID;


'-----Enumeration-----
typedef enum _DOT11_BSS_TYPE
{
dot11_BSS_type_ infrastructure,
dot11_BSS_type_ independent,
dot11_BSS_type_ any
}DOT11_BSS_TYPE , *PDOT11_BSS_TYP E;

typedef DWORD WLAN_REASON_COD E, *PWLAN_REASON_C ODE;

typedef enum _DOT11_PHY_TYPE
{
dot11_phy_type_ unknown,
dot11_phy_type_ any,
dot11_phy_type_ fhss,
dot11_phy_type_ dsss,
dot11_phy_type_ irbaseband,
dot11_phy_type_ ofdm,
dot11_phy_type_ hrdsss,
dot11_phy_type_ erp,
dot11_phy_type_ IHV_start,
dot11_phy_type_ IHV_end
}DOT11_PHY_TYPE , *PDOT11_PHY_TYP E;

typedef enum _DOT11_AUTH_ALG ORITHM
{
DOT11_AUTH_ALGO _80211_OPEN,
DOT11_AUTH_ALGO _80211_SHARED_K EY,
DOT11_AUTH_ALGO _WPA,
DOT11_AUTH_ALGO _WPA_PSK,
DOT11_AUTH_ALGO _WPA_NONE,
DOT11_AUTH_ALGO _RSNA,
DOT11_AUTH_ALGO _RSNA_PSK,
DOT11_AUTH_ALGO _IHV_START,
DOT11_AUTH_ALGO _IHV_END
}DOT11_AUTH_ALG ORITHM, *PDOT11_AUTH_AL GORITHM;

typedef enum _DOT11_CIPHER_A LGORITHM
{
DOT11_CIPHER_AL GO_NONE,
DOT11_CIPHER_AL GO_WEP40,
DOT11_CIPHER_AL GO_TKIP,
DOT11_CIPHER_AL GO_CCMP,
DOT11_CIPHER_AL GO_WEP104,
DOT11_CIPHER_AL GO_WPA_USE_GROU P,
DOT11_CIPHER_AL GO_RSN_USE_GROU P,
DOT11_CIPHER_AL GO_WEP,
DOT11_CIPHER_AL GO_IHV_START,
DOT11_CIPHER_AL GO_IHV_END
}DOT11_CIPHER_A LGORITHM, *PDOT11_CIPHER_ ALGORITHM;
Apr 6 '07 #1
1 2133
Motoma
3,237 Recognized Expert Specialist
You will probably need to know how many networks are available. If you go beyond that number, I'm sure you will get an exception thrown.
I don't know how you would go about getting this, but you may want to check google for something like "wifi network enumeration api" or something like that.
Apr 6 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
1359
by: Laurence Nixon | last post by:
Hello all. I am seeking ideas on how to determin a specific value with varied parameters. This will be for students who have taken modules in a course for pre-certification. So it will be like this: StudentA ModuleA + ModuleC + ModuleD + ModuleE = (Completetion of this COURSE1)
0
1346
by: Magnabyte | last post by:
Hello all. I am seeking ideas on how to determin a specific value with varied parameters. This will be for students who have taken modules in a course for pre-certification. So it will be like this: StudentA ModuleA + ModuleC + ModuleD + ModuleE = (Completetion of this COURSE1)
2
22311
by: Derrick | last post by:
How does one declare an event within an interface, so that every class which implements that interface must implement that event? I think I just need to specifiy the actual event as I would a function, but what about the delegate? Up to now, all my interfaces have only dealt with properties and functions. Here's basically what I want to do (for example): public interface IFoo
5
15801
by: Jiggaz | last post by:
Hi, Look my stored procedure : __________________ ALTER PROCEDURE dbo.CreateAccount @Nickname varchar(30), @Password varchar(15), @Email varchar(50), @Date datetime,
10
2158
by: Bob Hollness | last post by:
Hi all. I have a Sub that calls another sub. Both subs use a common object, so I used Public to declare it at the top of the module, as below. Public Writer As StreamWriter = File.CreateText(Application.StartupPath & "\Update.txt") The first time my Sub runs it works fine. But the second time it fails telling me "Cannot write to a closed TextWriter. I am guessing that this is
6
2134
by: **Developer** | last post by:
Notice below I sometimes used the "A" version. I found by cut-and-try that only the "A" version would work correctly. Anyone have a suggestion of why the "W" version would not work correctly? One reason is that the ByRef or ByVal does not show by InteliSence so the "p" would help there. ------ Secondly, I'd like to be consistent with the parameter names. I'd like to
2
13459
by: juan.gautier | last post by:
Hi, I try to construct a SQL code for a view to select a specific data from a table, this query take the value of the filter from a text box in a visual basic 6.0 form. my problem is when i DECLARE the variable @AMP receive a error message that said "The Declare cursor SQL construct or statement is not supported." What i do wrong? Please help me. i attach the code. DECLARE @AMP int;
1
2786
by: ares.lagae | last post by:
- I have a typelist and I want to declare a member variable for each of the types. How can I do that? E.g. I have the typelist "typedef boost::mpl::vector<int, float> types;" and I want to declare member variables with type "int" and "float". - I have a typelist and I want to declare a variable based on each of the types types. How can I do that? E.g. I have the typelist "typedef boost::mpl::vector<int, float> types;" and I want to...
1
3782
by: okonita | last post by:
Hi all, My environment is DB2 UDBv8.2 on Windows and Linux. I am getting a lot of errors on the script you see below. Some of the error I am geting are: -----------------------------------Start of Script----------------------------------- ---------------------original creation by Norm Wong------------------------ CREATE PROCEDURE DB2ADMIN.REORGTS( ) DYNAMIC RESULT SETS 1
12
9054
by: forrestgump | last post by:
I am currently trying to create VBA to send a specified excel sheet to varied email sources. I currently have the code below which sends the attachment in an email to a specified source e.g. mrqwe@hotmails.com, however I want to change this so the address is chosen from a specified cell on a worksheet. I have tried to reference a cell e.g. .sendmail Sheets("sheet3").range("A1"),_ but this does not work. Any ideas anyone? Sub...
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10101
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9906
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8933
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7456
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6712
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3609
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.