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
>
>