Error adding unmanaged DLL ref to C# project

S

shade

Hello everyone,

I'm writing a C# app with Visual Studio 2005 that needs to use classes
and functions from an unmanaged DLL (that was build with Visual Studio
2003). In order to build my C# app, I thought I had to include a
reference to the DLL. When I try that, I get this error:

A reference to (my DLL) could not be added. Please make sure that the
file is accessible, and that it is a valid assembly or COM component.

Please forgive me if I've posted to the wrong place; your feedback/
direction is greatly appreciated.
 
N

Nicholas Paldino [.NET/C# MVP]

Shade,

The error basically tells you what you have to do. You can not just
access a native dll from .NET. You either have to expose the classes as COM
objects, or create a managed wrapper that you can use in your program.
 
S

shade

Shade,

The error basically tells you what you have to do. You can not just
access a native dll from .NET. You either have to expose the classes as COM
objects, or create a managed wrapper that you can use in your program.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)




Hello everyone,
I'm writing a C# app with Visual Studio 2005 that needs to use classes
and functions from an unmanaged DLL (that was build with Visual Studio
2003). In order to build my C# app, I thought I had to include a
reference to the DLL. When I try that, I get this error:
A reference to (my DLL) could not be added. Please make sure that the
file is accessible, and that it is a valid assembly or COM component.
Please forgive me if I've posted to the wrong place; your feedback/
direction is greatly appreciated.- Hide quoted text -

- Show quoted text -

Hi Nicholas,

Thanks for the quick reply. I understand what I have to do, but *how*
to do it still doesn't make sense. For example, let's say I do the
managed wrapper - wouldn't that be another C++ project in which
the .cpp codes creates pointers to the original classes/methods? Even
so, how will I be able to build that project if I can't created a
reference to the unmanaged dll?

Thanks for your patience and feedback.
 
B

Ben Voigt [C++ MVP]

Hi Nicholas,

Thanks for the quick reply. I understand what I have to do, but *how*
to do it still doesn't make sense. For example, let's say I do the
managed wrapper - wouldn't that be another C++ project in which
the .cpp codes creates pointers to the original classes/methods? Even
so, how will I be able to build that project if I can't created a
reference to the unmanaged dll?

A C++/CLI program would use the DLL in the native manner -- using header
files and linking with the import library, or using dynamic loading via
LoadLibrary.

You can also use C# to access bare functions in a native DLL, using
DllImport, but there is no way to get to native classes.
 

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