473,396 Members | 1,757 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

HRESULT return value in Javascript without exception

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.







Jul 30 '07 #1
6 3214
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" <Ro*@discussions.microsoft.comwrote in message
news:36**********************************@microsof t.com...
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.







Jul 30 '07 #2
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" <Ro*@discussions.microsoft.comwrote in message
news:36**********************************@microsof t.com...
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.









Jul 30 '07 #3
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.






Jul 30 '07 #4
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.







Jul 30 '07 #5
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" <Ro*@discussions.microsoft.comwrote in message
news:5F**********************************@microsof t.com...
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.
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

Jul 30 '07 #6
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" <Ro*@discussions.microsoft.comwrote in message
news:5F**********************************@microsof t.com...
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.





















>


Jul 31 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: lakshmi | last post by:
Hi We are rewriting a COM object in C#. The COM object returns HRESULT for invalid arguments, null values etc. The HRESULT is created using the MAKE_HRESULT macro in C++. 1.What is the C#...
3
by: Lekyan | last post by:
I have problem setting the password for an ADAM user using C#. I used the SetPassword code given in the Microsoft page, changed several parameters, but ran into an exception. I wonder if other...
1
by: Kimmo Laine | last post by:
Hi, we have a (unmanaged) ATL COM server, which implements two interface: ITestInterface1 and ITestInterface2. Both of these interfaces also support the ISupportErrorInfo-interface. Interface...
1
by: Display Name | last post by:
Exception class has HRESULT as protected member. Is there a header file or tool to get the entire mapping of C# Exception to HRESULT? Any tools / header file / links appreciated
1
by: Manoj | last post by:
Hi, In our application we reference com components written in c++.When errors occur the messages appear like this 'Exception from HRESULT: 0xC0068002" is there a way to convert this HResult...
0
by: TrtnJohn | last post by:
I've recently converted some VB 6 code over that used the old non-structured exception handling. I also have some .NET classes that raise custom exception classes. When the code was VB6 I used to...
4
by: cpajoe2001 | last post by:
I am not sure if this is the proper place to put this thread but I have run into a road block. I am writing a web app that will create groups in Active Directory then add users to those groups. I...
11
by: Academia | last post by:
I've been Googling and there is many many hits but I can't find what I want. I've read at one time how DotNET treats HRESULT but can't find it now. Does it return HRESULT unchanged or does it...
4
by: yogarajan | last post by:
The specified module could not be found. (Exception from HRESULT: 0x8007007E) Description: An unhandled exception occurred during the execution of the current web request. Please review the stack...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.