COM interop

C

C# beginner

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.
 
W

Willy Denoyette [MVP]

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

C# beginner

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.
 
W

Willy Denoyette [MVP]

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.
 
G

Guest

Thanks Willy. I think I got it to work. My understanding
is the project references were messed up. Thanks a lot for
your help.
-----Original Message-----
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.

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. wrote
in message placed
it component
as


.
 

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