473,382 Members | 1,332 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

consuming managed C# DLL from unmanaged VB6

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
5 2390
"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
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
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
"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Bob Rock | last post by:
Hello, in the last few days I've made my first few attempts at creating mixed C++ managed-unmanaged assemblies and looking aftwerwards with ILDASM at what is visible in those assemblies from a...
1
by: Eric Twietmeyer | last post by:
Hello, I'm starting to investigate cs, managed c++ and interoperating with a very large unmanaged code base. We are going to use Windows Forms (written in cs) to replace our old fashioned GUI. ...
5
by: Chris Kiechel | last post by:
I am writing a .NET Windows application and it needs to perform DDE calls to a legacy system. I created a C++ unmanaged class that performs the actual DDE connection and communication. However,...
3
by: zhphust | last post by:
I want to convert a object of a managed class to a unmanaged structure that has the same member with that managed class. Can anybody tell me how i can do it? Thanks in advance. -- zhphust...
3
by: Thorsten | last post by:
HI I'm a C# developer and unfortunately I have to write now some code in managed and unmanaged C++. In this area I'm Newbie and therefore please forgive me if this is a really simple...
1
by: Matyi | last post by:
Hello everybody! I've this problem: I'm working on a download meter, based on wpcap. As wpcap code is unmanaged, I decided to create the needed functions in a unmanaged project (one for...
9
by: Amit Dedhia | last post by:
Hi All I have a VC++ 2005 MFC application with all classes defined as unmanaged classes. I want to write my application data in xml format. Since ADO.NET has buit in functions available for...
7
by: Tremendo | last post by:
Hi, I need to consume an unmanaged DLL from managed C#. The DLL is "ae766.dll". I have problems with one function in it. Who developed the DLL, provided the following information, regarding that...
25
by: Koliber (js) | last post by:
sorry for my not perfect english i am really f&*ckin angry in this common pattern about dispose: ////////////////////////////////////////////////////////// Public class...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.