Forum Discussion

rkarger's avatar
rkarger
Occasional Contributor
13 years ago

Sending a response through an event handler

The event that I am handling in my current test needs to send a response back to its source.  The script that handles the event include a string parameter that had to be updated to send the response back to the source.  I am not having any trouble receiving the event in TestComplete but the system that is supposed to receive the response is getting absolutely nothing.



Sub MyEventControl_OnViewportQuery(Sender, nTransactionID, lQueryType, pszwQueryPrompt, ppszwResponse, nUserPassBack)

  If lQueryType = 8 Then

    ppszwResponse = "Yes"

    Log.Message ppszwResponse

  End If

End Sub



Does anyone have experience with a similar situation or problem?
  • Hi Rebecca,



    From the ppszwResponse parameter name, it seems to be a pointer to a Unicode string or a pointer to an array of Unicode strings. These data types are different from VBScript strings, that's why, a simple assignment doesn't work.



    To figure out how to use the
    ppszwResponse
    parameter in TestComplete scripts, we'll need the following information:

    * The event handler interface declaration (for example, an IDL file).

    * An example in C++ (or whatever language the component is written in) that shows how to fire this event and use its parameters.



    Could you please ask your developers for this information, and then post it here? If you don't want to post it on a public forum, you can open a support ticket (that's private) and attach it there.
  • rkarger's avatar
    rkarger
    Occasional Contributor
    I've pursued the private support route, thank you.
  • Hi Rebecca,



    Just a quick idea. According to Microsoft KB article 244012 and this blog post by Eric Lippert from Microsoft, VBScript supports only VARIANT ByRef parameters. However, your component seems to be using ByRef BSTR, which isn't supported. This would explain why the parameter value isn't passed from VBScript into the component.



    If I get it right, possible workarounds for the issue would involve changes in the component's source code:

    - change the parameter type from BSTR * to VARIANT *, or

    - create type-library-based IDispatch implementation that would transform ByRef VARIANTs pointing to strings into ByRef strings.



    Hopefully, Support can shed more light on this though.
  • rkarger's avatar
    rkarger
    Occasional Contributor
    Hi Helen,



    The parameter is a BSTR*, yes.  I used GetVarType to check what it was coming in as and whether or not I have ByRef there it is an OLEStr.  It's not possible to get the source code changed as far as I know - do you have any other thoughts?  I'm still waiting to hear a response on my support ticket, which I submitted Friday.



    Thanks,

    Rebecca
  • Hi Rebecca,



    On second thought, you can probably work around this by creating an intermediate layer for event handling, say, in C#. For example, you could write a small C# app that would handle the OnViewportQuery event and have this app running along with your test script at the same time. You'll also be able to pass data between your test script and this C# app, since TestComplete can access all classes and members inside .NET applications. So, I think this could actually work.
  • hlalumiere's avatar
    hlalumiere
    Regular Contributor
    In this case the easiest approach would be to write a COM wrapper in VB.Net express to provide a compatibility layer to the library you need, and make your calls to that wrapper.