"Maxim Fridental" <
[hidden email]> wrote in message
news:b4aae4$1to6q3$
[hidden email]...
> Hello,
>
> 1. The following doesn't work:
> (UnicodeString new: 5) trimNulls
> UnicodeString doesn't understand #asExternalAddress.
Thanks, recorded as issue #1187.
>
> 2. I can pass String, UnicodeString or BSTR as a parameter to a method
stub
> for the external interfacing that requires bstr. But I can't do this with
my
> subclass of String, UnicodeString or BSTR. The error message is "can't
> coerce <my subclass name> to bstr". It's appeared to be hard coded in the
> external interfacing engine, as I've tried not to subclass but to make a
> copy of BSTR with all its methods, and this doesn't work either.
>
In some cases, for reasons of efficiency and/or safety, the expected types
of some of the parameter types are indeed hard coded. However in the case of
string types such as #lpstr, all that is needed is that the class be marked
as "null terminated". This causes the VM to allocate an extra, hidden,
null-terminator character so that the Smalltalk object is implicitly of the
correct format to pass directly to an external API. To mark a byte class as
null terminated:
MyStringClass isNullTerminated: true
This need only be done once, as the flag is preserved in packages and when
the class is filed out.
In general if you find the VMs automatic marshalling to be inappropriate for
your needs, you can simply take more of the work on yourself by using a
looser parameter type. For example use 'lpvoid' instead of 'lpstr'. If you
want to pass a BSTR argument without using the 'bstr' parameter type, then
you can to first convert it to BSTR (or your own BSTR class) from a String
(or your own string class). The VM will automatically convert the string
types it knows about to BSTRs, but it can't do this for String types it
doesn't know about.
Regards
Blair