使用方法:
1.直接把此 dll 文件放到 bin 目录下.
2.创建C#调用类 wlincese.cs文件
![[转载]C#调用WinLicenseSDK.dll在线生成dat许可证/注册 winlicense 破解](http://img.413yy.cn/images/31101031/31121429t01dbaf6db0788efabb.png)
代码如下:
public class wlincese
{
[DllImport("WinlicenseSDK.dll", EntryPoint ="WLGenLicenseFileKey", CallingConvention =CallingConvention.StdCall)]
public extern static intWLGenLicenseFileKey(stringpLicenseHash, string pUserName, string pOrganization, stringpCustomData, string pMachineID, int NumDays, int NumExec, refSystemTime pExpirationDate, int CountryId, int Runtime, intGlobalTime, byte[] pBufferOut);
[StructLayout(LayoutKind.Sequential)]
public class SystemTime
{
public short wYear;
public short wMonth;
public short wDayOfWeek;
public short wDay;
public short wHour;
public short wMinute;
public short wSecond;
public short wMilliseconds;
}
}
上面是完整的 wlincese.cs 文件代码(没有加入命名空间)
红色部分是.net下调用非托管代码编译DLL文件的方法
蓝色部分是定义将要用到的方法(此方法必须是DLL文件中包含的方法)
绿色部分就是上面方法需要的参数
最下面 紫色部分是定义的一个 结束时间类 类里定义的 年,月,日......都是int16 类型的整数,为什么定义此类?因为上面方法的参数 绿色部分中 ref SystemTime 就是此类型的一个变量.
asp.net 页面web调用生成在线许可证
//指定许可散列生成特定密钥申请
string cusHashKey = "";
//指定许可证密钥注册名称 如为 空 无法登记名称信息
string cusKeyName = "";
//指定许可证密钥组织名称 如为 空 无法组织名称信息
string cusOrganization = "";
//指定用户自定义数据如为 空 无法还原用户自定义数据
string cusDataInfo = "";
//指定生成许可证密钥的机器码 如为 空 此许可证将会在所有终端激活(无机械锁)
string macKey = "1058-F257-96A0-DE3B-A67A-45A0-21B2-0D36";
//指定许可证使用的天数 如为0 许可证将不受天数限制
int numDay = 30;
//指定许可证中电脑台数限制 如为 0 将不限制电脑台数
int numComputer = 25;
//指定许可证到期日期 例如: 2012-08-01 14:45:45 ref可进可出参数
Test.SystemTime endTime = new Test.SystemTime();
endTime.wYear = Convert.ToInt16(2012);
endTime.wMonth = Convert.ToInt16(8);
endTime.wDay = Convert.ToInt16(1);
endTime.wHour = Convert.ToInt16(14);
endTime.wMinute = Convert.ToInt16(45);
endTime.wSecond = Convert.ToInt16(45);
//指定国家ID 如为0 将努力使生成的许可证在所有国家可用
int countryID = 0;
//指定全球时间限制范围内生成许可证文件 如为 0 表示生成许可证不受全球时间限制
int globalTime = 0;
//指定运行的网络实例 如为0 许可证将不受不同网络限制
int netWorkID = 0;
//指定密钥缓存区
byte[] byteKey = new byte[65533];
//指定bat密钥文件保存路径并打开此文件流
FileStream fileStream = new FileStream(Server.MapPath("/key/" +macKey + ".bat"), FileMode.OpenOrCreate);
//调用 wlincese 中定义的方法
int k = wlincese.WLGenLicenseFileKey(
cusHashKey,
cusKeyName,
cusOrganization,
cusDataInfo,
macKey,
numDay,
numComputer,
ref endTime,
countryID,
netWorkID,
globalTime,
byteKey);
if (k > 0)
{
try
{
//将缓存区字节数组写入文件流,保存成本地文件
fileStream.Write(byteKey, 0, k);
}
catch
{ }
finally
{
fileStream.Flush();
fileStream.Close();
}
//如果保存文件成功 返回web下载地址
}
上面是业务需要将许可证文件保存到指定目录下,你也可以直接输出http流 response 到客户端.