5

Okay. Well, I know this question has a good chance of being closed within the first 10 minutes, but I am going to ask it anyways for I have spent almost day and an half trying to find a solution. Still, I can't figure this one out. There is not much info on this on the Internet not even on the HASP (safenet) website although they have demos.

I have a HASP HL USB dongle. I try to convert their demo and test run it but for the life of me I simply can't get it to login even. It keeps raising Aladdin.HASP.HaspStatus.HaspDotNetDllBroken exception.

However, if I run the C version of their demo, it works perfectly.

Here is the Csharp version of my code:

Aladdin.HASP;
HASP myHasp = new HASP();
var thestatus = myHasp.Login(vender_code);
myHasp.Logout;

I would like to login to USB HASP and get its HaspID and the settings in its memory.

Thanks in advance,

ThN
  • 3,235
  • 3
  • 57
  • 115

1 Answers1

3

It might be that you aren't having all dependencies for the HASP runtime. I'm packing with the app:

hasp_windows_NNNNN.dll (NNNNN = your number)
hasp_net_windows.dll
MSVCR71.DLL (added manually)
msvc runtime 80

One runtime library is required by HASP and it doesn't tell you which one unless you put it in the DEPENDS.EXE utility (you probably have you on your Visual Studio installation).

To log in (and read some bytes):

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

Hope it helps. My HASPed software works like a charm. BTW, wasn't able to put envelope around .NET app under no combination of settings.

Daniel Mošmondor
  • 19,718
  • 12
  • 58
  • 99
  • Daniel, Thank you for your reply, but I still can't get it to work. Whenever I try to add MSVCR71.dll to my reference list, the compiler raises message "Operation is not valid due current state of the object." I am not sure why. The only dll file I am able to add reference to is hasp_net_windows.dll. – ThN May 30 '12 at 14:27
  • That is unmanaged dll and thus can't be added as a reference. Just put it into the executable folder. Also, use depends.exe to find any missing dependent DLL that you might need. – Daniel Mošmondor May 30 '12 at 16:43
  • Daniel, I was only able to find hasp_net_windows.dll and MSVCR71.dll and not the hasp_windows_NNNNN.dll you speak of. Do I need to download the missing DLL file from the Internet? Those files I found are within the executable folder. Still, I am getting the same exception. I ran Depends.exe and it keeps complaining that IEShims.dll is missing, even though it is found in my system. – ThN May 31 '12 at 12:28
  • ieshims.dll isn't important. See that tool that hasp have, maybe it is generating that dll for you, I can't remember. – Daniel Mošmondor May 31 '12 at 15:01
  • Daniel, I am finally able to read my HASP dongle successfully. However, hasp.Getfile function won't work for me. So, I used hasp.getsessioninfo which did work. Thank you for your help. – ThN Aug 08 '12 at 18:48
  • regarding getfile, did you create memory block with hasp management tools? – Daniel Mošmondor Aug 08 '12 at 20:17
  • Daniel, memory block with hasp management tools??? I know you can read and write to dongle memory through their tools. opps! in the previous comment I meant to say that without passing in any parameters to GETFILE method worked but not the other way around. That's how I am able to read the dongle memory. – ThN Aug 08 '12 at 20:39
  • AFAIK, You have to define a memory block in HASP management (can't remember a name) to be able to use it. Glad I helped :) – Daniel Mošmondor Aug 08 '12 at 21:45