Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to invoke a static member of a COM class in VBScript

555 views
Skip to first unread message

Mark Stasak

unread,
Aug 20, 2003, 5:52:12 PM8/20/03
to
Suppose I have a .Net class with a callable COM wrapper. The class has a
shared (static) member function. I try to invoke it like an instance
method, but get a method not found error. Is there any way to invoke a
shared method?

In VB.Net:
Namespace CryptoToolkit
Public NotInheritable Class Ticket
Inherits System.Object
Public Shared Function getUserId(ByVal ticket As String) As String

In VBScript:
dim obj
obj=Server.CreateObject("CryptoToolkit.Ticket")
dim userid
userid=obj.getUserId("sometext")

-> error: Object doesn't support this property or method - Microsoft
VBScript runtime error


Alex K. Angelopoulos [MVP]

unread,
Aug 22, 2003, 9:36:51 AM8/22/03
to
IIRC, you can't call a shared member from script. You may want to create a
truly public function that "wraps" the shared function.

There are a couple of other issues in special cases, but this is probably
the cause of your problem.

Mark Stasak

unread,
Aug 22, 2003, 10:19:18 AM8/22/03
to
Thanks, I'm trying that and getting no properties or methods visible in my
wrapper class.

I'll probably get there eventually - going to the school of hard knocks for
.Net COM Interop with a weakly named assembly deployed to the directory of
the app. I'm fairly sure I'm headed in the right direction, though - just
need all my project settings and ComVisible attributes set up right. If all
else fails, I'll try strongly naming the class. But that's all a .Net
issue, not VbScript-related in any particular way...

"Alex K. Angelopoulos [MVP]" <aka-at-mvps-dot-org> wrote in message
news:eLf1yJLa...@TK2MSFTNGP12.phx.gbl...

Alex K. Angelopoulos [MVP]

unread,
Aug 22, 2003, 1:53:00 PM8/22/03
to
Mark Stasak wrote:
> Thanks, I'm trying that and getting no properties or methods visible
> in my wrapper class.
>
> I'll probably get there eventually - going to the school of hard
> knocks for .Net COM Interop with a weakly named assembly deployed to
> the directory of the app. I'm fairly sure I'm headed in the right
> direction, though - just need all my project settings and ComVisible
> attributes set up right. If all else fails, I'll try strongly naming
> the class. But that's all a .Net issue, not VbScript-related in any
> particular way...

I gave up on the "visible" attributes since it's so blinking hard to do
right all the time. And function overloading in C# is just not worth it
either...

Mark Stasak

unread,
Aug 27, 2003, 4:14:08 PM8/27/03
to
(for Alex and posterity)

Eventual success. There seems to be a lot which can go wrong, and I spent
more time looking at OLE Viewer and Regedit than I care to. The route which
eventually worked was:

Make a wrapper which exposes the static method as an instance method. In
the wrapper project, use an explicit interface for the wrapper class. Use
explicit GUIDs for the interface and class. Specify a class interface type
of None. Specify comVisible(True)] for members. Compile class to a DLL and
deploy to target machine. Run "REGASM x.DLL /TLB /CODEBASE". Then access
the class from .asp vbscript using conventional
myObj=Server.CreateObject("namespace.classname") techniques.

I never backtracked to see which steps were unnecessary.

Lessons learned:

Before updating the DLL, unregister the old one with "REGASM x.DLL /TLB
/CODEBASE /U" - the tlb and codebase options help regasm to remove more
registry associations. To be sure, Run OLE/COM Object Viewer and check "All
Objects" and "Type Libraries" to make sure you don't acquire lots of
duplicate type libraries - regasm seems to make duplicate typelibs without
end. Ignore the strong names warnings from regasm /codebase - these are
significant if the component will be shared by other apps, but I could not
make .asp pages find the object without this - apparently the "application
folder" is not particularly well defined in IIS/VBScript, or at least it is
not the location of the .asp page (not sure if I tried a /bin subfolder).

using System;
using System.Runtime.InteropServices;

namespace clientticketssowrapper
{
[Guid("1664245D-758F-319B-8D43-CE855A558102")]
[ComVisible(true)]
public interface TicketWrapperInterface {
string getUserId(string ticket);
}

//[System.Runtime.InteropServices.ComVisible(true)]
[Guid("1664245D-758F-319B-8D43-CE855A558103")]
[ClassInterface(ClassInterfaceType.None)]
public class TicketWrapper : TicketWrapperInterface {
public TicketWrapper() {
}

[ComVisible(true)]
public string getUserId(string ticket) {
return CryptoToolkit.Ticket.getUserId(ticket);
}
}
}


"Alex K. Angelopoulos [MVP]" <aka-at-mvps-dot-org> wrote in message

news:uD3q7YN...@tk2msftngp13.phx.gbl...

0 new messages