Hi Chris,
Thanks :-)
Firstly, it's defined as part of a parameters struct:
typedef struct
{
// -------- Input parameters
UInt32 NumberOfMoviesNeeded;
UInt32 NumberOfTracksPerMovieNeeded;
REALstring FileLocation;
// other stuff...
} SongLoaderData, *SongLoaderDataRef;
This struct is part of a class called SongLoader. Because I work on a
background thread on Mac, I actually store the SongLoaderData
extern REALclassDefinition RB_SongLoader; // forward declaration
struct RB_SongLoaderData
{
// To be thread-safe, RB only manages a pointer to the memory. Any
access to the memory itself will be done in a custom way by me!
// The memory for the parameters themselves is assigned in the class
constructor below
SongLoaderDataRef myParametersRef;
};
The data is assigned as follows:
static void RB_SongLoaderConstructor (REALobject instance)
{
ClassData (RB_SongLoader, instance, RB_SongLoaderData, me);
OSStatus osErr = noErr;
// allocate some thread-safe memory for the parameters
me->myParametersRef = SongLoaderDataRef(calloc(1,
sizeof(SongLoaderData)));
// Get a pointer to the parameters, so that we can modify their default
values
SongLoaderDataRef myParameters =
(SongLoaderDataRef)me->myParametersRef;
}
The parameters are then passed around by reference to various functions.
The particular code that is causing me a problem is:
const char *FileLocationCString =
inParameters->FileLocation->CString();
// this always returns a cstring with weird characters
CFStringRef FileLocationCFString =
CFStringCreateWithCString(kCFAllocatorDefault, FileLocationCString,
REALGetStringEncoding(inParameters->FileLocation));
// this works on Mac but not on Win (due to weird characters?) -
returns NULL every time
This is how I get and set the string:
static REALstring FileLocationGetter (REALobject instance, long param)
{
ClassData (RB_SongLoader, instance, RB_SongLoaderData, me);
SongLoaderDataRef myParameters = (SongLoaderDataRef)me->myParametersRef;
return myParameters->FileLocation;
}
static void FileLocationSetter (REALobject instance, long param, REALstring
value)
{
ClassData (RB_SongLoader, instance, RB_SongLoaderData, me);
SongLoaderDataRef myParameters = (SongLoaderDataRef)me->myParametersRef;
myParameters->FileLocation = value;
}
If you can get this working, I¹ll buy you a beer :-)
Dave.
> From: Chris Little <cslittle at mac dot com>
> Reply-To: REALbasic Plugins <realbasic-plugins at lists dot realsoftware dot
> com>
> Date: Fri, 27 Jan 2006 09:24:41 -0500
> To: REALbasic Plugins <realbasic-plugins at lists dot realsoftware dot com>
> Conversation: CFStrings on Win32
> Subject: Re: CFStrings on Win32
>
> on 1/27/06 8:48 AM, Dave Addey at listmail1 at dsl dot pipex dot com wrote:
>
>> Hi all,
>>
>> Thanks for all of the help with this. Unfortunately, I still can't get it
>> to work. All of this approach works for creating a CFString, but Cstring()
>> is still returning weird characters on Windows. It's specifically the
>> CString from the REALstring which is causing problems, rather than the
>> CFString creation. For some reason, the CString just isn't coming back out
>> correctly on Windows from within the plugin code. (It's fine when set and
>> retrieved in RB).
>>
>> I've spent ages pulling my hair out over this one, so I think I'm going to
>> try a different approach - perhaps using declares for this bit, and then
>> passing in CFObject references to the plugin instead.
>
> Can you repost your current code. I'll put it in a plug-in and try it here.
>
> Chris
_______________________________________________
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>
|