HOWTO: Add methods to C++ UserControl.

G

Guest

HOWTO: Add methods to C++ UserControl.

Please help,

I want to add a method to a C++ .NET UserControl that is based off the
sample in the MSND article titled:

How to automate Internet Explorer in a contained UserControl control by
using Visual C++ .NET 2003

This article shows how to make and deploy, and run a C++ UserControl. But I
do not know how to use Visual Studio to add a method to the sample, so that
script in an HTML files that uses the UserControl can call the method.
Example:

<html>
<OBJECT id="theId" classid="YourControl.dll#NameSpace.NameOfControl">
</OBJECT>
<script>
var csRET = theId.RunMyMethod("Hello", "World");
alert("The RET is '" + csRET + "'...");
</script>
</html>
 
G

Guest

I have more information on this subject.

I can easily add properties and get the HTML script to set/get the
properties. But I can not get the script to invoke a function/method. For
example, I added to that sample these lines:

String *csOptions;

__property String *get_Options()
{
return csOptions;
}
__property void set_Options(String *csOptions_)
{
csOptions = csOptions_;
}

int RunI()
{
return 66;
}


Then to that HTML I sent, I added this to the script:

<script language=javascript>
var objTest;
objTest = document.getElementById("objTest");
alert("CHK #001");
objTest.Options = "Hello!";
alert("objTest.Options = '" + objTest.Options + "'..."); // This works!!!
And it says "Hello!".
alert("objTest.RunI = '" + objTest.RunI() + "'..."); // This bombs, and
says object does not have this method?!?!?!?
</script>

What does the RunI function need for the script to be able to call it?
 
G

Guest

I have more info on this issue. I'm DEAD in the water until some one gives me
the answer.

There is either something that has to be added to the C++ managed code to
make it expose methods, and/or something has to be done in the HTML script to
make it find/resolve the interface to the method.

The method is fine. Other .NET apps can find the method and call it, as well
as properties. But the HTML script can only get the properties, and always
comes back with an error saying method or object does not exists.

By the way, I'm using VC++ 2003.
 
G

Guest

More info,

That sample I made with the property is not working after all. Infactm the
property to the calss is not being called at all, instead, the browser is
creating an HTML attribute onto the OBJECT's elements. So, not only do I not
know how to call a method, but I also do not know how to get/set a method.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top