[Martenlist] external structure access problem
Jack Small
jack at andescotia.com
Fri Sep 29 16:29:58 EDT 2006
Adrian,
On Sep 29, 2006, at 9:08 AM, Adrian Wirz wrote:
> I have finally succeeded in integrating a dynamic library into a
> framework. After some tests it seems to run pretty well (finally).
> The main problem was linking the dynamic library with a non-
> standard name in Xcode 1.5 which seems to be rather reluctant to
> find such a library when linking.
Well, truly, congratulations! That's a huge accomplishment right there!
> Now there are a few problems regarding access to external
> structures. Here is one:
>
> The following declaration run through the C tool yields the
> subsequent result:
>
> typedef unsigned char st32[32];
> typedef struct IDRec {
> st32 StationName;
> st32 UserName;
> st32 UserPass;
> st32 TaskName;
> Boolean isapi;
> Boolean unused;
> } IDRec;
>
> After running through the C tool:
>
> VPL_ExtField _IDRec_6 = { "unused",129,1,kUnsignedType,"NULL",
> 0,0,"unsigned char",NULL};
> VPL_ExtField _IDRec_5 = { "isapi",128,1,kUnsignedType,"NULL",
> 0,0,"unsigned char",&_IDRec_6};
> VPL_ExtField _IDRec_4 = { "TaskName",96,32,kPointerType,"unsigned
> char",0,1,NULL,&_IDRec_5};
> VPL_ExtField _IDRec_3 = { "UserPass",64,32,kPointerType,"unsigned
> char",0,1,NULL,&_IDRec_4};
> VPL_ExtField _IDRec_2 = { "UserName",32,32,kPointerType,"unsigned
> char",0,1,NULL,&_IDRec_3};
> VPL_ExtField _IDRec_1 = { "StationName",0,32,kPointerType,"unsigned
> char",0,1,NULL,&_IDRec_2};
> VPL_ExtStructure _IDRec_S = {"IDRec",&_IDRec_1};
>
> I cannot access the string fields in IDRec from within Marten
> (build 056.00g006) with the following code:
>
> IDRec external object
> °
> | "MyMac String"
> | °
> | /
> ° °
> <StationName<
> °
> |
> °
> >StationName>
> ° °
>
> The code is executed alright but when I retrieve the fields again
> they contain nothing or garbage. So I asked myself whether the
> computed type (kPointerType) of the fields is correct? Or is the
> way I access the fields not correct?
Well, first of all, that's an excellent text representation. I'm not
sure why the mailing list is sending out plain-text only messages,
but it is very annoying.
Technically, the fields are character arrays, which is why they are
given pointer types. However, these are not pointers to strings
(which would have a size of 4) which is why Marten gets confused.
My first question is: Are these pascal strings (with a length byte
first) or are they c strings (with a terminating zero)? Typically,
char arrays of this type are pascal strings, but that depends on the
implementation.
I would solve this using a little known technique for external gets.
Instead of using an external set ( <StationName< ), I would use an
"address get" to get a pointer to the character array
( >&StationName> ) then use put-integer/text to poke in the correct
values.
Here is an example that will poke in a pascal string:
-------------- next part --------------
Oddly enough, you can just use a "regular" external-get to access the
array, but you will need to write a function to extract pascal
strings, as Marten only knows how to deal with c strings.
> I'd be very happy about some help here. Thanks.
I hope this helps! If not let me know and we will find some way!
You're really close!
More later,
Jack
More information about the Martenlist
mailing list