By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,160 Members | 1,323 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,160 IT Pros & Developers. It's quick & easy.

consuming managed C# DLL from unmanaged VB6

P: n/a
Hi,

I created a DLL using managed C# and this DLL needs to be consumed by two
applications:
- One is written in managed C#, and will
run on a PC that does have the .NET framework installed (no problems regarding this one).
- The other one is written in unmanaged Visual Basic 6, and will run on a PC that does NOT have the
..NET framework installed (my problems start here).

I wonder..
1) Is it required to install the .NET framework on the second PC, to consume
that DLL?
2) If the answer to 1) is yes, is there a way to create the DLL (or another version of the DLL), so
that I don't need to install the .NET framework on the second PC?
3) How do I have to export, in the DLL, the following managed C# function,
so that it can be consumed by the unmanaged VB6 application?

public bool Function(int i, double d,out string s)
Thank you very much.
Jan 25 '07 #1
Share this Question
Share on Google+
5 Replies


P: n/a
"Tremendo" <no****@hatespam.comwrote in message
news:f9********************************@4ax.com...
Hi,

I created a DLL using managed C# and this DLL needs to be consumed by two
applications:
- One is written in managed C#, and will
run on a PC that does have the .NET framework installed (no problems regarding this one).
- The other one is written in unmanaged Visual Basic 6, and will run on a PC that does NOT
have the
.NET framework installed (my problems start here).

I wonder..
1) Is it required to install the .NET framework on the second PC, to consume
that DLL?
Yes. You can't run C# (or any other managed language) code without the framework installed.
2) If the answer to 1) is yes, is there a way to create the DLL (or another version of the
DLL), so
that I don't need to install the .NET framework on the second PC?
No, unless you want to implement the DLL in unmanaged code.

3) How do I have to export, in the DLL, the following managed C# function,
so that it can be consumed by the unmanaged VB6 application?

public bool Function(int i, double d,out string s)
You don't have to export anything, you simply have to annotate the method so that it becomes
COM visible.
Please consult the MSDN docs, start with "Introduction to COM Interop" for details on how to
design/implement your classes to be used as COM server.

Willy.

Jan 25 '07 #2

P: n/a
Take a look at the following site, I did call a C# DLL function from
PowerBuilder and gets a return value from the C# DLL.

http://www.codeproject.com/dotnet/ne...97#xx1254697xx
"Tremendo" <no****@hatespam.com>
???????:f9********************************@4ax.com ...
Hi,

I created a DLL using managed C# and this DLL needs to be consumed by two
applications:
- One is written in managed C#, and will
run on a PC that does have the .NET framework installed (no problems
regarding this one).
- The other one is written in unmanaged Visual Basic 6, and will run on a PC
that does NOT have the
..NET framework installed (my problems start here).

I wonder..
1) Is it required to install the .NET framework on the second PC, to consume
that DLL?
2) If the answer to 1) is yes, is there a way to create the DLL (or another
version of the DLL), so
that I don't need to install the .NET framework on the second PC?
3) How do I have to export, in the DLL, the following managed C# function,
so that it can be consumed by the unmanaged VB6 application?

public bool Function(int i, double d,out string s)
Thank you very much.
Jan 25 '07 #3

P: n/a
On Thu, 25 Jan 2007 09:37:10 +0100, "Willy Denoyette [MVP]" <wi*************@telenet.bewrote:
>"Tremendo" <no****@hatespam.comwrote in message
news:f9********************************@4ax.com.. .
>Hi,

I created a DLL using managed C# and this DLL needs to be consumed by two
applications:
- One is written in managed C#, and will
run on a PC that does have the .NET framework installed (no problems regarding this one).
- The other one is written in unmanaged Visual Basic 6, and will run on a PC that does NOT
have the
.NET framework installed (my problems start here).

I wonder..
1) Is it required to install the .NET framework on the second PC, to consume
that DLL?

Yes. You can't run C# (or any other managed language) code without the framework installed.
Ok. If I install the .NET framework on the second PC, will I be able to call that managed DLL from
unmanaged VB6 or I need to change the VB itself?

IOW, installing the .NET framework seems to be necessary. Is it also sufficient?
Thank you again.
Jan 25 '07 #4

P: n/a
"Tremendo" <no****@hatespam.comschrieb im Newsbeitrag
news:r0********************************@4ax.com...
On Thu, 25 Jan 2007 09:37:10 +0100, "Willy Denoyette [MVP]"
<wi*************@telenet.bewrote:
>>"Tremendo" <no****@hatespam.comwrote in message
news:f9********************************@4ax.com. ..
>>Hi,

I created a DLL using managed C# and this DLL needs to be consumed by
two
applications:
- One is written in managed C#, and will
run on a PC that does have the .NET framework installed (no problems
regarding this one).
- The other one is written in unmanaged Visual Basic 6, and will run on
a PC that does NOT
have the
.NET framework installed (my problems start here).

I wonder..
1) Is it required to install the .NET framework on the second PC, to
consume
that DLL?

Yes. You can't run C# (or any other managed language) code without the
framework installed.

Ok. If I install the .NET framework on the second PC, will I be able to
call that managed DLL from
unmanaged VB6 or I need to change the VB itself?

IOW, installing the .NET framework seems to be necessary. Is it also
sufficient?
you can export the .NET classes as COM objects. Look in the docs for COM
interop.
>

Thank you again.

Jan 25 '07 #5

P: n/a
Hi,

Thanks to all of you for your directions. I read some documents about
COM interop, and I think I'm closer now to knowing what should I do.
From what I've understood, these are the steps I should follow:
[I'm using Visual Studio 2005 on the first PC.]

1) The managed class I want to expose should have attributes like the
ones shown in the code below.
2) The managed DLL should be built with the option "Make assembly
COM-visible". That creates xx.dll and xx.pdb. Forget about xx.pdb.
3) Run "tlbexp xx.dll". This creates xx.tlb.
4) Run "regasm xx.dll /regfile". This creates xx.reg.
5) Copy the files xx.dll, xx.tlb and xx.reg to the second PC (the one
with unmanaged VisualBasic 6).
6) Install the .NET framework 2.0 on the second PC.
7) Execute xx.reg on the second PC (to add entries to its registry).
8) With the IDE of VB6, add a reference to the COM object named "xx",
and consume it as needed.

Some questions I have:

a) Are the steps more or less right?
b) Which is a good directory in the second PC to copy to and keep the
files xx.dll and xx.tlb? (the xx.reg won't be needed after being
executed).
c) The registry entries know where the xx.tlb is, and the xx.tlb knows
where the xx.dll is. Is this right?
d) Can I choose GUIDs at random? (I've seen that VS2005 includes a
tool to generate them in several formats).
Again, thank you for your time.
Tremendo.
----------------------------------------------

#region Using directives

using System;
using System.Text;
using System.Runtime.InteropServices;

#endregion

namespace N_Test
{
[GuidAttribute("C8660246-1962-4efd-9DAE-D3DC7533EA8E")]

[InterfaceTypeAttribute(ComInterfaceType.InterfaceI sIDispatch)]
public interface _C_Test
{
[DispIdAttribute(1)]
int TestAdd(int a,int b);
}

[GuidAttribute("8D43EC40-BA2D-4f0e-AD9D-3756030BF59A")]
[ClassInterfaceAttribute(ClassInterfaceType.None)]
[ProgIdAttribute("N_Test.C_Test")]
public class C_Test : _C_Test
{
public int
result;
public C_Test()
{
result=2;
}

public int TestAdd(int a,int b)
{
result=a+b;
return(result);
}
} // C_Test
} // N_Test

Jan 28 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.