May 21st 2007
Example Code from REAL World: List of available encodings
This is the example code from my REAL World presentation on declares. As I did last year, I asked for a declare someone in the audience was wanting to have written, and did it on the spot to show how to go from finding the docs to having working code. This year, someone needed to find a list of available encodings. This code only works on the Mac currently.
Function AvailableEncodings() As TextEncoding()
Dim out() As TextEncoding
#If TargetCarbon
Declare Function CFStringGetListOfAvailableEncodings Lib "CoreFoundation" As Ptr
Const kCFStringEncodingInvalidId = &hffffffff
Dim list As Ptr = CFStringGetListOfAvailableEncodings
Dim i As Integer
While list.Int32(i * 4) <> kCFStringEncodingInvalidId
out.Append Encodings.GetFromCode( list.Int32( i * 4 ) )
i = i + 1
Wend
#EndIf
Return out
End Function
Enjoy!