PointerField question?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

PointerField question?

kruger
Suppose I have a C struct like

typedef struct tagMY_STRUCT
{
 WORD wordField;
 LPSTR stringField;
} MY_STRUCT;"

The defineFields method for MY_STRUCT class looks like

defineFields

   self defineField: #wordField type: WORDField new;
        defineField: #stringField type: (PointerField type: String)

How Can I read/write the LPSTR field from this structure?


Thanks


Reply | Threaded
Open this post in threaded view
|

Re: PointerField question?

Blair McGlashan
<[hidden email]> wrote in message
news:[hidden email]...

> Suppose I have a C struct like
>
> typedef struct tagMY_STRUCT
> {
>  WORD wordField;
>  LPSTR stringField;
> } MY_STRUCT;"
>
> The defineFields method for MY_STRUCT class looks like
>
> defineFields
>
>    self defineField: #wordField type: WORDField new;
>         defineField: #stringField type: (PointerField type: String)
>
> How Can I read/write the LPSTR field from this structure?

Having generated the accessor methods (MY_STRUCT compileDefinition) it is
simply a matter of sending #stringField to read the value, and #stringField:
to write it. In the latter case you can pass a Smalltalk String, but you
must make sure it is not garbage collected while the structure is referring
to it. The easiest way to achieve this is to add an instance variable and
additional setter method which both stores the string into the instance
variable and calls #stringField: to store its address in the structure.

There are a number of examples of this in the image, e.g. LVCOLUMN (the
pszText field).

Regards

Blair