Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

HowTo return an OLE String in an Automation Server Interface

23 views
Skip to first unread message

usenet

unread,
May 29, 2003, 11:38:12 AM5/29/03
to
in C++ Builder, i use this simple code:

void __fastcall TMainForm::MyServerMyEvent(TObject *Sender, BSTR *Name)
{
// BSTR = OLE String, or Wide String)
WideString retval("Return this String"); // WideString is a wrapper
for BSTR*

*Name = retval.Copy();
}

how is this done in VO?

METHOD MyEvent( pName ) CLASS MainForm

//???

Willie Moore

unread,
May 29, 2003, 11:35:06 PM5/29/03
to
Usenet,

if you are just trying to return a string, return a string

method myEvent(cInString) class MainForm
local cRet as string
if !isString(cInstring)
cInstring ;= ""
endif
cRet := "the string you passed in was : " + cInstring
return cRet

To call this from VBScript you would do something like this (assuming that
the OLE class is myOLE.Server)
dim oserver
oServer = Server.CreateObject("myOLEServer")
Response.write oServer.MyEvent("Got Ya")

you will notice that my code is a little longer, but I have added some error
checking for the string. That will keep IIS from crashing if you pass in an
int, or NIL

Regards,

Willie


"usenet" <vo...@null.com> wrote in message news:3ED62964...@null.com...

usenet

unread,
May 30, 2003, 9:23:36 AM5/30/03
to
Willie Moore wrote:

>Usenet,
>
>if you are just trying to return a string, return a string
>

[...]

i'm trying to return a WideString (or OLE-String, or BSTR)

the *.tlb declares the parameter as BSTR* [in out]

in C++, the resulting (autogenerated) prototype includes still the BSTR
*Name:

>>void __fastcall TMainForm::MyServerMyEvent(TObject *Sender, BSTR *Name)
>>

I have to return a WideString, so i create one object 'retval' of the
calss 'WideString'

>> WideString retval("Return this String"); // WideString is a wrapper
>>
>>

*Name => gets the value-of-Name => BSTR
and copy(!) its contents to the BSTR (which in fact is a "pointer to a
null-terminated wide-string")

>> *Name = retval.Copy();
>>
>>
now, after this 'off-topics', the simple question:

>>how is this done in VO?
>>

Assuming the COMSDK serves me correctly the BSTR* into the variable
pName, how do i...

-read this BSTR* into a native VO String.
-write a (Wide)String into this BSTR*

Ronny Michiels

unread,
May 30, 2003, 8:50:47 AM5/30/03
to
W2String(), String2W() ?

-----------------
LOCAL pszTemp AS PSZ
LOCAL cTemp AS STRING

// Put some text in a psz, in fact a pointer to a null-terminated (wide)
string...
pszTemp:=String2W("ONLY FOR TESTING PURPOSES !!!")

// Get it back in a VO string...
cTemp:=W2String(pszTemp)
? cTemp
------------------

Just trying to help...

Ronny.

FDW

unread,
May 30, 2003, 9:09:59 AM5/30/03
to
usenet,

For byte/word-string conversions you can use the TS_String class

ASSIGN ByteString(cByteString AS STRING) AS STRING PASCAL CLASS TS_String
ACCESS ByteString AS STRING PASCAL CLASS TS_String
ASSIGN WordString(pWordString AS PTR) AS PTR PASCAL CLASS TS_String
ACCESS WordString AS PTR PASCAL CLASS TS_String

Frans

"usenet" <vo...@null.com> wrote in message news:3ED75B58...@null.com...

usenet

unread,
May 30, 2003, 2:47:46 PM5/30/03
to
FDW wrote:

>usenet,
>
>For byte/word-string conversions you can use the TS_String class
>
>ASSIGN ByteString(cByteString AS STRING) AS STRING PASCAL CLASS TS_String
>ACCESS ByteString AS STRING PASCAL CLASS TS_String
>ASSIGN WordString(pWordString AS PTR) AS PTR PASCAL CLASS TS_String
>ACCESS WordString AS PTR PASCAL CLASS TS_String
>
>Frans
>
>

Thank you,

i prefere the suggested 'native' "W2String(), String2W()", so i don't
need additional library.

could you please take a look on this message:
http://groups.google.com/groups?selm=3ED67119...@null.com

usenet

unread,
May 30, 2003, 3:10:47 PM5/30/03
to
Ronny Michiels wrote:

> W2String(), String2W() ?

this sounds good!

i'm wondering, why the VO-help doesn't list those 2 Functions.

> -----------------
> LOCAL pszTemp AS PSZ
> LOCAL cTemp AS STRING
>
> // Put some text in a psz, in fact a pointer to a null-terminated
> (wide) string...
> pszTemp:=String2W("ONLY FOR TESTING PURPOSES !!!")
>
> // Get it back in a VO string...
> cTemp:=W2String(pszTemp)
> ? cTemp
> ------------------

i understand the usage.

> Just trying to help...

...and i'm very thankfully.

-

final step:

>> Assuming the COMSDK serves me correctly the BSTR* into the variable
>> pName, how do i...
>

looks it does:

METHOD MyEvent( pName ) CLASS MainForm

// pName is a USUAL of type PTR. The PTR points to the BSTR (pointer to
widestring)

LOCAL pszTemp AS PSZ
LOCAL cTemp AS STRING

pszTemp := //??? how to get the value of the pointer out of pName? (in
C++ *pName)

cTemp := W2String(pszTemp) //pszTemp points to the WideString

Feedback(cTemp) // shows the string which comes in

pszTemp:=String2W("This string returns") //??? does this operation a
copy, or must i use MemCopy


ilias

unread,
Jun 3, 2003, 6:34:31 PM6/3/03
to
-------------------------------------------------------------
[repost, original post: usenet <vo...@null.com> 1.6.03 16:33]
[! for some reason the post was not feeded to e.g. google !]
-------------------------------------------------------------

usenet wrote:

>>>Assuming the COMSDK serves me correctly the BSTR* into the variable
>>>pName, how do i...

>>looks it does:

Iit does not!

I can return a value this way:

METHOD MyEvent( pName ) CLASS MainForm

LOCAL pszParamInOut AS PSZ
LOCAL pszReturn AS PSZ

pszParamInOut := pName //!!! pName contains already a PSZ (not
a PTR to a PSZ)

pszReturn := String2Psz("VORETURN") //!!! return a string(!) not a
WideString
MemCopy(pszParamInOut, pszReturn, PszLen(pszReturn)+1 ) // +1 for
0terminator

RETURN NIL

-

It looks like COMSDK generated code serves a native PSZ, thus the
developer can write event-code with native VO string functions,
instead of dealing with BSTR (WideStrings).

This sounds good, where is the problem?

The problem is, that pName is an in/out parameter.

But the incoming string is *not* readable. Neither as WideString, nor
as String.

Debugging of the COMSDK generated code is a little difficult, as the
code is somehow 'hidden'.

Finally the code appears whilst single-step-debugging. It contains
deeply nested IF-THEN-constructs, difficult to read.

Additionally, the code is full of vendor specific debugging calls,
which blows the code up and seems to change the default behavior of VO
debugging.

-

METHOD MyEvent( pName ) CLASS MainForm

LOCAL pszParamInOut AS PSZ
LOCAL cTempW AS STRING
LOCAL cTempN AS STRING
LOCAL cTempS AS STRING

pszParamInOut := pName //!!! pName contains already a PSZ (not
a PTR to a PSZ)

cTempS := STRING(pszParamInOut)
cTempN:=Psz2String( pszParamInOut )
cTempW:=W2String( pszParamInOut )

? pName //!!! results in ?|???????
? cTempS //!!! results in ?|???????
? cTempN //!!! results in ?|???????
? cTempW //!!! results in ????

ilias

unread,
Jun 3, 2003, 6:59:16 PM6/3/03
to
-------------------------------------------------------------
[repost, original post: usenet <vo...@null.com> 1.6.03 20:31]

[! for some reason the post was not feeded to e.g. google !]
-------------------------------------------------------------

usenet wrote:

> usenet wrote:

> It looks like COMSDK generated code serves a native PSZ, thus the developer can > write event-code with native VO string functions, instead of dealing with BSTR > (WideStrings).

> This sounds good, where is the problem?

> The problem is, that pName is an in/out parameter.

> But the incoming string is *not* readable. Neither as WideString, nor as
> String.

I think i've located the bug whilst single-stepping in the
debug-window:

FUNCTION TS_Variant2Usual, second call to WideCharToMultiByte

PSZ(pstruWinVariantArg.uVariant.pbstrVal)

instead of

PSZ(_CAST,LONG(pstruWinVariantArg.uVariant.plVal));

> Debugging of the COMSDK generated code is a little difficult, as the code is
> somehow 'hidden'.

> Finally the code appears whilst single-step-debugging. It contains deeply
> nested IF-THEN-constructs, difficult to read.

but at least it contains extensive documentation in the headers for
nearly eavery function/method (sometimes a copy of MSDN)

> Additionally, the code is full of vendor specific debugging calls, which blows
> the code up and seems to change the default behavior of VO debugging.

-

I cannot edit in the debug-window.

Where's the IDE-function "Open Source File"?

Ok, i go (again) the 'hand-workers-way', to locate the file myself.

ilias

unread,
Jun 4, 2003, 5:24:48 PM6/4/03
to
usenet <vo...@null.com> wrote in message news:<3ED62964...@null.com>...

Now, after a few day's 'fighting':

If you use COMSDK, be aware that at time of this posting there's no
webadress with collected bugreports, bugfixes, new versions etc.

-

Apply this Bugfix:

[COMSDK] - Bug Report/Fix: BSTR* [in,out]
http://groups.google.com/groups?selm=35a10d4c.0306031406.7c654983%40posting.google.com

after that, the generated code from COMSDK works fine (in *this*
matter, don't know further).

-

you have simply to return a string.

METHOD OnTestEvent( pName ) CLASS MyTestEventHandler
LOCAL pszTemp AS PSZ
LOCAL cReturn AS STRING
LOCAL cIncoming AS STRING

pszTemp := pName // pName is a USUAL containing a PSZ

cIncoming := psz2String(pszTemp)

? cIncoming // look what's coming in

cReturn := "ReturnValue"

// it is then copied(!) to the provided pointer
MemCopy(pszTemp, PSZ(cReturn), SLen(cReturn)+1 ) // +1 for
0terminator

RETURN NIL

-

0 new messages