HRESULT return value in Javascript without exception

Discussion in 'ASP .Net' started by =?Utf-8?B?Um9i?=, Jul 30, 2007.

  1. Hi,
    If I call my own DLL from Javascript, a HRESULT is returned.
    Javascript cannot cast this to an integer.
    Is there any other way of typecasting this returnvalue to integer, wihout
    using the exception method which is described everywhere ?
    Please note that I am unfamiliar with javascript, I am used to C/C++.

    My Javascript call looks like :

    var result;
    result = Testfunc1();

    The function is called OK, but the returnvalue cannot be converted.
    It is printed as "undefined".
    I just need 0 or 1 to be returned (or 2 other values, one for OK, and one
    for ERROR)
    So I tried the following :

    result = (Testfunc1() & 255) ;

    But this always returns 0 for some reason....

    It seems unlogical and not neat, to throw exceptions when really nothing
    serious happenned, just to convert the returnvalue. Also the clientcode will
    be poluted with a lot of extra (rather poorly structured) lines.
    So If I could just get the low-byte of the HRESULT, this would be enough for
    me.

    Please Help !

    Greetings,
    Rob.
    =?Utf-8?B?Um9i?=, Jul 30, 2007
    #1
    1. Advertising

  2. How does javascript know your function?

    Do you mean you call it on an object reference like

    myObj = ActiveXObject ("Prog ID of COM DLL");
    result = myObj.Testfunc1();


    --
    Eliyahu Goldin,
    Software Developer
    Microsoft MVP [ASP.NET]
    http://msmvps.com/blogs/egoldin
    http://usableasp.net


    "Rob" <> wrote in message
    news:...
    > Hi,
    > If I call my own DLL from Javascript, a HRESULT is returned.
    > Javascript cannot cast this to an integer.
    > Is there any other way of typecasting this returnvalue to integer, wihout
    > using the exception method which is described everywhere ?
    > Please note that I am unfamiliar with javascript, I am used to C/C++.
    >
    > My Javascript call looks like :
    >
    > var result;
    > result = Testfunc1();
    >
    > The function is called OK, but the returnvalue cannot be converted.
    > It is printed as "undefined".
    > I just need 0 or 1 to be returned (or 2 other values, one for OK, and one
    > for ERROR)
    > So I tried the following :
    >
    > result = (Testfunc1() & 255) ;
    >
    > But this always returns 0 for some reason....
    >
    > It seems unlogical and not neat, to throw exceptions when really nothing
    > serious happenned, just to convert the returnvalue. Also the clientcode
    > will
    > be poluted with a lot of extra (rather poorly structured) lines.
    > So If I could just get the low-byte of the HRESULT, this would be enough
    > for
    > me.
    >
    > Please Help !
    >
    > Greetings,
    > Rob.
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    Eliyahu Goldin, Jul 30, 2007
    #2
    1. Advertising

  3. Yes.....
    As I mentioned, the function is called OK, So I left this part out.

    Greetings,
    Rob

    "Eliyahu Goldin" wrote:

    > How does javascript know your function?
    >
    > Do you mean you call it on an object reference like
    >
    > myObj = ActiveXObject ("Prog ID of COM DLL");
    > result = myObj.Testfunc1();
    >
    >
    > --
    > Eliyahu Goldin,
    > Software Developer
    > Microsoft MVP [ASP.NET]
    > http://msmvps.com/blogs/egoldin
    > http://usableasp.net
    >
    >
    > "Rob" <> wrote in message
    > news:...
    > > Hi,
    > > If I call my own DLL from Javascript, a HRESULT is returned.
    > > Javascript cannot cast this to an integer.
    > > Is there any other way of typecasting this returnvalue to integer, wihout
    > > using the exception method which is described everywhere ?
    > > Please note that I am unfamiliar with javascript, I am used to C/C++.
    > >
    > > My Javascript call looks like :
    > >
    > > var result;
    > > result = Testfunc1();
    > >
    > > The function is called OK, but the returnvalue cannot be converted.
    > > It is printed as "undefined".
    > > I just need 0 or 1 to be returned (or 2 other values, one for OK, and one
    > > for ERROR)
    > > So I tried the following :
    > >
    > > result = (Testfunc1() & 255) ;
    > >
    > > But this always returns 0 for some reason....
    > >
    > > It seems unlogical and not neat, to throw exceptions when really nothing
    > > serious happenned, just to convert the returnvalue. Also the clientcode
    > > will
    > > be poluted with a lot of extra (rather poorly structured) lines.
    > > So If I could just get the low-byte of the HRESULT, this would be enough
    > > for
    > > me.
    > >
    > > Please Help !
    > >
    > > Greetings,
    > > Rob.
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > >

    >
    >
    >
    =?Utf-8?B?Um9i?=, Jul 30, 2007
    #3
  4. =?Utf-8?B?Um9i?=

    bruce barker Guest

    HResult is meant to return errors, and is not the return value of a
    interface. change the com interface to return an int value, then
    javascript can access it.

    -- bruce (sqlwork.com)

    Rob wrote:
    > Hi,
    > If I call my own DLL from Javascript, a HRESULT is returned.
    > Javascript cannot cast this to an integer.
    > Is there any other way of typecasting this returnvalue to integer, wihout
    > using the exception method which is described everywhere ?
    > Please note that I am unfamiliar with javascript, I am used to C/C++.
    >
    > My Javascript call looks like :
    >
    > var result;
    > result = Testfunc1();
    >
    > The function is called OK, but the returnvalue cannot be converted.
    > It is printed as "undefined".
    > I just need 0 or 1 to be returned (or 2 other values, one for OK, and one
    > for ERROR)
    > So I tried the following :
    >
    > result = (Testfunc1() & 255) ;
    >
    > But this always returns 0 for some reason....
    >
    > It seems unlogical and not neat, to throw exceptions when really nothing
    > serious happenned, just to convert the returnvalue. Also the clientcode will
    > be poluted with a lot of extra (rather poorly structured) lines.
    > So If I could just get the low-byte of the HRESULT, this would be enough for
    > me.
    >
    > Please Help !
    >
    > Greetings,
    > Rob.
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    bruce barker, Jul 30, 2007
    #4
  5. Tried that, but the project (ATL activex) doesn't compile such a member.
    It says that all interface members must return HRESULT.

    Error, returnvalue, whatever.... ( is S_OK an error? )
    What matters to me is that Javascript seems unable to typecast the 4 byte
    piece of memory (HRESULT==LONG in C++) that is returned to something usefull.

    Greetings,
    Rob.


    "bruce barker" wrote:

    > HResult is meant to return errors, and is not the return value of a
    > interface. change the com interface to return an int value, then
    > javascript can access it.
    >
    > -- bruce (sqlwork.com)
    >
    > Rob wrote:
    > > Hi,
    > > If I call my own DLL from Javascript, a HRESULT is returned.
    > > Javascript cannot cast this to an integer.
    > > Is there any other way of typecasting this returnvalue to integer, wihout
    > > using the exception method which is described everywhere ?
    > > Please note that I am unfamiliar with javascript, I am used to C/C++.
    > >
    > > My Javascript call looks like :
    > >
    > > var result;
    > > result = Testfunc1();
    > >
    > > The function is called OK, but the returnvalue cannot be converted.
    > > It is printed as "undefined".
    > > I just need 0 or 1 to be returned (or 2 other values, one for OK, and one
    > > for ERROR)
    > > So I tried the following :
    > >
    > > result = (Testfunc1() & 255) ;
    > >
    > > But this always returns 0 for some reason....
    > >
    > > It seems unlogical and not neat, to throw exceptions when really nothing
    > > serious happenned, just to convert the returnvalue. Also the clientcode will
    > > be poluted with a lot of extra (rather poorly structured) lines.
    > > So If I could just get the low-byte of the HRESULT, this would be enough for
    > > me.
    > >
    > > Please Help !
    > >
    > > Greetings,
    > > Rob.
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > >

    >
    =?Utf-8?B?Um9i?=, Jul 30, 2007
    #5
  6. Try describing your interface method in IDL like this:

    HRESULT Testfunc1([out, retval] long *pResult);

    and in C++ :

    STDMETHODIMP Cwork::Testfunc1(long *pResult)
    {
    *pResult = 111;
    return S_OK;
    }


    --
    Eliyahu Goldin,
    Software Developer & Consultant
    Microsoft MVP [ASP.NET]
    http://msmvps.com/blogs/egoldin


    "Rob" <> wrote in message
    news:...
    > Tried that, but the project (ATL activex) doesn't compile such a member.
    > It says that all interface members must return HRESULT.
    >
    > Error, returnvalue, whatever.... ( is S_OK an error? )
    > What matters to me is that Javascript seems unable to typecast the 4 byte
    > piece of memory (HRESULT==LONG in C++) that is returned to something

    usefull.
    >
    > Greetings,
    > Rob.
    >
    >
    > "bruce barker" wrote:
    >
    > > HResult is meant to return errors, and is not the return value of a
    > > interface. change the com interface to return an int value, then
    > > javascript can access it.
    > >
    > > -- bruce (sqlwork.com)
    > >
    > > Rob wrote:
    > > > Hi,
    > > > If I call my own DLL from Javascript, a HRESULT is returned.
    > > > Javascript cannot cast this to an integer.
    > > > Is there any other way of typecasting this returnvalue to integer,

    wihout
    > > > using the exception method which is described everywhere ?
    > > > Please note that I am unfamiliar with javascript, I am used to C/C++.
    > > >
    > > > My Javascript call looks like :
    > > >
    > > > var result;
    > > > result = Testfunc1();
    > > >
    > > > The function is called OK, but the returnvalue cannot be converted.
    > > > It is printed as "undefined".
    > > > I just need 0 or 1 to be returned (or 2 other values, one for OK, and

    one
    > > > for ERROR)
    > > > So I tried the following :
    > > >
    > > > result = (Testfunc1() & 255) ;
    > > >
    > > > But this always returns 0 for some reason....
    > > >
    > > > It seems unlogical and not neat, to throw exceptions when really

    nothing
    > > > serious happenned, just to convert the returnvalue. Also the

    clientcode will
    > > > be poluted with a lot of extra (rather poorly structured) lines.
    > > > So If I could just get the low-byte of the HRESULT, this would be

    enough for
    > > > me.
    > > >
    > > > Please Help !
    > > >
    > > > Greetings,
    > > > Rob.
    > > >
    > > >
    > > >
    > > >
    > > >
    > > >
    > > >
    > > >
    > > >
    > > >
    > > >
    > > >
    > > >
    > > >
    > > >
    > > >
    > > >
    > > >
    > > >
    > > >
    > > >

    > >
    Eliyahu Goldin, Jul 31, 2007
    #6
  7. Hi,
    Thanks for the response.
    I tried that too, but I cannot seem to pass a pointer from javascript.

    From what I read on Inet, Javascript can pass "references" if you pass a
    non-basic type to a function (like an object). So If I have "int a" , I
    should pass "a.value", which should be passed as a "reference" (whatever that
    is in Javascript).
    For an int * my c++ function does not receive a correct pointer.
    So if anyone knows how to do this, please let me know.

    Greetings,
    Rob.









    "Eliyahu Goldin" wrote:

    > Try describing your interface method in IDL like this:
    >
    > HRESULT Testfunc1([out, retval] long *pResult);
    >
    > and in C++ :
    >
    > STDMETHODIMP Cwork::Testfunc1(long *pResult)
    > {
    > *pResult = 111;
    > return S_OK;
    > }
    >
    >
    > --
    > Eliyahu Goldin,
    > Software Developer & Consultant
    > Microsoft MVP [ASP.NET]
    > http://msmvps.com/blogs/egoldin
    >
    >
    > "Rob" <> wrote in message
    > news:...
    > > Tried that, but the project (ATL activex) doesn't compile such a member.
    > > It says that all interface members must return HRESULT.
    > >
    > > Error, returnvalue, whatever.... ( is S_OK an error? )
    > > What matters to me is that Javascript seems unable to typecast the 4 byte
    > > piece of memory (HRESULT==LONG in C++) that is returned to something

    > usefull.
    > >
    > > Greetings,
    > > Rob.
    > >
    > >
    > > "bruce barker" wrote:
    > >
    > > > HResult is meant to return errors, and is not the return value of a
    > > > interface. change the com interface to return an int value, then
    > > > javascript can access it.
    > > >
    > > > -- bruce (sqlwork.com)
    > > >
    > > > Rob wrote:
    > > > > Hi,
    > > > > If I call my own DLL from Javascript, a HRESULT is returned.
    > > > > Javascript cannot cast this to an integer.
    > > > > Is there any other way of typecasting this returnvalue to integer,

    > wihout
    > > > > using the exception method which is described everywhere ?
    > > > > Please note that I am unfamiliar with javascript, I am used to C/C++.
    > > > >
    > > > > My Javascript call looks like :
    > > > >
    > > > > var result;
    > > > > result = Testfunc1();
    > > > >
    > > > > The function is called OK, but the returnvalue cannot be converted.
    > > > > It is printed as "undefined".
    > > > > I just need 0 or 1 to be returned (or 2 other values, one for OK, and

    > one
    > > > > for ERROR)
    > > > > So I tried the following :
    > > > >
    > > > > result = (Testfunc1() & 255) ;
    > > > >
    > > > > But this always returns 0 for some reason....
    > > > >
    > > > > It seems unlogical and not neat, to throw exceptions when really

    > nothing
    > > > > serious happenned, just to convert the returnvalue. Also the

    > clientcode will
    > > > > be poluted with a lot of extra (rather poorly structured) lines.
    > > > > So If I could just get the low-byte of the HRESULT, this would be

    > enough for
    > > > > me.
    > > > >
    > > > > Please Help !
    > > > >
    > > > > Greetings,
    > > > > Rob.
    > > > >
    > > > >
    > > > >
    > > > >
    > > > >
    > > > >
    > > > >
    > > > >
    > > > >
    > > > >
    > > > >
    > > > >
    > > > >
    > > > >
    > > > >
    > > > >
    > > > >
    > > > >
    > > > >
    > > > >
    > > > >
    > > >

    >
    >
    >
    =?Utf-8?B?Um9i?=, Jul 31, 2007
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Stan Sainte-Rose

    Exception from HRESULT: 0x800AC352

    Stan Sainte-Rose, May 10, 2004, in forum: ASP .Net
    Replies:
    13
    Views:
    1,981
  2. Replies:
    1
    Views:
    6,502
    maythetzan
    Feb 26, 2008
  3. Mitja Semolic
    Replies:
    0
    Views:
    8,546
    Mitja Semolic
    Nov 15, 2005
  4. chanmm
    Replies:
    6
    Views:
    35,439
    Damien
    Nov 25, 2005
  5. Lloyd Dupont
    Replies:
    0
    Views:
    4,194
    Lloyd Dupont
    Jan 5, 2007
Loading...

Share This Page