Re: COM interop

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Willy Denoyette [MVP] (willy.denoyette_at_pandora.be)
Date: 03/01/04


Date: Mon, 1 Mar 2004 20:48:47 +0100

What error do you get when calling Set o = CreateObject(....)
What attributes did you set on your methods, remember vbscript can only call
methods on objects implementing IDispatch (and dual) interfaces.

Here's a small sample that illustrates the attribute usage...

using System.Runtime.InteropServices;
using System;

// interface definition, dual to be script friendly
[InterfaceType(ComInterfaceType.InterfaceIsDual)]
[Guid("D3DF5658-3D3F-436b-B6A6-F10E77AE3F5F")] // Use guidgen to obtain
valid GUID's
public interface IDotNetInterface
{
    int someMethod();
}

// class
[ClassInterface(ClassInterfaceType.None)]
[ProgId("Test.DotNetInterface")] // progid
public class DotNetInterface : IDotNetInterface
{
   public int someMethod()
   {
// Implemetation of someMethod, returning an int
    return 0;
   }
}
Check MSDN for details on InterfaceType and ClassInterface attributes.

The VBScript Client...

Set o = CreateObject("Test.DotNetInterface")
Dim var, ret
ret = o.someMethod()
WScript.Echo ret

Willy.

"C# beginner" <anonymous@discussions.microsoft.com> wrote in message
news:524501c3ffc1$030cd710$a101280a@phx.gbl...
> Thanks Willy. As I mentioned in my previous posting, I
> have registered my C# component using regasm and generated
> a tlb file. Per your suggestion, I tried using
> the /codebase option also. still doesn't work. Any help is
> appreciated.
>>-----Original Message-----
>>Placing your assembly in the GAC won't help a COM client
> to find the
>>assembly, COM has no idea what the GAC is.
>>What you should do instead is to register your assembly
> using the Codebase
>>option of regasm.
>>
>>Willy.
>>
>>"C# beginner" <anonymous@discussions.microsoft.com> wrote
> in message
>>news:4c0f01c3ffb8$7c812690$a301280a@phx.gbl...
>>> Hi all
>>> I am trying to call my C# class library from COM. My C#
>>> library works perfectly in the .NET environment. I have
>>> registered my C# component using regasm and also placed
> it
>>> in the GAC. But for some reason my VBScript COM
> component
>>> can't interop with .NET. I am calling my .NET component
> as
>>> follows.
>>>
>>> Set GSF = CreateObject("CSAppName.ClassName")
>>>
>>> Can you please tell me what I am missing? Thanks a lot
> for
>>> your help.
>>
>>
>>.
>>



Relevant Pages

  • Marshaler bug with VBScript arrays
    ... Interop marshaler won't pass VBScript arrays to my interface by reference. ... In the C++ code, I dereference it manually to get to the array, and I use ... MarshalAs(UnmanagedType.CustomMarshaler) attribute with a custom ...
    (microsoft.public.dotnet.framework.interop)
  • [PATCH 5/5] AFS: Adjust the new netdevice scanning code
    ... Rather than using an array size of 6 in some places and an array size of ... if (ret < 0) ... int ret = -ENODEV; ... * get a list of this system's interface IPv4 addresses, ...
    (Linux-Kernel)
  • Re: parsing a tree like structure
    ... I'm wondering if there is a nice way to parse this data, ... push @ret, ... SCSI Interface: ... Scsi Stats: ...
    (perl.beginners)
  • JScript and DLLs/Server Side Objects
    ... JScript and the object appears to present a broken interface to me...there ... I decided to rewrite one page in VBScript and see ... Is this an issue between JScript and VBScript, or is it possible that my 3rd ...
    (microsoft.public.inetserver.asp.general)
  • Re: HEADSUP: arp-v2 has been committed
    ... ret = setsockopt(sock, IPPROTO_IP, optname, ... the interface which has the default route. ... mreqn.imr_ifindex = ifindex; ...
    (freebsd-current)