Problem with OpenNetCF Networking.GetAdapters

  • Thread starter Thread starter nzpcmad
  • Start date Start date
N

nzpcmad

This call can throw an "Index out of range" exception which has been
discussed in this group and the source for Adapter.cs has been updated
to solve this.

(I compile the classes myself rather than use the 1.2 dll).

On my device (Casio DTX10), this exception is still thrown if I do not
open up the connection beforehand i.e. no adapter. If I run it after
opening the connection, it works fine i.e. finds one adapter.

Perhaps it would be better in this case to throw a "No adapter present"
exception which would be a lot more meaningful and point you in the
right direction?

Thanks
 
There have been a couple of updates. If you can get the 'real' latest code
from us now, let me know if you still have that problem and I'll look at it,
if so. I seem to remember fixing the case of 0 adapters already, though.

Paul T.
 
I got the source code yesterday. (Under the "Source" tab).

Adapter.cs contains this line in FirstAdapter():

// Reset the indexing.
// fixed bug when only one device returned - thanks Sergey Bogdanov for
the bugfix
firstnextIndex = 0;
firstnextOffset = this.Next == 0 ? 0 : this.Next - ourBase;

(Note this is for one device not none?)

This fix sorted out my original problem which was the "Index out of
range" exception when I used the 1.2 dll.

Thanks
 
Do you have this method defined in this way?

-----
// Main constructor. This figures out how much space
// is needed to hold the list of adapters, allocates
// a byte array for that space, and gets the list
// from GetAdaptersInfo().
unsafe public IP_ADAPTER_INFO()
{
// Find out how much space we need to store the
// adapter list.
int size = 0;
int err = AdapterPInvokes.GetAdaptersInfo( null, ref size );
if ( err != 0 )
{
// This is what we'd expect: there is not enough room in the
// buffer, so the size is set and an error is returned.
if ( err == 111 )
{
// ToDo: Handle buffer-too-small.
}
}

// Check for size = 0 (no adapters, presumably).
ourSize = (uint)size;
if ( ourSize == 0 )
{
data = null;
}
else
{
data = new byte[ size ];

// We need to lock this in memory until we can
// get its address. Since GetAdaptersInfo will
// be storing Next pointers from adapter information
// to adapter information, we need to know what
// the base for those pointers is. We can then
// calculate the offset into the byte array of
// IP_ADAPTER_INFO from that.
// Fix the data array in memory. We need to do
// this to store the base address of the array.
// The GetAdaptersInfo call will put various Next
// pointers in the structure and we need to know
// what the base address against which those are
// measured is. With that, we can figure out what
// offset in the data array they reference.
fixed( byte *b = &data[ 0 ] )
{
// Save the base address.
ourBase = (uint)b;

// Actually call GetAdaptersInfo.
int siz = (int)ourSize;
err = AdapterPInvokes.GetAdaptersInfo( data, ref siz );
}

if ( err != 0 )
data = null;
}
}

-----

When there are no adapters known to the system, the size returned from
GetAdpatersInfo( NULL, &size ) should be zero, causing the collection to be
empty. Make sure that you have all of OpenNETCF.Net up-to-date...

Paul T.
 
Thanks Daniel,

I got out "Adapter.cs" and compiled it. However, there are obviously a
number of changes

e.g. I now get errors on "AuthenticationMode", "SelfMarshalledStruct"
etc.

So I obviously need to get the whole .NET subtree.

Is there any way of doing this other than clicking on each line
one-by-one and saving the files?

Thanks
 
I posted a ZIP containing the current .Net stuff, if you're reading the
group with a real newsreader...

Paul T.
 
Back
Top