Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

Calling a DLL using Javascript

Hi All,

I know that this is not right forum to address this issue, i had posted
this problem in Javascript forum but of no use, i appreciate if any
one of you can answer or point me to some useful guide.
I tried my hand in google and googlegroups(dejanews) but of no benefit.

I am not able to access a dll function from a remote script using
ActiveXobject when
an output parameter is used, but i could able to access the same when no
output parameter
is used.

While calling a DLL function from my javascript app i am passing 3
parameters
(2 input parameters and 1 output parameter).
The output parameter basically stores the return value which then will be
used
in my Javascript app.
Pl note that in my IDL file i changed the return type of output
parameter to
[out, retval].

Here is my Javascript file.

fun1(id,password)
{
var AutherizedUser;
var ValidateObject = new ActiveXobject("InstallDLL.Install");
ValidateObject.ValidateUser(id,password,AutherizedUser);
return AutherizedUser;
}

DLL

STDMETHODIMP CInstall::ValidateUser(BSTR userId, BSTR pwd, BOOL* pVal)
{
// TODO: Add your implementation code here
LDAP *ldap;

ldap = ldap_open("ldap.xyz.com", LDAP_PORT);

if(ldap == NULL)
{
*pVal = FALSE;
return S_FALSE;
}

ULONG val = ldap_simple_bind_s(ldap, dn, BSTRToChar(pwd));
//pl note that these functions are working properly and no problem with
them.
if (val == LDAP_SUCCESS)
{
*pVal = TRUE;
}
else
{
*pVal = FALSE;
return S_FALSE;
}
return S_OK;
}

I appreciate your help.


Regards
Venkat
0 Kudos
Message 1 of 4
(4,004 Views)
I think the problem might be with your return type - try using VARIANT_BOOL instead of BOOL. Please give that a shot and reply with the result. Thanks.

- Elton
0 Kudos
Message 2 of 4
(4,004 Views)
"Elton Wells" wrote in message
news:506500000005000000A81C0100-1042324653000@exchange.ni.com...
> I think the problem might be with your return type - try using
> VARIANT_BOOL instead of BOOL. Please give that a shot and reply with
> the result. Thanks.
>
> - Elton

Elton thanks for the reply but the problem was in Javascript calling.
The calling is different when output parameters are used. Pl find the
difference.

If id,password and AutherizedUser are Input parameters then Javascript
calling is

var AutherizedUser;
var ValidateObject = new ActiveXobject("InstallDLL.Install");
ValidateObject.ValidateUser(id,password,AutherizedUser);
return AutherizedUser;

If id and password are input parameters and AuthorizedUser is output
par
ameter then the calling is
var AutherizedUser;
var ValidateObject = new ActiveXobject("InstallDLL.Install");
AutherizedUser = ValidateObject.ValidateUser(id,password);
return AutherizedUser;

But at the same time as i mentioned earlier for output parameters we need to
mention
[out,retval] in IDL file.

Regards
Venkat
0 Kudos
Message 3 of 4
(4,004 Views)
If my previous answer didn't apply to the question at all, then I don't still don't understand what your question is. I thought that your original question was that you were trying to return a boolean value from the ValidateUser method and that wasn't working when you were trying to call if from JavaScript. If that is the case, then [out, retval] will work, but you need to use automation compatible types. The C++ snippet that you posted showed that you were using a BOOL for your return type, and it should be VARIANT_BOOL. If this wasn't your question, could you please be more explicit about what you're trying to do and what exactly isn't working.

You also mentioned this:


"If id,password and AutherizedUser are Input parameters then
Javascript calling is:


var AutherizedUser;
var ValidateObject = new ActiveXobject("InstallDLL.Install");
ValidateObject.ValidateUser(id,password,Autherized User);
return AutherizedUser;
"

You said that AuthorizedUser is an input parameter, but since you're passing it to the method and then returning it, it looks like you're trying to use it as an output parameter. If AuthorizedUser really is an input parameter, this snippet is always going to return null because AuthorizedUser never gets initialized to anything. Is that the problem that you were seeing?

- Elton
0 Kudos
Message 4 of 4
(4,004 Views)