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

Adding an unmanaged DLL

Hello,

wondering if somone could clear something up for me as i have been
reading around this subject for a while and am still confused.

I have a DLL from a hardware vendor but i dont know what language the
DLL is written in.

I would like to use this DLL from managed code (c#). From what i have
read i need this to be a COM object, but i dont really understand how
you differentiate between a dll written in C++ which is a COM object
and on that isnt.

Each time i try to add the dll as a reference (VS 2003 .Net 2.0) i get
the following message:

A reference to MYDLL.dll could not be added. This is not a valid
assembly or COM component.

I have tried using PINVOKE see code below and managed to call a
method from the DLL using my c# application but i dont really want to
write a method for each method the DLL supports, mainly becuase i am
worried about casting data types etc

[DllImport("MyDLL.dll", SetLastError = true, CharSet =
CharSet.Auto)]
static extern bool AlarmLogSize(int lpDirectoryName,
out uint lpFreeBytesAvailable);

Form1.AlarmLogSize(0, out freeBytesAvail);
MessageBox.Show(freeBytesAvail.ToString());

Can anyone tell me how best i can use this DLL and what my options
are.

Also i have an example application written in VB6 which come with the
DLL and that has a Module which seems looks like this:

Public Declare Function AlarmLogSize Lib "VertX.dll" (ByVal mode As
Long, _
logSize As Long) As Long

I have no idea when it comes to VB but i presume this is the
equivilent of what am doing with my PINVOKE applicaiton.

Any help really appreicated!

Thanks

Adam

Apr 25 '07 #1
1 3016
The first thing you should do is determine whether this dll is indeed a COM
server. Attempt to register it with "regsvr32 yourdllpathandname".
Regsvr32.exe should be in your windows or system32 folder. If COM
registration succeeds, you should then be able to set a reference from Visual
Studio by switching to the COM tab in "add reference" and you should find
your COM server listed there.
Visual Studio will automatically generate a .NET Com Interop wrapper.
Peter

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"ba.hons" wrote:
Hello,

wondering if somone could clear something up for me as i have been
reading around this subject for a while and am still confused.

I have a DLL from a hardware vendor but i dont know what language the
DLL is written in.

I would like to use this DLL from managed code (c#). From what i have
read i need this to be a COM object, but i dont really understand how
you differentiate between a dll written in C++ which is a COM object
and on that isnt.

Each time i try to add the dll as a reference (VS 2003 .Net 2.0) i get
the following message:

A reference to MYDLL.dll could not be added. This is not a valid
assembly or COM component.

I have tried using PINVOKE see code below and managed to call a
method from the DLL using my c# application but i dont really want to
write a method for each method the DLL supports, mainly becuase i am
worried about casting data types etc

[DllImport("MyDLL.dll", SetLastError = true, CharSet =
CharSet.Auto)]
static extern bool AlarmLogSize(int lpDirectoryName,
out uint lpFreeBytesAvailable);

Form1.AlarmLogSize(0, out freeBytesAvail);
MessageBox.Show(freeBytesAvail.ToString());

Can anyone tell me how best i can use this DLL and what my options
are.

Also i have an example application written in VB6 which come with the
DLL and that has a Module which seems looks like this:

Public Declare Function AlarmLogSize Lib "VertX.dll" (ByVal mode As
Long, _
logSize As Long) As Long

I have no idea when it comes to VB but i presume this is the
equivilent of what am doing with my PINVOKE applicaiton.

Any help really appreicated!

Thanks

Adam

Apr 25 '07 #2

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

Similar topics

2
by: Lady_A | last post by:
Hi, I need to add a reference to a static library (*.lib) to a COM/ATL project in VS.NET. Apparently if this library is not in my solution that is not possible using the ordinary way : Add...
5
by: Angel | last post by:
Is there some way to add a C-header file into a C# project? The problem is that this .h file contains several complex structures (over 20) that are used by some unmanaged code. These functions...
4
by: Rachel Suddeth | last post by:
What is the difference between a managed/unmanaged resource, and how do you tell which is which? I'm trying to understand how to write some Dispose() methods, and we are supposed to put code that...
1
by: Sparhawk | last post by:
Hi, my company is going to migrate a large VC++ application to .NET to make use of Windows Forms (the old class library is not updated any more). We are not planning to migrate the rest of the...
6
by: marek | last post by:
Hello All, we are doing a quite a big project that contains at the lowest level an unmenaged c++ classes. Above it there are managed wrappers and at the top there are ASP.NET pages. Can anyone...
6
by: Stephen Walch | last post by:
Our application environment consists of three basic layers: 1. Third-party unmanaged DLLs that were written before the CLR was invented and maintain a significant amount of information (including...
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...
5
by: akash | last post by:
I'm having problems calling an unmanaged class from a managed wrapper. I suspect I'm missing something obvious, as I'm unfamiliar with C++ and classes are very simple. My unmanaged class is as...
7
by: Pixel.to.life | last post by:
Gurus, Another question on one of the coveted Microsoft products: JIT debugger with VS2005. I have a managed app that builds great on one machine (Vista Home basic, VS2005, JIT enabled for...
12
by: Jeff Gaines | last post by:
I am a hobbyist programmer, using C# and VS2008 and writing desktop apps. I am trying hard to take a modular approach to avoid re-inventing the wheel but I'm finding it a bit frustrating. For...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
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?
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...

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.