PC Review


Reply
Thread Tools Rate Thread

Adding an unmanaged DLL

 
 
ba.hons
Guest
Posts: n/a
 
      25th Apr 2007
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

 
Reply With Quote
 
 
 
 
=?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
Guest
Posts: n/a
 
      25th Apr 2007
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
>
>

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Manage in unmanaged easier or unmanaged in managed garlic Microsoft Dot NET Compact Framework 5 28th Apr 2008 04:07 PM
Error adding unmanaged DLL ref to C# project shade Microsoft C# .NET 3 17th Aug 2007 11:08 PM
Access violation in unmanaged code: Linking managed with unmanaged static libs Pixel.to.life Microsoft VC .NET 3 23rd Jul 2007 04:16 AM
Adding an unmanaged DLL ba.hons Microsoft C# .NET 4 26th Apr 2007 03:37 PM
call managed/unmanaged classes from unmanaged code bonk Microsoft VC .NET 1 1st Oct 2005 04:10 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:58 AM.