how to declare a pointer

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Simon

    #1

    how to declare a pointer

    I'm a js newbie trying to use some very simple js to call an ActiveX
    object's methods.
    I need to use a pointer to call an embedded ActiveX object's method to
    receive a number.
    As I understand it, js is typeless so how can I get a variable to be a
    pointer type?
    Passing var i as the parameter gets an undefined value in return.

    Thanks IA, Simon


  • Michael Winter

    #2
    Re: how to declare a pointer

    On Sun, 4 Apr 2004 19:35:24 +0000 (UTC), Simon
    <simbil.nospam. bill@btinternet .please.com> wrote:
    [color=blue]
    > I'm a js newbie trying to use some very simple js to call an ActiveX
    > object's methods.
    > I need to use a pointer to call an embedded ActiveX object's method to
    > receive a number.
    > As I understand it, js is typeless so how can I get a variable to be a
    > pointer type?
    > Passing var i as the parameter gets an undefined value in return.[/color]

    JavaScript doesn't have pointers[1]. The closest thing is references, but
    they only exist for passing objects and arrays as function parameters.
    Primitive types (booleans, string, numbers) are always passed by value.

    Without pointing to the documentation for this ActiveX object, or
    describing it in more detail, there isn't much help anyone can provide.

    Mike


    [1] Microsoft's DHTML Reference documentation talks about them all the
    time, but there's a lot of mistakes in those pages, and using the word
    "pointer" is one of them.

    --
    Michael Winter
    M.Winter@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)

    Comment

    • Simon

      #3
      Re: how to declare a pointer

      >[color=blue]
      > JavaScript doesn't have pointers[1]. The closest thing is references, but
      > they only exist for passing objects and arrays as function parameters.
      > Primitive types (booleans, string, numbers) are always passed by value.
      >
      > Without pointing to the documentation for this ActiveX object, or
      > describing it in more detail, there isn't much help anyone can provide.
      >[/color]

      Mike,

      The ActiveX object is one of my own so I can change the parameters as
      necessary. Currently it has a function that takes 2 paramters, one in is a
      WideString (in) and the other is a Variant pointer (out). It was written
      purely as an exercise to see if I can get a returned variable in javascript.
      The ActiveX limitation is that 'out' type parameters must be pointers.
      It may work if I can pass a variable by reference as a reference is an
      address of the variable much like a pointer? Is there a way to reference a
      variable in js or does it happen automatically when the variable is passed
      to a function?

      Thanks, Simon


      Comment

      • Michael Winter

        #4
        Re: how to declare a pointer

        On Mon, 5 Apr 2004 08:11:04 +0000 (UTC), Simon
        <simbil.nospam. bill@btinternet .please.com> wrote:

        [snip]
        [color=blue]
        > The ActiveX object is one of my own so I can change the parameters as
        > necessary. Currently it has a function that takes 2 paramters, one in is
        > a WideString (in) and the other is a Variant pointer (out). It was
        > written purely as an exercise to see if I can get a returned variable in
        > javascript.[/color]

        It would probably be best to use a return value, rather than attempting to
        pass by reference.
        [color=blue]
        > The ActiveX limitation is that 'out' type parameters must be pointers.
        > It may work if I can pass a variable by reference as a reference is an
        > address of the variable much like a pointer?[/color]

        There is no concept of "addresses" in JavaScript.
        [color=blue]
        > Is there a way to reference a variable in js or does it happen
        > automatically when the variable is passed to a function?[/color]

        References are always used with objects and arrays, whether a function
        call is involved or not. However, they are only used with objects and
        arrays. You can't specify how a variable is passed during a call.

        Mike

        --
        Michael Winter
        M.Winter@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)

        Comment

        • Simon

          #5
          Re: how to declare a pointer

          > It would probably be best to use a return value, rather than attempting to[color=blue]
          > pass by reference.
          >[/color]
          Functions of automation interfaces mush have a return type of HResult (a
          least that is what my IDE tells me), so I cannot emply this strategy.
          [color=blue]
          > References are always used with objects and arrays, whether a function
          > call is involved or not. However, they are only used with objects and
          > arrays. You can't specify how a variable is passed during a call.
          >[/color]
          Looks like it won't work then. Thanks for your help.


          Comment

          • Dag Sunde

            #6
            Re: how to declare a pointer

            "Simon" <simbil.nospam. bill@btinternet .please.com> wrote in message
            news:c4tn34$hps $1@titan.btinte rnet.com...[color=blue][color=green]
            > > It would probably be best to use a return value, rather than attempting[/color][/color]
            to[color=blue][color=green]
            > > pass by reference.
            > >[/color]
            > Functions of automation interfaces mush have a return type of HResult (a
            > least that is what my IDE tells me), so I cannot emply this strategy.
            >[color=green]
            > > References are always used with objects and arrays, whether a function
            > > call is involved or not. However, they are only used with objects and
            > > arrays. You can't specify how a variable is passed during a call.
            > >[/color]
            > Looks like it won't work then. Thanks for your help.
            >[/color]

            Do I understand you corredtly, when I sat that you have made a (visible)
            ActiveX component that you display on a web-bage like this:

            <object
            classid="clsid: E217D189-AEA5-4F62-A044-A716C202474B"
            id="activeX">
            </object>

            ....and that you want to access some (public) value or call a method in
            that activeX component from JavaScript on the same page?

            like this(?):

            <script type="text/javascript">
            function Test()
            {
            var myObj = document.getEle mentById("activ eX")
            alert(myObj.get Value());
            }
            </script>

            If so, that is quite possible, and JavaScript can call any public method,
            and access any public member of the activeX control. And functions are
            *not* limited to the HResult type!

            --
            Dag.


            Comment

            • Simon

              #7
              Re: how to declare a pointer

              >[color=blue]
              > Do I understand you corredtly, when I sat that you have made a (visible)
              > ActiveX component that you display on a web-bage like this:
              >
              > <object
              > classid="clsid: E217D189-AEA5-4F62-A044-A716C202474B"
              > id="activeX">
              > </object>
              >[/color]

              Yep
              [color=blue]
              > ...and that you want to access some (public) value or call a method in
              > that activeX component from JavaScript on the same page?
              >
              > like this(?):
              >
              > <script type="text/javascript">
              > function Test()
              > {
              > var myObj = document.getEle mentById("activ eX")
              > alert(myObj.get Value());
              > }
              > </script>[/color]

              Near enough, yes.
              [color=blue]
              >
              > If so, that is quite possible, and JavaScript can call any public method,
              > and access any public member of the activeX control. And functions are
              > *not* limited to the HResult type!
              >[/color]

              The return of an automation interface method is limited to HResult in
              Delphi, I don't know why.

              I have no problem getting and setting properties and I have no problem
              calling methods. The issue is getting a return (out) parameter from the
              method.

              eg. Method = AddText(in Text: BSTR; out Index: long * )

              I can call the above method and it will execute, but I cannot get the out
              parameter.
              In Delphi the out parameters must be pointer types.

              Any ideas?

              Simon


              Comment

              • Dag Sunde

                #8
                Re: how to declare a pointer

                "Simon" <simbil.nospam. bill@btinternet .please.com> wrote in message
                news:c4uhbq$j4v $1@hercules.bti nternet.com...
                <snipped />
                [color=blue]
                > The return of an automation interface method is limited to HResult in
                > Delphi, I don't know why.
                >
                > I have no problem getting and setting properties and I have no problem
                > calling methods. The issue is getting a return (out) parameter from the
                > method.
                >
                > eg. Method = AddText(in Text: BSTR; out Index: long * )
                >
                > I can call the above method and it will execute, but I cannot get the out
                > parameter.
                > In Delphi the out parameters must be pointer types.
                >
                > Any ideas?[/color]

                Let's clear up a couple of things first...

                The HRESULT return type of an automation interface does not have
                anything to do with your parameters of return value, but is the result
                of the automation process (ie. success/error code).

                The Delphi help file say that:
                "If a parameter type is specified as a Pointer type, the Type Library
                editor usually translates that type into a variable parameter. When the
                type library is saved, the variable parameter's associated ElemDesc's
                IDL flags are marked IDL_FIN or IDL_FOUT."



                // ---------- copied from Delphi help...----------------
                DevGuide: Developing COM-based applications
                Valid types

                Topic Groups See Also

                In the Type Library editor, you use different type identifiers, depending on
                whether you are working in IDL or Delphi. Specify the language you want to
                use in the Environment options dialog.

                The following types are valid in a type library for COM development. The
                Automation compatible column specifies whether the type can be used by an
                interface that has its Automation or Dispinterface flag checked. These are
                the types that COM can marshal via the type library automatically.

                Delphi type IDL type variant type Automation compatible Description
                Smallint short VT_I2 Yes 2-byte signed integer
                Integer long VT_I4 Yes 4-byte signed integer
                Single single VT_R4 Yes 4-byte real
                Double double VT_R8 Yes 8-byte real
                Currency CURRENCY VT_CY Yes currency
                TDateTime DATE VT_DATE Yes date
                WideString BSTR VT_BSTR Yes binary string
                IDispatch IDispatch VT_DISPATCH Yes pointer to IDispatch interface
                SCODE SCODE VT_ERROR Yes Ole Error Code
                WordBool VARIANT_BOOL VT_BOOL Yes True = -1, False = 0
                OleVariant VARIANT VT_VARIANT Yes Ole Variant
                IUnknown IUnknown VT_UNKNOWN Yes pointer to IUnknown interface
                Shortint byte VT_I1 No 1 byte signed integer
                Byte unsigned char VT_UI1 Yes 1 byte unsigned integer
                Word unsigned short VT_UI2 Yes* 2 byte unsigned integer
                LongWord unsigned long VT_UI4 Yes* 4 byte unsigned integer
                Int64 __int64 VT_I8 No 8 byte signed integer
                Largeuint uint64 VT_UI8 No 8 byte unsigned integer
                SYSINT int VT_INT Yes* system dependent integer (Win32=Integer)
                SYSUINT unsigned int VT_UINT Yes* system dependent unsigned integer
                HResult HRESULT VT_HRESULT No 32 bit error code
                Pointer VT_PTR -> VT_VOID No untyped pointer
                SafeArray SAFEARRAY VT_SAFEARRAY No OLE Safe Array
                PChar LPSTR VT_LPSTR No pointer to Char
                PWideChar LPWSTR VT_LPWSTR No pointer to WideChar


                * Word, LongWord, SYSINT, and SYSUINT may be Automation-compatible with some
                applications.
                See safe arrays for more information about the SAFEARRAY Variant type.

                Note

                The Byte (VT_UI1) is Automation-compatible, but is not allowed in a Variant
                or OleVariant since many Automation servers do not handle this value
                correctly.
                Besides these IDL types, any interfaces and types defined in the library or
                defined in referenced libraries can be used in a type library definition.
                The Type Library editor stores type information in the generated type
                library (.TLB) file in binary form.
                If a parameter type is specified as a Pointer type, the Type Library editor
                usually translates that type into a variable parameter. When the type
                library is saved, the variable parameter's associated ElemDesc's IDL flags
                are marked IDL_FIN or IDL_FOUT.

                Often, ElemDesc IDL flags are not marked by IDL_FIN or IDL_FOUT when the
                type is preceded with a Pointer. Or, in the case of dispinterfaces, IDL
                flags are not typically used. In these cases, you may see a comment next to
                the variable identifier such as {IDL_None} or {IDL_In}. These comments are
                used when saving a type library to correctly mark the IDL flags.

                --
                Dag.


                Comment

                • Simon

                  #9
                  Re: how to declare a pointer

                  <snipped>
                  [color=blue]
                  > Let's clear up a couple of things first...
                  >
                  > The HRESULT return type of an automation interface does not have
                  > anything to do with your parameters of return value, but is the result
                  > of the automation process (ie. success/error code).
                  >[/color]

                  Ok.
                  [color=blue]
                  > The Delphi help file say that:[/color]
                  <snipped>

                  Yes.

                  So back to my original question - how can I use an IDL_FOUT parameter in
                  javascipt?

                  Activex:
                  eg. Method = AddText(in Text: BSTR; out Index: long * )

                  Js:
                  var i;
                  i = 0;
                  activeX.Method( 'hello', i);
                  //i still = 0

                  Thanks, Simon


                  Comment

                  • Dag Sunde

                    #10
                    Re: how to declare a pointer

                    "Simon" <simbil.nospam. bill@btinternet .please.com> wrote in message
                    news:c519ra$o7$ 1@hercules.btin ternet.com...[color=blue]
                    > <snipped>
                    >[color=green]
                    > > Let's clear up a couple of things first...
                    > >
                    > > The HRESULT return type of an automation interface does not have
                    > > anything to do with your parameters of return value, but is the result
                    > > of the automation process (ie. success/error code).
                    > >[/color]
                    >
                    > Ok.
                    >[color=green]
                    > > The Delphi help file say that:[/color]
                    > <snipped>
                    >
                    > Yes.
                    >
                    > So back to my original question - how can I use an IDL_FOUT parameter in
                    > javascipt?
                    >
                    > Activex:
                    > eg. Method = AddText(in Text: BSTR; out Index: long * )
                    >
                    > Js:
                    > var i;
                    > i = 0;
                    > activeX.Method( 'hello', i);
                    > //i still = 0
                    >[/color]

                    Have you tried declaring it like:

                    HRESULT = _stdcall AddText([in] BSTR Text, [out, retval] long * Index);
                    (in the "View -> Type Library" menu...)

                    and use it like:

                    var i = activeX.method( 'hello');

                    ???

                    --
                    Dag.



                    Comment

                    • Simon

                      #11
                      Re: how to declare a pointer

                      >[color=blue]
                      > Have you tried declaring it like:
                      >
                      > HRESULT = _stdcall AddText([in] BSTR Text, [out, retval] long *[/color]
                      Index);[color=blue]
                      > (in the "View -> Type Library" menu...)
                      >
                      > and use it like:
                      >
                      > var i = activeX.method( 'hello');
                      >
                      > ???
                      >
                      > --
                      > Dag.
                      >
                      >[/color]

                      I tried that and it works with the out param set as the retval.
                      Thanks Dag.


                      Comment

                      Working...