cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Visit the PTCooler (the community lounge) to get to know your fellow community members and check out some of Dale's Friday Humor posts! X

User_terminate

Ketan_Lalcheta
19-Tanzanite

User_terminate

Hello,

I am aware that user_terminate is the function where toolkit application scope ends. What I would like to do is that based on certain conditions I am planning to do in user_terminate, DLL scope sholud not be ended.

Any suggestion would be much helpful.

Let me know in case you require more explanation on this query.

Thanks and Regards

Ketan


This thread is inactive and closed by the PTC Community Management Team. If you would like to provide a reply and re-open this thread, please notify the moderator and reference the thread. You may also use "Start a topic" button to ask a new question. Please be sure to include what version of the PTC product you are using so another community member knowledgeable about your version may be able to assist.
ACCEPTED SOLUTION

Accepted Solutions

I think I understand now.

First the chances that two users are trying to write to the log file in the exact same time are really small.

In the situation that simultaneous writing do happen I'd try to create a delay for one of the users.

Try the following code:

void user_terminate()
{
     ProUIMessageButton *buttons;
     ProUIMessageButton user_choice;
        Pro
     ProArrayAlloc (2, sizeof (ProUIMessageButton), 1, (ProArray*)&buttons);
     buttons[0] = PRO_UI_MESSAGE_RETRY;
     buttons[1] = PRO_UI_MESSAGE_IGNORE;

     do
               /* log writing here */
          ProUIMessageDialogDisplay (PROUIMESSAGE_ERROR,L"Message Title",L"Some message!",buttons,PRO_UI_MESSAGE_OK,&user_choice);

     while ( user_choice != PRO_UI_MESSAGE_IGNORE ) ;

     ProArrayFree ((ProArray*)&buttons);
     
     return;
}

It is very crude but I hope you will get the ideea.

You will have to put log writing sequence inside the do - while loop and to set the correct exit condition.

View solution in original post

10 REPLIES 10

If I understood correctly what you are trying to do is to prevent the toolkit application to stop unless certain conditions are meet. I'm afraid that is not possible.

"user_terminate" is a void function. That mean there is no specific return value when exiting the function. Simply said there is no way to make the difference if the exit condition is true or false.

Based on the information on the user guide; "user_terminate" is executed every time the applications end. It is a good place to do some "clean-up" like deleting user-defined menus, deleting temporary files, freeing up globally defined arrays and other thing of that nature.

The important note here is that the toolkit application will end no matter the actions defined in "user_terminate" and the outcome of those actions.

Correct... I would like Auxiliary application I.e. toolkit application still be available to user based on condition from user_terminate.

Okay...seems it's not possible.. One thing I would try to check if I can still call user_initialize from user_terminate itself so that user gets feel of running application even if user_terminate is called.

Any thought on this?

Thanks and Regards

Ketan

Calling user_initalize from within the application has a high risk to lead to infinite loops, memory overflows or other things like that. I'm not saying it won't work as I never tried but personally I'd avoid this at any cost.

In a situation similar with the one you described I think I'd take a somewhat opposite approach:

1. Make sure the users can't stop the application. For this you need to remove "ALLOW_STOP" and "DELAY_START" lines from the toolkit registry file.

2. Control when the commands defined by the application are available via the uiCmdAccessState functions. Let's say you define a command with the following line:

ProCmdActionAdd("NewCommand", (uiCmdCmdActFn)NewCmdFunction,        uiProe2ndImmediate,AccessFunction, PRO_B_TRUE, PRO_B_TRUE, &cmd_id);

The "AccessFunction" argument is the uiCmdAccessState function. Here you can define the conditions if the new command is available or not.

For example you can make a certain function to be available only for drawings.

Take a look at the documentation and the sample application. There are some good example of access functions there.

Totally agree with what you suggested... But I have different pain area. I would like end user to start and stop application. Plus I do not want to provide or remove functionality from user_terminate.

Let me tell you my thoughts if doing something on user_terminate. What additional thing I would like to do from application is to append application data(file name, user name etc) in a log file on shared location. Btthis data will get written when user stops application. Chances are there that other user is already stopped application and log file is in use. So, I want new user to ask him to stop for a while evenif user_terminate is called to write his log... I hope I have explained my pain area.

Any thoughts would behelpful..

I think I understand now.

First the chances that two users are trying to write to the log file in the exact same time are really small.

In the situation that simultaneous writing do happen I'd try to create a delay for one of the users.

Try the following code:

void user_terminate()
{
     ProUIMessageButton *buttons;
     ProUIMessageButton user_choice;
        Pro
     ProArrayAlloc (2, sizeof (ProUIMessageButton), 1, (ProArray*)&buttons);
     buttons[0] = PRO_UI_MESSAGE_RETRY;
     buttons[1] = PRO_UI_MESSAGE_IGNORE;

     do
               /* log writing here */
          ProUIMessageDialogDisplay (PROUIMESSAGE_ERROR,L"Message Title",L"Some message!",buttons,PRO_UI_MESSAGE_OK,&user_choice);

     while ( user_choice != PRO_UI_MESSAGE_IGNORE ) ;

     ProArrayFree ((ProArray*)&buttons);
     
     return;
}

It is very crude but I hope you will get the ideea.

You will have to put log writing sequence inside the do - while loop and to set the correct exit condition.

Another possible solution would be the usage of a database, or a diff file if file get already worked that get joined on a later procedure.

Hi Ketan -

I may have misunderstood, but I think there is a simple solution to at least one of your problems.

Ketan Lalcheta wrote:

Totally agree with what you suggested... But I have different pain area. I would like end user to start and stop application. Plus I do not want to provide or remove functionality from user_terminate.

In your registry (.dat) file, each application has an option called allow_stop :

If you set this to TRUE, you can stop the application during the session. If this field is missing or is set to FALSE, you cannot stop the application, regardless of how it was started.

Does setting allow_stop to FALSE resolve that problem for you?

I agree Gabriel that you shouldn't attempt to circumvent user_terminate. That function must execute correctly when the user quits Creo Parametric.

|+|  M a r k  |+|

Hi

Once application is running into creo and if I go to .dat file and set allow_stop to false, would it result that user cannot stop application at all? Only option is to close creo session only?

Ketan -

I don't remember ever setting allow_stop to false, but...

[...] would it result that user cannot stop application at all? Only option is to close creo session only?

Your summary is correct, as far as I know.

There are two things you should be aware of:

  1. Nobody is a perfect programmer. If your application somehow causes problems for your Creo users, then they have a good reason to stop the program. If you prevent them from stopping the program, it will cause harm to their employer and your reputation.
  2. A determined and knowledgeable user could either edit the .dat file or copy it to run your program under a different name.

The best way to write these tools is to make them useful to your end users. It's much less helpful if you write code tries to "stop" them from doing their jobs creatively.

|+|  M a r k  |+|

Good points Mark. I totally agree.

The end user of my programs are most often my fellow coworkers. Some of them may use 2 or 3 different programs on a single day. Being able to start and stop the applications as they need make everyone's life more easier.

Announcements


Top Tags