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:

get_user_type


Recommended Posts

Hi guys,

 

I'm using finally

code:

[DllImport("SimAccess.dll", EntryPoint = "?get_hasp_info@@YAXDPAUmcSimInfo@@@Z")]

public extern static void get_hasp_info(sbyte countLicenses, mcSimInfo* sim);

 

with

 

[structLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]

public struct mcSimInfo

{

public sbyte netHasp;

public sbyte netHaspNetwork;

public long serialNumber;

public short timeLimitOK;

public sbyte timed;

public short daysLeft;

public ushort timedStartDate;

public ushort timedEndDate;

public short userType;

public int nMillSeatsLicensed;

public int nMillSeatsLeft;

public int nLatheSeatsLicensed;

public int nLatheSeatsLeft;

public int nWireSeatsLicensed;

public int nWireSeatsLeft;

public int nDesignSeatsLicensed;

public int nDesignSeatsLeft;

public int nRouterSeatsLicensed;

public int nRouterSeatsLeft;

public sbyte maintenance;

public short maintDaysLeft;

public short maintDateOK;

public ushort maintExpirationDate;

}

--Titus

Link to comment
Share on other sites

Thanks a lot Roger !

 

Well, initially, I wanted just userType but having more details is better smile.gif

 

Now I'm trying to implement get_user_type() into a standalone application, with this declaration

code:

[DllImport("mastercam.exe", EntryPoint = "?get_user_type@@YAFXZ")]

public extern static short get_user_type();

but I'm getting an AccessViolationException when calling.

 

Anything wrong in my declaration ?

 

Thanks

--Titus

Link to comment
Share on other sites

I created a simple (C#) Windows Forms Application (with a textbox and an OK button) and this appeared to work for me ->

 

code:

  System.Runtime.InteropServices.DllImport("mastercam.exe", EntryPoint = "?get_user_type@@YAFXZ")]        

public static extern short get_user_type();

 

private void buttonOK_Click(object sender, EventArgs e)

{

short utype = get_user_type();

this.textBox1.Text = utype.ToString();

}

Of course the App's .EXE must be in the same folder as mastercam.exe using the DllImport declaration shown above.

Link to comment
Share on other sites

You can get AccessViolationException if you're mixing Release & Debug code.

If seen this happen if my NETHook) app is a Debug build and Mastercam is a Release build.

 

If you could explain in detail exactly what you're trying to do, that may help.

 

'Stand-alone' application.

Are you trying to get this info without having Mastercam running?

I would not be surprised if that did not work.

Link to comment
Share on other sites

Thanks Roger !!

 

I'm not mixing Release and Debug code, it was just a quick test to see what's happening when the library mastercam.exe is the one in sdkdebug folder.

 

I'm doing a C# Windows Form Application straightforward, having a textbox and a button on it so it's not a NET-Hook and Mastercam is not running. I need to know the type of the user without having to open Mastercam.

 

I keep getting that exception whenever McamX2-MR2mastercam.exe is used.

 

Thanks,

--Titus

Link to comment
Share on other sites

Using a simple (standalone) C# Windows Form Application that has a textbox and a button on it.

Mastercam is not running...

 

To read the data on the HASP we can call the exported GetSimInfo function in SimAccess.dll.

 

Of course SimAccess.dll is 'unmanaged' code.

So we use P/Invoke Interop to do the calling from our 'managed' (C#) App to the 'unmanaged' SimAccess.dll

 

code:

       using System.Runtime.InteropServices; 

 

// Must layout the data structure that ‘GetSimInfo’ is expecting

// (This must add up to ‘112’ bytes)

[structLayout(LayoutKind.Sequential)]

public struct mcSimInfo

{

[MarshalAs(UnmanagedType.Bool)]

public byte netHasp; // bool

public byte netHaspNetwork; // bool

public int serialNumber;

public int timeLimitOK;

public byte timed; // bool

public int daysLeft;

 

[MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst = 12)]

public byte[] timedStartDate; // char

 

[MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst = 12)]

public byte[] timedEndDate; // char

 

public int userType;

public int nMillSeatsLicensed;

public int nMillSeatsLeft;

public int nLatheSeatsLicensed;

public int nLatheSeatsLeft;

public int nWireSeatsLicensed;

public int nWireSeatsLeft;

public int nDesignSeatsLicensed;

public int nDesignSeatsLeft;

public int nRouterSeatsLicensed;

public int nRouterSeatsLeft;

public byte maintenance; // bool

public int maintDaysLeft;

public byte maintDateOK; // bool

 

[MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst = 12)]

public byte[] maintExpirationDate; // char

}

 

 

// Declare the DllImport for the function we wish to call in the external DLL

[DllImport("simaccess.dll", EntryPoint = "GetSimInfo")]

public extern static void GetSimInfo(bool countLicenses,

[MarshalAs(UnmanagedType.Struct)]

ref mcSimInfo simInfo);

 

 

/// <summary>

/// Read the HASP

/// via the 'GetSimInfo' function in SimAccess.dll

/// and return the ‘usertype’ data

/// </summary>

private int ReadSimInfo()

{

bool countLicenses = false;

mcSimInfo simInfo = new mcSimInfo();

// int size = Marshal.SizeOf(simInfo); // Diagnostics - to check the struct size

GetSimInfo(countLicenses, ref simInfo);

return simInfo.userType;

}

 

 

private void buttonOK_Click(object sender, EventArgs e)

{

int userType = ReadSimInfo();

this.textBox1.Text = userType.ToString();

}


Link to comment
Share on other sites

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