Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello All
Could some one describe or direct me to an article which describes how to implement interfacing with a hardware device that come with a DLL. I have a USB Device that came with a DLL. I have the list of the functions. What I need is to implement the function pointers and HINSTANCE into my C# WPF Project and call the functions through my GUI. A step by step instruction is appreciated.
Posted
Comments
Sergey Alexandrovich Kryukov 9-Dec-11 0:04am    
What do you mean by the DLL? Is it a .NET assembly or not? (I'm afraid not.)
--SA

Thanks for your respond SAKryukov. The DLL is not a .NET assembly. I am using DllImport for function pointers. At this time below is all I got. However I still need to add a C# equivlent of HINSTANCE and loadlibrary
(in C++ it is :HINSTANCE hDll = LoadLibrary("HINSTANCE hDll = LoadLibrary("supertim.dll");.dll"))
to bound the control to my dll. I don't know how to achieve that in C#. The other thing I need to do is to get the Handle that the control is bound to and send it through InitTimerDll() function. I appreciate your help.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Interop;
using System.Runtime.InteropServices;


namespace WpfApplication1
{
class myDLL_DLL_Interface
{

struct dll_init_params { ushort simp; ushort simt;}
[DllImport("myDll.dll")]
public static extern void InitTimerDll("Handle", ref dll_init_params InitParams);
[DllImport("myDll.dll")]
public static extern void TerminateTimerDll();
[DllImport("myDll.dll")]
public static extern void ProberOnLine(ushort i);
[DllImport("myDll.dll")]
public static extern bool StageZmove(ushort die, ushort dir);
[DllImport("myDll.dll")]
public static extern int StageZPosition();
[DllImport("myDll.dll")]
public static extern bool StageToLoad(ushort die);
[DllImport("myDll.dll")]
public static extern bool StageGoTo(ushort die, long x, long y);
[DllImport("myDll.dll")]
public static extern void SetCounterX(ushort x);
[DllImport("myDll.dll")]
public static extern void SetCounterY(ushort y);
[DllImport("myDll.dll")]
public static extern bool Contact();
[DllImport("myDll.dll")]
public static extern void StartDelayInking();


}
}
 
Share this answer
 
Comments
Maciej Los 11-May-12 12:07pm    
I belive that isn't an answer. If you need to update your question, use "Improve question" button. Please, remove this "solution".
It looks like this is not a .NET assembly but a native (unmanaged) DLL. There are no "steps" to help you.

You need to have profiles of all functions and learn P/Invoke. Start from here:
http://en.wikipedia.org/wiki/P/Invoke[^],
http://msdn.microsoft.com/en-us/library/Aa712982[^].

Read this CodeProject article: Essential P/Invoke[^].

Doing it for your API can be very easy or very difficult. It depends on complications like incompatible types, callbacks, etc. The problems can range from trivial translation into C# to creation of custom marshaller.

There is an alternative approach which is especially good if you have a static link library. You can create a mixed-mode (managed+unmanaged) C++/CLI DLL. You can mix C++ with C++/CLI and wrap all native calls to your native DLL into .NET C++/CLI "ref" classes. The obtained executable can be used like a regular .NET assembly and referenced by your C# assembly.

—SA
 
Share this answer
 
v2
Comments
Maciej Los 11-May-12 12:08pm    
+5
Sergey Alexandrovich Kryukov 11-May-12 13:56pm    
Thank you.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900