先在引用选取你需要用的这个dll,在程序中添加类,举个简单的例子给你,
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime.InteropServices;
using C1.C1Zip;namespace Util
{
#region
/// <summary>
/// This Class is used for get or set local machine time
/// </summary>
public class Cls_ChangeDT
{
//this function is used for get local machine time
[DllImport("Kernel32.dll")]
public static extern void GetLocalTime(SystemTime st); //this function is used for set local machine time
[DllImport("Kernel32.dll")]
public static extern void SetLocalTime(SystemTime st); //this structure define a systemtime
[StructLayout(LayoutKind.Sequential)]
public class SystemTime
{
public ushort wYear;
public ushort wMonth;
public ushort wDayOfWeek;
public ushort wDay;
public ushort wHour;
public ushort wMinute;
public ushort wSecond;
public ushort wMilliseconds;
}
}
}
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime.InteropServices;
using C1.C1Zip;namespace Util
{
#region
/// <summary>
/// This Class is used for get or set local machine time
/// </summary>
public class Cls_ChangeDT
{
//this function is used for get local machine time
[DllImport("Kernel32.dll")]
public static extern void GetLocalTime(SystemTime st); //this function is used for set local machine time
[DllImport("Kernel32.dll")]
public static extern void SetLocalTime(SystemTime st); //this structure define a systemtime
[StructLayout(LayoutKind.Sequential)]
public class SystemTime
{
public ushort wYear;
public ushort wMonth;
public ushort wDayOfWeek;
public ushort wDay;
public ushort wHour;
public ushort wMinute;
public ushort wSecond;
public ushort wMilliseconds;
}
}
}
1、使用TLBIMP命令将非托管dll转化为可托管的引用,楼主的问题很可能这样可以解决。这个时候需要使用者对dll的内容十分清楚,包括引用的函数接口,参数等;
2、如果想使用从C++来实现托管环境中没有提供支持的功能,最好使用Vc++。net生成ATL控件,这样成功后系统会自动编译并且注册,只要在控件面板中添加该控件就可以了,这种方法的好处是可以在对象浏览器中看到控件的方法申明!!
这样VS.net会自动对你的unmanaged Code进行包装,
接下去就同其他组件一样使用就行了,
不过里面的一些方法和属性类型被转变成了object类型。
你要对里面的函数比较清楚.