[Mono-osx] How to handle CFArrayRef?

Sebastian Mauer sebastian.mauer at rwth-aachen.de
Tue Apr 22 15:58:04 EDT 2008


Hi Erik,

I solved my problem, after getting a IntPtr for each Element within
The Array I could get another IntPtr pointing at the data via
CFDataGetBytePtr.
With this IntPtr, Marshal.PtrToStructure worked like a charm.

Thanks again,

Sebastian

-----Ursprüngliche Nachricht-----
Von: Erik Ylvisaker [mailto:eylvisaker at physics.ucdavis.edu] 
Gesendet: Dienstag, 22. April 2008 21:39
An: Sebastian Mauer
Cc: mono-osx at lists.ximian.com
Betreff: Re: AW: [Mono-osx] How to handle CFArrayRef?

Sebastian,

I think you would want to use CFDataGetBytes to copy the data to a 
region you allocate with Marshal.AllocHGlobal.  Then I think 
Marshal.PtrToStructure would be used.

~Erik

Sebastian Mauer wrote:
> Hello Erik,
>
> thanks for that hint. So I'm able to read an IntPtr for each entry within
> this
> CFArray. My Header File says "the arrays hold CFData objects which contain
> WirelessNetworkInfo structures",
> So I guess I have to implement some part of CFData as well. If I had a
> pointer to the CFData's contents could I use Marshal.PtrToStructure to
> finally get my WirelessNetworkInfo structs?
>
> Greetings,
> Sebastian
>
> -----Ursprüngliche Nachricht-----
> Von: Erik Ylvisaker [mailto:eylvisaker at physics.ucdavis.edu] 
> Gesendet: Dienstag, 22. April 2008 03:47
> An: Sebastian Mauer; mono-osx at lists.ximian.com
> Betreff: Re: [Mono-osx] How to handle CFArrayRef?
>
> You have to call other functions in Core Foundation to get values out of 
> the array.  If all you need is the functions CFArrayGetCount and 
> CFArrayGetValueAtIndex, you can use the sample code I've attached 
> below.  You might also want CFArrayGetValues.  Documentation for the 
> CFArray functions is here:
>
http://developer.apple.com/documentation/CoreFoundation/Reference/CFArrayRef
> /Reference/reference.html
>
>
>         const string appServices = 
>
"/System/Library/Frameworks/ApplicationServices.framework/Versions/Current/A
> pplicationServices"; 
>
>  
>         [DllImport(appServices)]
>         internal static extern int CFArrayGetCount(IntPtr theArray);
>  
>         [DllImport(appServices)]
>         internal static extern IntPtr CFArrayGetValueAtIndex(IntPtr 
> theArray, int idx);
>
>
> Sebastian Mauer wrote:
>   
>> Hello there,
>>
>> I'm currently implementing part of the Apple80211.framework, and made
good
>> progress until now.
>> The function WirelessScan will pass me a pointer to a CFArrayRef (part of
>> CoreFoundation) which contains several WirelessNetworkInfo structs and
I'm
>> not sure how to map/handle them within c#
>>
>> extern WIErr WirelessScan(
>> 	WirelessContextPtr inContext,
>> 	CFArrayRef *apList,
>> 	const UInt32 stripDups);
>>
>> This is the information I got from the respective header file:
>> *  It will allocate 2 CFArrays to store a list
>>  *  of managed and adhoc networks. The arrays hold CFData
>>  *  objects which contain WirelessNetworkInfo structures.
>>
>> What can I do to ultimately recieve an Array out of WirelessNetworkInfo
>> structs?
>>
>> Greetings,
>>
>> Sebastian Mauer
>>
>> _______________________________________________
>> Mono-osx mailing list
>> Mono-osx at lists.ximian.com
>> http://lists.ximian.com/mailman/listinfo/mono-osx
>>
>>   
>>     
>
>
>   



More information about the Mono-osx mailing list