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:

Recommended Posts

Yes it is. Sorry about that bonk.gif

 

Here's what I posted in the X Beta forums a couple of months back:

 

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

Getting started with Nethooks is super simple. I'm a fan of C# so I'll use that to explain. You'll first create a Class Library project in Visual Studio; C#, VB or J# (does anybody actually use J#?!?!?). Then you'll want to add a COM reference to nethook.dll (it'll be in the root directory fo wherever you installed X). You'll then want to add this to your class's using section:

 

code:

using Mastercam;

Next you'll have to make the class you (or more specifically, VS .NET) created extend the CMCNETApp. So change this:

 

code:

public class CTheClassYouCreate

{

to:

 

code:

public class CTheClassYouCreated : CMCNETApp

{

Instead of a main() method as the entry point, you have to add an ovverriden method called Run() to your class:

 

code:

public override MC_RETURN Run(System.Int32 param)

{

return MC_RETURN.MC_NOERROR;

}

Build it and you should be good to go. So for a HelloWorld Nethook:

 

code:

using System;

using System.Windows.Forms;

using Mastercam;

 

namespace HelloWorld

{

public class CHelloWorldNethook : CMCNETApp

{

public CHelloWorldNethook()

{

}

 

public override MC_RETURN Run(System.Int32 param)

{

MessageBox.Show("Hello World!");

return MC_RETURN.MC_NOERROR;

}

}

}

And like Roger mentioned, check out what's available to you in nethook.dll in the Object Browser. HTH

----------

 

I can whip you up a VB.NET version, if you wish. It basically comes down to replacing C# synatx with VB.NET (Ex:"using" -> "Imports", "override" -> "Overrides", "Implements" when subclassing, etc).

 

HTH

Link to comment
Share on other sites

Speaking of real "C" hooks (not C# or VB), I have few observations/questions.

 

I used the stub generated by the c-hook wizard without any modification, and it did not run: the message box mentioned the incompatible version number. So I created a small driver, loaded one of the provided c-hooks, called "m_version" function, and there it was: the version number should be 1001, but the macro C_H_VERSION has the value of 1000. I suppose the 1001 means version 10, service pack 1, but the SDK files have not been updated. Or is there a newer SDK, which I have not got yet?

 

My second observation is that when the dummy c-hook (with modified version number) terminates, the DLL is not unloaded properly, and is still locked. Is this a feature that would speed up subsequent loading, and if so can it be disabled? It is a big problem during the development, I can not rebuild it without shutting down the Mastercam.

 

Marko

Link to comment
Share on other sites

If you replace your m_verion routine with this -->

Your CHook will run on ANY version of X.

Note that this may not always be desirable !

IF your CHook requires a specific release !

 

code:

extern "C" __declspec(dllexport) int m_version (int version)

{

int ret = C_H_VERSION;

 

// Allow chook to run in any version of mastercam that has

// the same major version

if ( (version / 100) == (C_H_VERSION / 100) )

ret = version;

 

return ret;

}

As for the termination issue, you can try this -->

 

In your m_main replace the return MC_RETURN; with return MC_UNLOADAPP;

 

Note that is will have no effect if your CHook is loaded via an .FT file (Function Table).

Read... Your CHook DLL will not unload.

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