Jump to content

Welcome to eMastercam

Register now to participate in the forums, access the download area, buy Mastercam training materials, post processors and more. This message will be removed once you have signed in.

Use your display name or email address to sign in:

serial number hasp


Recommended Posts

To get the Serial# of the HASP ->


Imports System.Runtime.InteropServices

Class Interop
     ' The name of the DLL that we call into...
     Public Const DLL As String = "Mastercam.exe"   ' An .EXE is this case!

     ' The function entry point is the “mangled” name as it appears in the Mastercam.exe file.
     ' Use the Visual Studio (cmd line) tool “DumpBin /exports <filename>”  to discover what’s inside a DLL/EXE.
     ' We can supply a friendly name we can use in our code that will call the “EntryPoint” named function. 

      <DllImport(DLL, EntryPoint := "?get_sim_serial_num@@YAJXZ", CharSet := CharSet.Auto)> _
       Public Shared Function HaspSerialNumber() As System.Int32
       End Function
End Class


Public Class MyNETHook
      Inherits Mastercam.App.NetHook2App

      ' NETHook Entry Point Function
      Public Overrides Function Run(param As Integer) As Mastercam.App.Types.MCamReturn
      Dim result As MCamReturn = MCamReturn.NoErrors
      Try
         Dim serial As System.Int32 = Interop.HaspSerialNumber()
         Dim msg As String = String.Format("Serial# = {0}", serial)
         MessageBox.Show(msg, "ReadHASP", MessageBoxButtons.OK)
      Catch ex As Exception
         MessageBox.Show(ex.Message, "UnHandled Exception: " + ex.Source, MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
         result = MCamReturn.ErrorOccurred
       End Try
       Return result Or MCamReturn.AppUnloaded
    End Function

End Class

Link to comment
Share on other sites

That can get a little tricky.

Not finding out what the function returns, that's quite easy,

but you need to determine which .NET type that equates to.

 

First you need to "undecorate" the function signature...

One way is using the Microsoft’s undname (cmd-line) tool like this ->

---------------------

C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC>undname ?get_sim_serial_num@@YAJXZ

Microsoft ® C++ Name Undecorator

Copyright © Microsoft Corporation. All rights reserved.

 

Undecoration of :- "?get_sim_serial_num@@YAJXZ"

is :- "long __cdecl get_sim_serial_num(void)"

---------------------

 

And there are several other tools out there on the Web like this DLL Export Viewer.

 

It shows us that this function returns a "long".

OK… What's the equivalent in .NET ?

 

A "long" in (Microsoft) C++ is a 32-bit value.

A "long" in .NET is an alias for System.Int64

So we certainly don't want to use the .NET "long" in the <DllImport...> on the .NET side!

 

***WARNING***

Don't go crazy scanning the DLLs for functions to use.

If that function you find and use is not listed in the CHook SDK - there is no guarantee that it will be available in the next release. *Consider yourself "properly warned"!

Link to comment
Share on other sites
  • 3 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.

Join us!

eMastercam - your online source for all things Mastercam.

Together, we are the strongest Mastercam community on the web with over 56,000 members, and our online store offers a wide selection of training materials for all applications and skill levels.

Follow us

×
×
  • Create New...