3

Hi Classic ASP Experts,

Basically, I am new to Classic ASP and VBScript, and got this "VBScript runtime error: Invalid procedure call or argument", while trying to pass an argument of complex type to the COM method (vide screenshot below). While the server object is getting created and the string passed to the COM method, any attempt to pass an argument of complex type goes in vain.

Please help.

Here's the Code Snippet:

VBScript (server-side) on ClassicASPHome.asp page:

<%
response.write("My first ASP script!")  

set co = Server.CreateObject("ClassicASPCOM.ComplexObject")

co.Message = "Messi"
co.Number = 100


Dim ccom
Set ccom = Server.CreateObject("ClassicASPCOM.ClassCOM")


response.Write(ccom.GetMessage("1234567890"))

'---------------Works fine till here

Dim ret

' ---------------The following statement throws error

ret = ccom.PaymentDetails(co)

response.Write("Fine")

Code Snippet (C#):

// C# Code (ClassicASPCOM.dll) built with Strong Name and Registered for COM Interop:

// Executed the following in Visual Studio Command Prompt in bin\Release folder
// Regasm ClassicASPCOM.dll

// Regasm ClassicASPCOM.dll /codebase

// Regasm ClassicASPCOM.dll /tlb

// gacutil/i ClassicASPCOM.dll

using System;
using System.Runtime.InteropServices;

namespace ClassicASPCOM
{
    [ComVisibleAttribute(true)]
    [Guid("D355BC25-B85F-4476-8D38-582F92F7B6F4")]
    public interface IComplexObject
    {
        [DispId(2221)]
        int Number {get; set;}
        [DispId(2222)]
        string Message { get; set; }
        [DispId(2223)]
        DateTime Dtime { get; set; }
    }

    [ComVisibleAttribute(true)]
    [Guid("4E602191-8D09-458E-A0D0-A0A267696F78"),
    ClassInterface(ClassInterfaceType.None)]
    public class ComplexObject : IComplexObject
    {
        int Nmbr;
        public int Number
        {
            get
            {
                return Nmbr;
            }
            set
            {
                Nmbr = value;
            }
        }

        string Msg;
        public string Message
        {
            get
            {
                return Msg;
            }
            set
            {
                Msg = value;
            }
        }

        DateTime Dt;
        public DateTime Dtime
        {
            get
            {
                return Dt;
            }
            set
            {
                Dt = value;
            }
        }
    }

    [ComVisibleAttribute(true)]
    [Guid("4042FE79-8ACA-4E5D-9F14-2FF7C6AE8D88")]
    public interface IGetMessage
    {
        [DispId(2224)]
        string GetMessage(string Message);
        [DispId(2225)]
        string PaymentDetails(ComplexObject cObject);
    }

    [ComVisibleAttribute(true)]
    [Guid("9A133858-5893-4CA7-9048-345CD0FCF535"),
    ClassInterface(ClassInterfaceType.None)]
    public class ClassCOM : IGetMessage
    {
        public string GetMessage(string Message)
        {
            return "Your Message: " + Message;
        }

        public string PaymentDetails(ComplexObject cObject)
        {
            return " Message: " + cObject.Message + " Number: " + cObject.Number;
        }
    }  
}

enter image description here

Thanks

4
  • 1
    Out of curiosity, why are you using .NET components from ASP3. Why not use ASP.NET directly, or is this a masochistic learning exercise? (in which case I'd recommend authoring COM components in C or C++ to avoid the problems with CLR marshaling). Commented Mar 27, 2013 at 15:00
  • Where does the barcome from? Commented Mar 27, 2013 at 17:18
  • Does it strike you as odd that ComplexObject does not implement IComplexObject? One imagines that you intended IComplexObject to be ComplexObject's dispinterface. Commented Mar 27, 2013 at 17:53
  • "ret = foo.PaymentDetails("co")" "bar" - typo - hence removed "public class ComplexObject" - typo - should read as - "public class ComplexObject : IComplexObject" Commented Mar 30, 2013 at 8:27

2 Answers 2

1

[I'm getting an error when] trying to pass an argument of type class to the COM method call.

You are not passing an argument of type class to the COM method call. You're passing the string "co", not the object reference stored in variable co.

Sign up to request clarification or add additional context in comments.

2 Comments

"ret = foo.PaymentDetails("co")" "bar" - typo - hence removed "public class ComplexObject" - typo - should read as - "public class ComplexObject : IComplexObject"
So in his case, how would you pass the object 'co' rather than the string "co"?
0

Besides the answer of Eric Lippert, I'm wondered why you have the comment "Works fine till here" because of this part:

set co = Server.CreateObject("ClassicASPCOM.ComplexObject") ' <- variable co is now an object
co = ""                ' <- variable co is now a string with value ""
co.Message = "Messi"   ' <- You should get an "Object required" error on this line
co.Number = 100

1 Comment

"ret = foo.PaymentDetails("co")" "bar" - typo - hence removed "public class ComplexObject" - typo - should read as - "public class ComplexObject : IComplexObject"

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.