0

In my classic ASP site I need to call COM object function.

Here is the COM component definition:

interface IMyComponent : IDispatch
{ 
   HRESULT GetVersion([in] int, [out] double*, [out] BSTR*);
}

In server side I create component object and try to call 'GetVersion' function:

<%
    Dim app
    Set app = CreateObject("MyComponent")

    Dim someUsefulValue
    Dim version

    app.GetVersion 1, someUsefulValue, version
%>

But this code fails with error "Type mismatch". How I should call this function?

4
  • Can you explain what you are trying to achieve by this? I guess this is an in-browser app, so this seems very strange. I"d also be interested in knowing where you read about "JScript" :) Commented Jul 6, 2011 at 8:20
  • @jrharshath, I think he's talking about consuming COM objects from classic ASP, which leaves you either VBScript or JScript as your choices for language. Commented Jul 6, 2011 at 8:23
  • @DuckMaestro, yes, you're right. Commented Jul 6, 2011 at 8:33
  • @Duck oh. owhhhhhhhhh... In that case, let me say upfront that it does not matter whether you're using ASP or not - what you are trying to do is access COM components on the client side, which immediately limits you to using on IE as the working browser. If that is acceptable to you, then feel free to continue on this treacherous path, but tread carefully :) Commented Jul 6, 2011 at 9:26

3 Answers 3

1

first of all, keep in mind that no other browser supports ActiveX rather than Internet Explorer, so I would re-think if you shouldn't get other approach to the problem, maybe using other component that is more open to other browsers...

like Microsoft Silverlight (if you are going the .NET way), Adobe Flash, Shockwave, Air...

in HTML

Your ASP page needs to have the <object> code of your ActiveX

<OBJECT ID="myActiveX "
    CLASSID="clsid: yourControlId">
</OBJECT>

then you just act as a normal DOM object

var myActiveX = document.getElementById("myObject");
alert( myActiveX.GetVersion(...) );
Sign up to request clarification or add additional context in comments.

3 Comments

he is talking about ASP.. it is server-side..
I think he's talking about "JScript" -> definitely client-side.
I'm talking about serverside. @jrharshath, JScript can be used as server-side ASP language.
0

Change the type of first parameter of the COM method to long, rather than int. Long translates to the variant type VT_I4, while int translates to VT_INT. If memory serves me right, VBScript doesn't recognize VT_INT as it's not an "automation compatible type" (the size of int may not be fixed across compilers/platforms!)

Comments

0

Try:

<%
    Dim app
    Set app = Server.CreateObject("MyComponent")

    Dim someUsefulValue
    Dim version

    app.GetVersion 1, someUsefulValue, version
%>

On the server side you should use Server.CreateObject, not just CreateObject as it is normally used for client side VBScript.

Make sure the COM object has been installed and registered using regsvr32 MyComponent.dll

2 Comments

-1, CreateObject works, though Server.CreateObject is preferred.
@Cheran rephrased answer to say should instead of need

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.