Click here to Skip to main content
15,896,111 members
Home / Discussions / C#
   

C#

 
AnswerRe: How to solve"Cross thread operation not valid" error when programming with C#.net Pin
shrinerainxp5-Apr-07 21:24
shrinerainxp5-Apr-07 21:24 
AnswerRe: How to solve"Cross thread operation not valid" error when programming with C#.net Pin
Luc Pattyn6-Apr-07 4:39
sitebuilderLuc Pattyn6-Apr-07 4:39 
QuestionError in saving excel file Pin
Manish_Home5-Apr-07 19:32
Manish_Home5-Apr-07 19:32 
AnswerRe: Error in saving excel file Pin
roel_v5-Apr-07 21:22
roel_v5-Apr-07 21:22 
QuestionDatatable Pin
AnhTin5-Apr-07 18:46
AnhTin5-Apr-07 18:46 
AnswerRe: Datatable Pin
_mubashir5-Apr-07 20:53
_mubashir5-Apr-07 20:53 
AnswerRe: Datatable Pin
Harini N K6-Apr-07 0:32
Harini N K6-Apr-07 0:32 
QuestionHelp!!! Declare a varied-length array of structures and the use of marshalling? Pin
peary5-Apr-07 18:21
peary5-Apr-07 18:21 
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 "AccessViolationException".

The full message is "Service cannot be started. System.AccessViolationException:
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.copy(), Marshal.PtrToStructure()....) 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 "AccessViolationException" 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 WlanGetAvailableNetworkList(
HANDLE hClientHandle,
const GUID* pInterfaceGuid,
DWORD dwFlags,
PVOID pReserved,
PWLAN_AVAILABLE_NETWORK_LIST* ppAvailableNetworkList
);

'-----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_AVAILABLE_NETWORK_LIST;

typedef struct _WLAN_AVAILABLE_NETWORK {
WCHAR strProfileName[256];
DOT11_SSID dot11Ssid;
DOT11_BSS_TYPE dot11BssType;
ULONG uNumberOfBssids;
BOOL bNetworkConnectable;
WLAN_REASON_CODE wlanNotConnectableReason;
ULONG uNumberOfPhyTypes;
DOT11_PHY_TYPE dot11PhyTypes[8];
BOOL bMorePhyTypes;
WLAN_SIGNAL_QUALITY wlanSignalQuality;
BOOL bSecurityEnabled;
DOT11_AUTH_ALGORITHM dot11DefaultAuthAlgorithm;
DOT11_CIPHER_ALGORITHM dot11DefaultCipherAlgorithm;
DWORD dwFlags;
DWORD dwReserved;
} WLAN_AVAILABLE_NETWORK, *PWLAN_AVAILABLE_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_TYPE;

typedef DWORD WLAN_REASON_CODE, *PWLAN_REASON_CODE;

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_TYPE;

typedef enum _DOT11_AUTH_ALGORITHM
{
DOT11_AUTH_ALGO_80211_OPEN,
DOT11_AUTH_ALGO_80211_SHARED_KEY,
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_ALGORITHM, *PDOT11_AUTH_ALGORITHM;

typedef enum _DOT11_CIPHER_ALGORITHM
{
DOT11_CIPHER_ALGO_NONE,
DOT11_CIPHER_ALGO_WEP40,
DOT11_CIPHER_ALGO_TKIP,
DOT11_CIPHER_ALGO_CCMP,
DOT11_CIPHER_ALGO_WEP104,
DOT11_CIPHER_ALGO_WPA_USE_GROUP,
DOT11_CIPHER_ALGO_RSN_USE_GROUP,
DOT11_CIPHER_ALGO_WEP,
DOT11_CIPHER_ALGO_IHV_START,
DOT11_CIPHER_ALGO_IHV_END
}DOT11_CIPHER_ALGORITHM, *PDOT11_CIPHER_ALGORITHM;


AnswerRe: Help!!! Declare a varied-length array of structures and the use of marshalling? Pin
Luc Pattyn6-Apr-07 4:50
sitebuilderLuc Pattyn6-Apr-07 4:50 
QuestionC# Pin
rednexhex5-Apr-07 16:59
rednexhex5-Apr-07 16:59 
AnswerRe: C# Pin
Sathesh Sakthivel5-Apr-07 17:12
Sathesh Sakthivel5-Apr-07 17:12 
AnswerRe: C# Pin
Rudolf Jan6-Apr-07 0:30
Rudolf Jan6-Apr-07 0:30 
QuestionCall an Executable from C# with Administrative rights Pin
ke3p_up5-Apr-07 16:40
ke3p_up5-Apr-07 16:40 
AnswerRe: Call an Executable from C# with Administrative rights Pin
shrinerainxp5-Apr-07 21:26
shrinerainxp5-Apr-07 21:26 
GeneralRe: Call an Executable from C# with Administrative rights Pin
ke3p_up5-Apr-07 22:41
ke3p_up5-Apr-07 22:41 
Questionsockets question Pin
dino20945-Apr-07 15:45
dino20945-Apr-07 15:45 
QuestionGeneric collection classes with Hashtable Pin
sreecahitu5-Apr-07 13:38
sreecahitu5-Apr-07 13:38 
AnswerRe: Generic collection classes with Hashtable Pin
roel_v5-Apr-07 21:04
roel_v5-Apr-07 21:04 
AnswerRe: Generic collection classes with Hashtable Pin
roel_v5-Apr-07 21:07
roel_v5-Apr-07 21:07 
QuestionHow to empty a Text file? Pin
Khoramdin5-Apr-07 12:50
Khoramdin5-Apr-07 12:50 
AnswerRe: How to empty a Text file? Pin
Luc Pattyn5-Apr-07 12:57
sitebuilderLuc Pattyn5-Apr-07 12:57 
AnswerRe: How to empty a Text file? Pin
Rudolf Jan6-Apr-07 0:32
Rudolf Jan6-Apr-07 0:32 
Questionopen OR run File Pin
TAREQ F ABUZUHRI5-Apr-07 12:28
TAREQ F ABUZUHRI5-Apr-07 12:28 
AnswerRe: open OR run File Pin
Luc Pattyn5-Apr-07 12:37
sitebuilderLuc Pattyn5-Apr-07 12:37 
QuestionHex String Pin
AAKAra5-Apr-07 11:37
AAKAra5-Apr-07 11:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.