locked
usafe32.dll vb6.0 to .net core C# RRS feed

  • Question

  • User-893002196 posted

    Hi All,

    What nuget should I used for this usafe.dll? I have vb6.0 code below & need to convert to be .net core C#. Anyone have idea how to do this?

    Dim uUSafePacket As USafePacket
                Dim uUSafeAuthCode As USafeAuthCode
                Dim uUSafeKeyID As USafeKeyID
                Dim iKeyIDSet As Integer
                Dim lResult As Long
    
                If USAFEInitGlobal(uUSafePacket) = 1 Then
                    uUSafeAuthCode.Value = sUSafeAuthCode
                    uUSafeKeyID.Value = sUSafeKeyID
                    lResult = USAFEUpdateRnboKey(uUSafePacket, uUSafeAuthCode, uUSafeKeyID, iKeyIDSet)
                Else
                    lResult = -1
                End If
    
    
                Me.NewKeyID = sUSafeKeyID
                Me.AuthCode = sUSafeAuthCode
                WriteKey = lResult

    Please advise. Thanks.

    Regards,
    Micheale

    Wednesday, March 17, 2021 1:37 AM

All replies

  • User1120430333 posted

    Unsafe Class (System.Runtime.CompilerServices) | Microsoft Docs

    NuGet Gallery | System.Runtime.CompilerServices.Unsafe 5.0.0

    Dim uUSafePacket As USafePacket in VB is this in C# USafePacket uUsSafePacket; 

    And 'Me.' in VB is this in C# 'this.'
    With the above, you should be able to figure out how to convert the code from VB to C#
    Wednesday, March 17, 2021 5:32 AM
  • User-893002196 posted

    Hi,

    Usafe32.dll is Sentinel SafeNet API

    https://sentineldiscussion.gemalto.com/viewFile.do?fileId=43161000000339031&forumGroupId=43161000000003001&portalzaid=-1

    But, I can't find the nuget for that.

    Thanks

    Regards,
    Micheale

    Wednesday, March 17, 2021 7:45 AM
  • Wednesday, March 17, 2021 2:59 PM
  • User-893002196 posted

    HI,

    Thanks Teacher Bruce.


    [DllImport("usafe32.dll", CharSet = CharSet.Unicode)]
            public static extern long USAFEInitGlobal(long uUSafePacket);
            [DllImport("usafe32.dll", CharSet = CharSet.Unicode)]
            public static extern Int32 USAFEFindRnboKey(byte uUSafePacket, string uUSafeKeyID);
            [DllImport("usafe32.dll", CharSet = CharSet.Unicode)]
            public static extern long USAFEUpdateRnboKey(byte uUSafePacket, string uUSafeAuthCode, string uUSafeKeyID, string iKeyIDSet);
    
    [HttpGet]
            public long WriteKey(string sUSafeKeyID, string sUSafeAuthCode)
            {
                USafePacket uUSafePacket;    ????
                USafeAuthCode uUSafeAuthCode;    ????
                USafeKeyID uUSafeKeyID;    ????
                int iKeyIDSet;
                long lResult;
    
                if (USAFEInitGlobal(uUSafePacket) = 1)
                {
                    uUSafeAuthCode.Value = sUSafeAuthCode;    ????
                    uUSafeKeyID.Value = sUSafeKeyID;    ????
                    lResult = USAFEUpdateRnboKey(uUSafePacket, uUSafeAuthCode, uUSafeKeyID, iKeyIDSet)
                }
                else
                {
                    lResult = -1;
                }
    
    
                Me.NewKeyID = sUSafeKeyID    ????
                Me.AuthCode = sUSafeAuthCode    ????
                WriteKey = lResult;
            }

    Can you advise how to resolved this  ????
    I got example error:  CS0246: The type or namespace name 'USafePacket' could not be found (are you missing a using directive or an assembly reference?)


    This is really new to me & I want to learnt. But no resources on the .net about [DllImport("usafe32.dll", CharSet = CharSet.Unicode)]

    Really appreciate for your guidance. 

    Thanks.

    Regards,
    Micheale

    Thursday, March 18, 2021 2:25 AM
  • User1120430333 posted

    It looks to me that the solution is too legacy to be viable in a .NET solution especially if you have to define some objects externally from the imported DLL. I don't know just saying.

    Thursday, March 18, 2021 6:53 AM
  • User-893002196 posted

    Hi DA924,

    It's an legacy project I think 20 years old. Some of the dll source code I don't have. So have to think a way to resolved it. ;)

    Thanks.


    Regards,
    Micheale

    Thursday, March 18, 2021 7:12 AM
  • User1120430333 posted

    I have gone through a couple VB6 to VB.NET conversions and have run into the problem you are facing concerning a 3rd party DLL solution that could not be used. The best thing I can tell you is search for a 3rd party vendor that has something similar that is .NET, if you can't be helped here.

    Thursday, March 18, 2021 9:39 AM
  • User-893002196 posted

    Hi,

    Thanks for the suggestion.

    Regards,
    Micheale

    Thursday, March 18, 2021 2:16 PM
  • User-474980206 posted

    Those are parameter names, not data types.  It is odd uUSafePacket is long in one method and byte in another.

    Thursday, March 18, 2021 2:26 PM
  • User-893002196 posted

    Hi Bruce,

    Let said I have this in VB6.0

    Dim oKeyIDConverter As New KeyIDConverter.Decoder

    If oKeyIDConverter.ReadOldKeyID() <> 0 Then
                lResult = -4
            Else
                sOldKeyID = oKeyIDConverter.OldKeyID
                If oKeyIDConverter.CreateNewKeyID(sOldKeyID) <> 0 Then
                    lResult = -3
                Else
                    sNewKeyID = oKeyIDConverter.NewKeyID
                    lInternalID = oKeyIDConverter.InternalID

    How to call in C#:-
    [DllImport("KeyIDConverter.dll")]
            public static extern long ReadOldKeyID();
            [DllImport("KeyIDConverter.dll")]
            public static extern long CreateNewKeyID(string sUSafeIOldKeyID);

    Please advise.

    Just to understand & see how can I work around because I still not sure can get the dll source code from 3rd party vendor or not since it's 20 years old.

    Thanks.

    Regards,
    Micheale

    Monday, March 22, 2021 10:48 AM