C#所需的HASP HL工作演示

ThN*_*ThN 5 .net c# usb exception hasp

好的.好吧,我知道这个问题很有可能在前10分钟内被关闭,但我还是会问它,因为我花了将近一天半的时间试图寻找解决方案.不过,我无法想出这个.虽然他们有演示,但即使在HASP(safenet)网站上也没有太多关于此的信息.

我有一个HASP HL USB加密狗.我尝试转换他们的演示和测试运行它,但对于我的生活我甚至无法让它登录甚至.它不断提高Aladdin.HASP.HaspStatus.HaspDotNetDllBroken异常.

但是,如果我运行他们演示的C版本,它可以很好地工作.

这是我的代码的Csharp版本:

Aladdin.HASP;
HASP myHasp = new HASP();
var thestatus = myHasp.Login(vender_code);
myHasp.Logout;
Run Code Online (Sandbox Code Playgroud)

我想登录USB HASP并在其内存中获取其HaspID和设置.

提前致谢,

Dan*_*dor 3

您可能没有 HASP 运行时的所有依赖项。我正在打包应用程序:

hasp_windows_NNNNN.dll (NNNNN = your number)
hasp_net_windows.dll
MSVCR71.DLL (added manually)
msvc runtime 80
Run Code Online (Sandbox Code Playgroud)

HASP 需要一个运行时库,并且它不会告诉您是哪一个,除非您将其放入 DEPENDS.EXE 实用程序中(您的 Visual Studio 安装中可能有)。

登录(并读取一些字节):

            byte[] key = new byte[16];
            HaspFeature feature = HaspFeature.FromFeature(4);
            string vendorCode = "your vendor string, get it from your tools";
            Hasp hasp = new Hasp(feature);
            HaspStatus status = hasp.Login(vendorCode);
            if (HaspStatus.StatusOk != status)
            {
                //  no license to run
                return false;
            }
            else
            {
                //  read some memory here
                HaspFile mem = hasp.GetFile(HaspFileId.ReadOnly);
                mem.Read(key, 0, 16);
                status = hasp.Logout();
                if (HaspStatus.StatusOk != status)
                {
                    //handle error
                }
            }
Run Code Online (Sandbox Code Playgroud)

希望能帮助到你。我的 HASPed 软件非常有用。顺便说一句,在没有设置组合的情况下,无法将信封放在 .NET 应用程序周围。