Here is a copy of an e-mail I sent to the betas list that may explain
what you need to do.
Charles Yeomans
------------------------
Recall that an OSType, or FourCharCode, is a UInt32. To make them a
little easier to remember, OSTypes are also specified as strings that
encode the UInt32 value in big-endian format.
REALbasic's OSType datatype always does the right thing. When you
pass 'moof' to a variable of OSType, it is treated as a big-endian
representation of a UInt32, in both PPC and x86 builds, and so
converted. Thus you don't need to reverse OSType strings.
When you are the recipient of a OSType in UInt32 format, to get the
string value you need to use a big-endian representation of the
number. For functions that return an OSType, the easiest way to do
it is to declare the return type as OSType and let Rb do it. For
example --
Soft Declare Function GetEventClass Lib CarbonLib (inEvent as
Integer) as OSType
dim eventClass as String = GetEventClass(theEventRef)
REALbasic now does auto-conversion between String and OSType, and it
correctly handles non-ASCII characters. So, for instance, the String
'mooƒ', perhaps encoded in UTF-8, is converted to an OSType 'mooƒ'
encoded in MacRoman. Conversion to OSType also truncates strings to
four characters.
When you set or get an OSType in a structure, you need to be a little
more careful. The best way appears to be to avoid the use of
StringValue in favor of UInt32Value, and do the conversion yourself.
I use the following functions for this.
Private Shared Function OSTypeToUInt(s as OSType) As UInt32
static m as new MemoryBlock(4)
m.LittleEndian = false
m.StringValue(0, 4) = s
return m.UInt32Value(0)
End Function
Private Shared Function UIntToOSType(theValue as Uint32) As OSType
Static m as new MemoryBlock(4)
m.LittleEndian = false
m.Long(0) = theValue
Return DefineEncoding(m.StringValue(0, 4), Encodings.MacRoman)
End Function
Reversing OSType codes to get things to work will drive you nuts;
it's better to remember that OSType strings are always big-endian,
and code accordingly.
--------------------------
On Nov 16, 2006, at 1:11 AM, Paul Levine wrote:
Thanks for the help.
Just on more stupid question. How do you properly convert a string
to an
integer, just get the asc value of each character, put them into a
memoryblock using byte and get the Integer value?
How would I convert "macs" to an integer?
I sent paul a response, looks like after he posted here. I'll
basically put the same information here as I sent him. I'll update
the website at some point to.
Yes, it is the OSTypes to blame. One of my other users a while back
sent me the trick via e-mail:
"To fix it and make it UB, just change all OSType's to integers, and
convert all OSType strings you're passing to integers as well, and it
works beautifully."
Here's why the release code has not been updated. I don't have an
intel mac yet. I'm not ready to release something into the wild and
call it universal, when I have no way to test it. So, being open
source, you guys may do with it what you like until I get an update
released.
--
Thom McGrath
The ZAZ Studios
<http://www.thezaz.com/> AIM: thezazstudios
On Nov 13, 2006, at 5:07 PM, Charles Yeomans wrote:
On Nov 13, 2006, at 3:30 PM, Joe Ranieri wrote:
The code probably needs to be updated to handle OSTypes correctly
in Intel builds.
Yep, that's exactly the problem. I debugged it for someone a while
back and the OSTypes were being done using a string in a
MemoryBlock so it wasn't respecting the endianness.
Is it not being supported by its developer?
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>