473,386 Members | 1,757 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,386 software developers and data experts.

DLLs in C#, legacy code concerns

OK, I just want to make sure I am correct in the following statements, and
then to get some advice as to how I should proceed.

First, is it accurate to say that in order for C# to use a DLL, the classes
and members exposed must utilize a COM interface?

I tried adding a refernce to a DLL that was just created (in C++ to cross
compile between Microsoft Visual C++ 6.0 and Borland C++ Builder 5, providing
messaging functionality through ACE) to solve a communications problem
between Borland and Microsoft compilers, only to have Visual Studio .NET 2003
(version 7.1 I believe) tell me that I cannot add the DLL file because it is
neither a valid assembly, nor a COM object.

Is is possible to use this DLL in Visual Studio .NET 2003 if I write my user
interface and export routines in C++ instead of C#?

How would you suggest I gain access to the messaging functionality located
in this DLL for my application?

Thanks in advance for all the help,

Andrew S. Giles
Nov 16 '05 #1
6 3358
Andrew,

Basically, if you want to interop with unmanaged code, you have two
choices. The first would be to expose it through a COM object, the second
is to export functions from a DLL. You could also create a managed wrapper
in C++ if you wish, and then set your reference to that.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Andrew S. Giles" <An**********@discussions.microsoft.com> wrote in message
news:CE**********************************@microsof t.com...
OK, I just want to make sure I am correct in the following statements, and
then to get some advice as to how I should proceed.

First, is it accurate to say that in order for C# to use a DLL, the
classes
and members exposed must utilize a COM interface?

I tried adding a refernce to a DLL that was just created (in C++ to cross
compile between Microsoft Visual C++ 6.0 and Borland C++ Builder 5,
providing
messaging functionality through ACE) to solve a communications problem
between Borland and Microsoft compilers, only to have Visual Studio .NET
2003
(version 7.1 I believe) tell me that I cannot add the DLL file because it
is
neither a valid assembly, nor a COM object.

Is is possible to use this DLL in Visual Studio .NET 2003 if I write my
user
interface and export routines in C++ instead of C#?

How would you suggest I gain access to the messaging functionality located
in this DLL for my application?

Thanks in advance for all the help,

Andrew S. Giles

Nov 16 '05 #2
You can access non COM dlls lookup extern keyword and DllImport attribute.
BenW

"Andrew S. Giles" wrote:
OK, I just want to make sure I am correct in the following statements, and
then to get some advice as to how I should proceed.

First, is it accurate to say that in order for C# to use a DLL, the classes
and members exposed must utilize a COM interface?

I tried adding a refernce to a DLL that was just created (in C++ to cross
compile between Microsoft Visual C++ 6.0 and Borland C++ Builder 5, providing
messaging functionality through ACE) to solve a communications problem
between Borland and Microsoft compilers, only to have Visual Studio .NET 2003
(version 7.1 I believe) tell me that I cannot add the DLL file because it is
neither a valid assembly, nor a COM object.

Is is possible to use this DLL in Visual Studio .NET 2003 if I write my user
interface and export routines in C++ instead of C#?

How would you suggest I gain access to the messaging functionality located
in this DLL for my application?

Thanks in advance for all the help,

Andrew S. Giles

Nov 16 '05 #3
ok, I am trying to get this to work, and wonder if I have messed something up.

The DLL contains a public class that I will call Fred.

So, I write the following in C#:
[DllImport("vpcmsgmfcd.dll")]
public static extern Fred classFred;

and I get an error asking what namespace am I supposed to be using.

I know I am doing something wrong, but I just do not know what. I am sorry
to be asking these annoyingly simple questions, but any help would be greatly
appreciated.

Andrew

"BenW" wrote:
You can access non COM dlls lookup extern keyword and DllImport attribute.
BenW

"Andrew S. Giles" wrote:
OK, I just want to make sure I am correct in the following statements, and
then to get some advice as to how I should proceed.

First, is it accurate to say that in order for C# to use a DLL, the classes
and members exposed must utilize a COM interface?

I tried adding a refernce to a DLL that was just created (in C++ to cross
compile between Microsoft Visual C++ 6.0 and Borland C++ Builder 5, providing
messaging functionality through ACE) to solve a communications problem
between Borland and Microsoft compilers, only to have Visual Studio .NET 2003
(version 7.1 I believe) tell me that I cannot add the DLL file because it is
neither a valid assembly, nor a COM object.

Is is possible to use this DLL in Visual Studio .NET 2003 if I write my user
interface and export routines in C++ instead of C#?

How would you suggest I gain access to the messaging functionality located
in this DLL for my application?

Thanks in advance for all the help,

Andrew S. Giles

Nov 16 '05 #4
Andrew,

If you want to export a class, then you have to wrap it in a manged
wrapper in C++, or you have to use COM interop. Using the DllImport
attribute works only for functions exported from the dll, not for classes.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Andrew S. Giles" <An**********@discussions.microsoft.com> wrote in message
news:D1**********************************@microsof t.com...
ok, I am trying to get this to work, and wonder if I have messed something
up.

The DLL contains a public class that I will call Fred.

So, I write the following in C#:
[DllImport("vpcmsgmfcd.dll")]
public static extern Fred classFred;

and I get an error asking what namespace am I supposed to be using.

I know I am doing something wrong, but I just do not know what. I am
sorry
to be asking these annoyingly simple questions, but any help would be
greatly
appreciated.

Andrew

"BenW" wrote:
You can access non COM dlls lookup extern keyword and DllImport
attribute.
BenW

"Andrew S. Giles" wrote:
> OK, I just want to make sure I am correct in the following statements,
> and
> then to get some advice as to how I should proceed.
>
> First, is it accurate to say that in order for C# to use a DLL, the
> classes
> and members exposed must utilize a COM interface?
>
> I tried adding a refernce to a DLL that was just created (in C++ to
> cross
> compile between Microsoft Visual C++ 6.0 and Borland C++ Builder 5,
> providing
> messaging functionality through ACE) to solve a communications problem
> between Borland and Microsoft compilers, only to have Visual Studio
> .NET 2003
> (version 7.1 I believe) tell me that I cannot add the DLL file because
> it is
> neither a valid assembly, nor a COM object.
>
> Is is possible to use this DLL in Visual Studio .NET 2003 if I write my
> user
> interface and export routines in C++ instead of C#?
>
> How would you suggest I gain access to the messaging functionality
> located
> in this DLL for my application?
>
> Thanks in advance for all the help,
>
> Andrew S. Giles

Nov 16 '05 #5
I can only export functions, but not classes, is this correct?

Andrew

"Nicholas Paldino [.NET/C# MVP]" wrote:
Andrew,

Basically, if you want to interop with unmanaged code, you have two
choices. The first would be to expose it through a COM object, the second
is to export functions from a DLL. You could also create a managed wrapper
in C++ if you wish, and then set your reference to that.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Andrew S. Giles" <An**********@discussions.microsoft.com> wrote in message
news:CE**********************************@microsof t.com...
OK, I just want to make sure I am correct in the following statements, and
then to get some advice as to how I should proceed.

First, is it accurate to say that in order for C# to use a DLL, the
classes
and members exposed must utilize a COM interface?

I tried adding a refernce to a DLL that was just created (in C++ to cross
compile between Microsoft Visual C++ 6.0 and Borland C++ Builder 5,
providing
messaging functionality through ACE) to solve a communications problem
between Borland and Microsoft compilers, only to have Visual Studio .NET
2003
(version 7.1 I believe) tell me that I cannot add the DLL file because it
is
neither a valid assembly, nor a COM object.

Is is possible to use this DLL in Visual Studio .NET 2003 if I write my
user
interface and export routines in C++ instead of C#?

How would you suggest I gain access to the messaging functionality located
in this DLL for my application?

Thanks in advance for all the help,

Andrew S. Giles


Nov 16 '05 #6
Andrew... Also, if you write it in ATL COM, all you do is add a reference to the dll and Visual Studio
creates the managed wrapper class for you.

http://www.geocities.com/jeff_louie/...op/atl_com.htm
How would you suggest I gain access to the messaging functionality located

in this DLL for my application?<

************************************************** ********************
Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...
Nov 16 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Russ | last post by:
Hello. I have a very large business application written all in VC++ and MFC. Now I want to interface some of it to the web. I have VS.NET2003 and have been studing walkthroughs and documentation...
10
by: Gary Jones | last post by:
Hi, I'm trying to find my feet with C# and have hit a bit of a wall. I have lots of legacy code in a DLL written in Delphi. I don't think the fact that it's written in Delphi should cause too...
6
by: _R | last post by:
I've had to write a lot of code to interface C# to older Win32 DLLs. Basically, an unmanaged C++ class talks directly to the Win32 DLL. A managed C++ class encloses the unmanaged C++ class. C#...
0
by: ZMan | last post by:
Scenario: This is about debugging server side scripts that make calls to middle-tier business DLLs. The server side scripts are legacy ASP 3.0 pages, and the DLLs are managed DLLs...
2
by: ClydeL | last post by:
Compling a legacy VC6.0 program with the VC2005 compiler used mfc80 dlls. Do these get installed with the .NET runtime or do they need to be installed separately.
7
by: Jeff Lynn | last post by:
Help! I recently upgraded my VS V6 to VS 2005 and was unable to build projects that were perfectly ok under VS V6. Where VS 2005 fails was in the linker resolving external DLLs, which are Open...
9
by: Roy Chastain | last post by:
I have a legacy structure that appears on a communications line that has 16 bit, 8 bit, 2 bit and 1 bit fields in it. The best I have been able to do with this was to use FieldOffset for the 8 and...
0
by: Adrian | last post by:
Hi, I'm working on a large legacy VC application which is split in to many DLLs. The chosen 'pattern' for many classes is to hide an implementation class in the cpp file. The problem I'm facing...
2
by: dan | last post by:
Our company has a large legacy application that we would like to convert to run under the CLR. The application consists of a large collection of Dlls that have been written in C++ and MFC over...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.