|
-
Feb 24th, 2004, 01:18 PM
#1
Thread Starter
New Member
JavaScript/C++: Passing a JavaScript String to C++ ActiveX Control
Hey everyone, I'm writing an ActiveX control to embed inside an Internet Explorer page, and I'm having trouble passing a string to an ActiveX method from inside JavaScript.
On the ActiveX side, I'm using C++ to compile and register an OCX, and the syntax for my method looks like this:
VARIANT_BOOL ProcessText(char * TextString)
On the JavaScript side, I call the method like this:
<OBJECT id="TextControl" classid="clsid:F73A5DFD-1117-4485-B486-8ECDF0638736" VIEWASTEXT>
<input name="btnProcess" type="button" value="Process" onclick="document.TextControl.ProcessText("Textblahblah");">
Clicking the Process button gives me a "Type Mismatch" error.
So what do I have to do to make this call work? The ActiveX function works fine if I call it from the ActiveX Test Container. It seems to be some kind of conversion problem between JavaScript and C++.
Thank you for any help.
-
Feb 25th, 2004, 06:14 AM
#2
The parameter should be a BSTR.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Feb 25th, 2004, 01:06 PM
#3
Thread Starter
New Member
Okay, I've tried both
VARIANT_BOOL ProcessText(BSTR TextString)
and
VARIANT_BOOL ProcessText(BSTR * TextString)
I still get a "Type Mismatch" from Internet Explorer with both.
-
Feb 27th, 2004, 11:59 AM
#4
Thread Starter
New Member
Update
A forum member suggested moving the JavaScript call out from the button onclick to a stand-alone JavaScript function like this:
function passmystring(myString)
{
TextControl.ProcessText(myString);
}
But, I still get a Type Mismatch inside the JavaScript function when it calls the ActiveX function.
I double-checked everything inside the debugger, and I've confirmed that I'm passing a proper string for myString.
Any other ideas on what's going wrong here?
-
Feb 27th, 2004, 03:43 PM
#5
Frenzied Member
I have written a lot of C but no C++. And I have written Java applets that receive Strings from JavaScript routines. So, I tried Googling for sites with Java<->C++ data types looking for the C++ equivalent of a Java String.
I found this: http://www.codemesh.com/en/faqProgrammingStrings.html, but I don't know if it will be helpful to you or not.
-
Feb 28th, 2004, 03:34 AM
#6
This is about JavaScript (specifically, JScript), not Java. The two technologies are not related.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Feb 28th, 2004, 08:09 AM
#7
Frenzied Member
Originally posted by CornedBee
This is about JavaScript (specifically, JScript), not Java. The two technologies are not related.
I am quite aware of that.
Apparently it wasn't clear that, knowing that JavaScript strings are compatible with Java Strings, I was trying to determine the C++ equivalent of a Java String.
-
Feb 28th, 2004, 10:41 AM
#8
I'm not so sure about that. Are JavaScript strings actually required by the ECMAScript standard to be of a particular form? JavaScript has a weird object model, I'm not sure if it's compatible with anything.
Anyway, Java strings are 16-bit UNICODE strings, I don't know if they're 0-terminated or where they store their length. The JNI functions do some sort of conversion.
BSTR, the ActiveX string type, is 16-bit UNICODE characters too, 0-terminated and with a 2-byte length just before the first character, but with the pointer (that BSTR is a typedef for) pointing not to the beginnning of the object (the length) but to the first character, thus the length has a negative offset!
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Feb 28th, 2004, 05:12 PM
#9
Frenzied Member
Since JavaScript variables are not typed, I'm guessing that they are all varients. And since I am able to pass string variables from my JavaScript routines to methods in my Java applets, it would appear that Java has no promlem converting them while the same cannot be said for C++. Does C++ have a varient data type?
-
Feb 28th, 2004, 05:14 PM
#10
Variants, well...
C++ has of course no native variant datatype. There's a lot of management to a variant, nothing that would belong into C++.
But of course there's VARIANT, from the WinAPI. It's the underlying implementation of the ActiveX and VB variant type.
A question about the error, when does it occur? No, wait, that's described.
Try the variant type. It might work.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Mar 1st, 2005, 09:29 AM
#11
New Member
Re: JavaScript/C++: Passing a JavaScript String to C++ ActiveX Control
Making the variable a LPCTSTR type will work. I have done that.
I have a problem of passing in an array of strings. I have made the parameter a BSTR, VARIANT FAR*. Can anybody help?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|