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:

chook question: move from m_main to m_open, m_enter, m_close


bryan314
 Share

Recommended Posts

Does anybody know the proper layout for when you go from using m_main as the entery point to m_open?

 

Do you call open_app() and close_app()

--in just m_open?

--or in all three: m_open, m_enter, m_close?

--or call open_app in m_open and close_app in m_close?

 

Any help would be appreciated.

 

Bryan smile.gif

Link to comment
Share on other sites

Dan,

 

We're talking about chook programming. The documentation has one paragraph on changing the program entry point so as to retain static variables across runs of a chook. But other than somd function names it goes into very little detail as to the new program structure. frown.gif

 

 

Bryan smile.gif

 

[ 02-19-2003, 08:56 AM: Message edited by: bryan314 ]

Link to comment
Share on other sites

Bullines is just about right. The C-hook "persists" in the sense that subsequent runs of the C-hook can remember variables, look for an open file, etc.

 

From the C-hook doc file:

 

Historically, once a C-Hook has been run and exited, it is always re-initialized when invoked again. To keep a C-Hook running, even after returning control of the interaction to Mastercam, define your main entry point as m_open( ) instead of m_main( ). This will enable the C-Hook to retain static variables. You also should provide a m_close( ) function which performs any necessary cleanup of your environment when Mastercam closes. You can optionally provide a m_enter( ) function which will be called when the C-Hook is invoked after m_open( ) was already used to open it the first time. This provides a secondary location at which to enter the C-Hook, knowing that it has already been loaded.

 

More from me :

 

So, in summary, if you want to maintain static variables in your C-hook, use m_open() instead of m_init(). This will run your C-hook, but when control is returned to Mastercam, we do not release the .DLL. You can also optionally define m_enter() to be the entry point for the 2nd (and 3rd, and 4th, etc) time your C-Hook is used. This simply lets you as a programmer govern what happens the 1st time a C-hook is used (maybe you want to initialize those statics, or open a temp file - do those with m_open) as opposed to subsequent uses of the same C-hook. As for m_close(), it will be called when Mastercam finishes so you're C-hook can clean up after itself (perhaps it can close the temp file that was opened with m_open)

How's that?

PDG

Link to comment
Share on other sites

First PDG (and everyone else) thanks for taking the time to help me out. smile.gif

 

Second what about open_app() and close_app(). When/Where are they called. Just in m_open?

 

Third. What the heck is m_init(). Did you mean m_main( )?

 

So would the code look similar to this?

 

code:

 

void your_function()

{

 

//code for first run here

 

}

 

 

void CH_ENTRY m_enter( )

{

//code run when run for second time or more time

 

}

 

 

void CH_ENTRY m_close( )

{

//clean up code for when mc closes

 

 

}

 

 

 

/************************************************/

/* do not delete m_main() */

/* M_MAIN FUNCTION */

/************************************************/

void CH_ENTRY m_open (long *ptrs)

{

if (open_app (ptrs))

if (product_level_1_or_design_enabled())

{

/* put your function here */

your_function();

}

close_app (ptrs);

}

/************************************************/

/* do not delete m_main() */

/* END M_MAIN FUNCTION */

/************************************************/

 


Bryan smile.gif

 

[ 02-19-2003, 04:00 PM: Message edited by: bryan314 ]

Link to comment
Share on other sites

PDG,

 

Does this look right?

 

code:

 

void your_function()

{

//code for first run here

}

 

void CH_ENTRY m_enter( long *ptrs )

{

if (open_app (ptrs))

//code run when run for second time or

more time

 

close_app (ptrs);

}

 

void CH_ENTRY m_close( )

{

//clean up code for when mc closes

}

 

void CH_ENTRY m_open (long *ptrs)

{

if (open_app (ptrs))

if (product_level_1_or_design_enabled())

{

/* put your function here */

your_function();

}

close_app (ptrs);

}

 


Also, is m_close( ) just m_close( ) or does it need to be m_close( long *ptrs ) ?

 

Maybe the next release of the developement kit could attach a skeleton code example in the documentation after the paragraph on this. I'm sure I'm not the only who's been confused over this. (Then again, Maybe I am the only one biggrin.gif )

 

Bryan smile.gif

Link to comment
Share on other sites
  • 1 year later...

Here is what I did to get it to work. The above information helped a bunch. Thanks all.

In my CMyDialog::OnInitDialog() function, I added a call to the following function (that has all the static vars) with a junk pointer and a handy flag that tells the function to repaint the variables (if there are any) in the dialog.

CMyDialog::LoadRoll (someptr, Flag);

The static vars in LoadRoll contain the array of parts (1 to many that were read in from a file) that I need to increment/decrement through and have drawn in a MCAM window.

Alt-C or the 2nd CREATE menu calls my chook back up to the point where I left off. I can then increment to my next part, Draw, ToolPath, Post, etc.

I modified the SHAPES.CPP and SHAPEDLG.CPP files to suit my needs

 

// Purpose: main function

 

static void chook_main (void)

{

boolean show_dialog;

Crkrolldlg dlg;

 

// Enable use of the MFC dynamically linked libraries

 

AFX_MANAGE_STATE( AfxGetStaticModuleState() );

 

show_dialog = TRUE;

undo_hold();

while (TRUE)

{

if (show_dialog)

{

if (dlg.DoModal() == IDOK) // run the dialog

{

dlg.m_RollType .MakeUpper ();

Process_Roll (Variables);

}

else // Cancel

break;

}

cleartextall();

} //while (TRUE)

} //static void chook_main (void)

 

// Purpose: Entry point for C-Hooks programs

/************************************************/

/* do not delete m_main() */

/* M_MAIN FUNCTION */

/************************************************/

extern "C" void CH_ENTRY m_open (long *ptrs)

{

if (open_app (ptrs))

chook_main();

close_app (ptrs);

}

//************************************************/

/* do not delete m_main() */

/* END M_MAIN FUNCTION */

/************************************************/

 

 

extern "C" void CH_ENTRY m_enter (long *ptrs)

{

boolean show_dialog;

Crkrolldlg dlg;

 

// Enable use of the MFC dynamically linked libraries

 

AFX_MANAGE_STATE( AfxGetStaticModuleState() );

if (open_app (ptrs))

{

show_dialog = TRUE;

undo_hold();

while (TRUE)

{

if (show_dialog)

{

if (dlg.DoModal() == IDOK) // run the dialog

{

dlg.m_RollType .MakeUpper ();

Process_Roll (Variables);

}

else // Cancel

break;

}

cleartextall();

} //while (TRUE)

}

close_app (ptrs);

} //extern "C" void CH_ENTRY m_enter (long *ptrs)

 

extern "C" void CH_ENTRY m_close (long *ptrs)

{

//if (open_app (ptrs))

//chook_main();

close_app (ptrs);

}

Link to comment
Share on other sites

Wire a little tip for you. If you would like for your code to look as it was when made in the text editor then use the code buttong and then insert the sode insdie of the 2 words like so:

code:

{Your program code here.}

 

 

{if it is indentend then like so.}

 

 

 

{if it is more then it will show up like so.}

I hope that helps. cheers.gifcheers.gif

 

Bryan wish I still had my C++ complier alot of what you are doing is making alot of sense. I still got all my old books from C++ just been so many years since I even tried to use really forgot most of it. I just hope all will still be good in X.

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