471,119 Members | 1,502 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,119 software developers and data experts.

Using a C# Class Library .dll in VB 6

Hello all,
I've wrote a .dll in c#. The .dll needs to be used by a VB 6
application. At first, I couldn't set a reference from the VB app, but then
I found the register for COM Interop in the build configuration in the
VS.net IDE. The VB 6 IDE now lists my class library as a reference. But
there are still a few issues. I can set a variable/object to the class.
i.e.:

Dim o As MyC#Namespace.MyC#Class (Note that the namespace/class doesn't have
C# in it)

When I try to access a public method, the VB6 Intellisence doesn't pull up
the list of Methods/Properties that are available with the Class Library.
Example:

variant foo = o.MyMethod <-- (No intellisence after o.)

The structure of my class library is as such:

namespace MyC#Namespace {

public class MyC#Class
{
public string MyMethod {
return "test";
}
}
}

Any suggestions are appreciated.

--
Jay Douglas
Fort Collins, CO


Nov 15 '05 #1
3 2002
Hi!

Set the ComVisible attribute for the methods in question, or to have all the
methods become available to COM clients, set it for the class.

--

Regards,
Gaurav Khanna
----------------------------------------------------------------------------
----------------
Microsoft MVP - .NET, MCSE Windows 2000/NT4, MCP+I
WinToolZone - Spelunking Microsoft Technologies
http://www.wintoolzone.com/
"Jay Douglas" <ja*************@squarei.com> wrote in message
news:#e**************@TK2MSFTNGP10.phx.gbl...
Hello all,
I've wrote a .dll in c#. The .dll needs to be used by a VB 6
application. At first, I couldn't set a reference from the VB app, but then I found the register for COM Interop in the build configuration in the
VS.net IDE. The VB 6 IDE now lists my class library as a reference. But
there are still a few issues. I can set a variable/object to the class.
i.e.:

Dim o As MyC#Namespace.MyC#Class (Note that the namespace/class doesn't have C# in it)

When I try to access a public method, the VB6 Intellisence doesn't pull up the list of Methods/Properties that are available with the Class Library.
Example:

variant foo = o.MyMethod <-- (No intellisence after o.)

The structure of my class library is as such:

namespace MyC#Namespace {

public class MyC#Class
{
public string MyMethod {
return "test";
}
}
}

Any suggestions are appreciated.

--
Jay Douglas
Fort Collins, CO

Nov 15 '05 #2
Hi!

Assumed that ComVisible was false. Also using AutoDual isn't advised
primarily because of versioning issues.

--

Regards,
Gaurav Khanna
----------------------------------------------------------------------------
----------------
Microsoft MVP - .NET, MCSE Windows 2000/NT4, MCP+I
WinToolZone - Spelunking Microsoft Technologies
http://www.wintoolzone.com/
"Nicholas Paldino [.NET/C# MVP]" <ni**************@exisconsulting.com> wrote
in message news:#$**************@TK2MSFTNGP12.phx.gbl...
Kumar,

All types in an assembly are accessible to COM by default.

The reason why the original poster is not seeing his methods is because the ClassInterface attribute is not being applied. It should be applied to his types, constructed with the value ClassInterfaceType.AutoDual. By
default, it is AutoDispatch (or considered that without the attribute), so
he could probably get to his methods, but through late binding.

To the original poster, it should be noted that this is a bad way to
expose your classes to COM. COM is an interface-based framework, and is
different from .NET in that .NET is class-based. Check out the section of
the .NET framework titled "Interoperating with Unmanaged Code", located at
(watch for line wrap):

http://msdn.microsoft.com/library/de...anagedcode.asp
In particular, check out the section titled "Exposing .NET Framework
Components to COM".

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- ni**************@exisconsulting.com

"Kumar Gaurav Khanna [.NET MVP]" <ga****@wintoolzone.com> wrote in message
news:us**************@TK2MSFTNGP10.phx.gbl...
Hi!

Set the ComVisible attribute for the methods in question, or to have all

the
methods become available to COM clients, set it for the class.

--

Regards,
Gaurav Khanna


--------------------------------------------------------------------------
--
----------------
Microsoft MVP - .NET, MCSE Windows 2000/NT4, MCP+I
WinToolZone - Spelunking Microsoft Technologies
http://www.wintoolzone.com/
"Jay Douglas" <ja*************@squarei.com> wrote in message
news:#e**************@TK2MSFTNGP10.phx.gbl...
Hello all,
I've wrote a .dll in c#. The .dll needs to be used by a VB 6
application. At first, I couldn't set a reference from the VB app, but
then
I found the register for COM Interop in the build configuration in the
VS.net IDE. The VB 6 IDE now lists my class library as a reference. But there are still a few issues. I can set a variable/object to the
class. i.e.:

Dim o As MyC#Namespace.MyC#Class (Note that the namespace/class
doesn't have
C# in it)

When I try to access a public method, the VB6 Intellisence doesn't
pull up
the list of Methods/Properties that are available with the Class

Library. Example:

variant foo = o.MyMethod <-- (No intellisence after o.)

The structure of my class library is as such:

namespace MyC#Namespace {

public class MyC#Class
{
public string MyMethod {
return "test";
}
}
}

Any suggestions are appreciated.

--
Jay Douglas
Fort Collins, CO



Nov 15 '05 #3
Okay, this is what I've figured out. Intellsence works in VB and everything
seems to be working just fine. Tell me what you think.

using System;
using System.Runtime.InteropServices;

namespace Squarei
{
//DEFINE THE PUBLIC INTERFACE FOR THE COM OBJECT
public interface IComInteropTest
{
void SetHTML(string strHtml);
string GetHTML();
}
//IMPLEMENT THE CLASS BELOW USING THE PUBLIC INTERFACE DEFINED ABOVE
[ClassInterface(ClassInterfaceType.None)]
public class ComInteropTest : IComInteropTest
{

public string strUrl = string.Empty;
public string strHtml = string.Empty;

public void SetHTML(string strHtml)
{
this.strHtml = strHtml;
}

public string GetHTML()
{
return strHtml;
}
}
}

--
Jay Douglas
Fort Collins, CO

"Jay Douglas" <ja*************@squarei.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Hello all,
I've wrote a .dll in c#. The .dll needs to be used by a VB 6
application. At first, I couldn't set a reference from the VB app, but then I found the register for COM Interop in the build configuration in the
VS.net IDE. The VB 6 IDE now lists my class library as a reference. But
there are still a few issues. I can set a variable/object to the class.
i.e.:

Dim o As MyC#Namespace.MyC#Class (Note that the namespace/class doesn't have C# in it)

When I try to access a public method, the VB6 Intellisence doesn't pull up the list of Methods/Properties that are available with the Class Library.
Example:

variant foo = o.MyMethod <-- (No intellisence after o.)

The structure of my class library is as such:

namespace MyC#Namespace {

public class MyC#Class
{
public string MyMethod {
return "test";
}
}
}

Any suggestions are appreciated.

--
Jay Douglas
Fort Collins, CO

Nov 15 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Reed | last post: by
14 posts views Thread by Tony Johansson | last post: by
5 posts views Thread by Marcel Gelijk | last post: by
7 posts views Thread by fakeprogress | last post: by
83 posts views Thread by liketofindoutwhy | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.