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:

unhandled exception with a chook


Recommended Posts

quote:

the main problem, is that the error appears when get_levname function


Are you certain that you allowed enough room for a '0' in the string name? It could be that the max_size parameter is too small for the level name. For example:

 

code:

char szSomeCharArray[7] = "Testing";  // bad

char szSomeCharArray[8] = "Testing"; // good

Link to comment
Share on other sites

Here's a slight modification of Bullines' code. It's not too pretty but compiles and runs fine on my machine. It prints the name level or error to mastercams prompt areas. See if this works any better.

 

Bryan smile.gif

 

code:

 

boolean succ;

short num_level = 1;

char Name_level[600];

 

succ = get_levname(num_level,599,Name_level);

 

if (succ == TRUE){

cleartextall();

mprintf("Successn");

mprintf("levelname:%sn",Name_level);

wait_for_space();

}

else

{

cleartextall();

mprintf("Something went wrongn");

wait_for_space();

}

 


Link to comment
Share on other sites

Thanks

it runs fine also

you know the oly difference between my code and your's is that i declared "char *Name_level" and u have declared an array!

in m_io.h, they said

 

EXTERN boolean (*_get_levname) (

short lev_num, /* I: level number */

short max_size, /* I: size of string */

char *level_name); /* O: level name (max of 'max_size' characters) */

#define get_levname (*_get_levname)

 

I don't understand why they (mastercam programmers) need to know the size of the level name if the same time they ask for an array!!?

thnk u very much

Link to comment
Share on other sites

quote:

With malloc we need to know the memory space to allocate


malloc(), on most platforms, takes only one parameter; the number of bytes to reserve. But this is besides the point wink.gif

 

quote:

No, Sorry itsn't the same thing.

With malloc we need to know the memory space to allocate dynamically, but here when we declare an array (staticaly) we know in advance the space needed!

So the max_size in get_levname function will be unused


You missed what I meant wink.gif I meant that the malloc() or memset() is likely called in Mastercam after a C-Hook developer, such as yourself, passes a var like max_size to a C-Hook function. Mastercam, in turn, probably uses malloc() or memset() internally.

Link to comment
Share on other sites

get_levname() is expecting that the programmer has declared the string size himself, i.e.

 

char lName[200];

 

or

 

char *lName = (char *)malloc(200, sizeof(char));

 

before calling the function. We will put the name in the memory that you provide. Passing the 'size' of the string ensures that we don't try to fill beyond the true length of the array

 

PDG

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