标题: UG二次开发时动态加载卸载dll及其他 [打印本页] 作者: huashanyjj 时间: 2004-11-19 09:07 标题: UG二次开发时动态加载卸载dll及其他 UG二次开发时,频繁启动UG非常耗时,特别是在UG1.0以后(UG1.0启动较快)。UG本身提供了这种功能:DIALOG CREATION FROM A USER EXIT,即从用户退出创建对话框。具体做法如下:
1、我们创建对话框资源时,.c文件中有如下内容:
/*-------DIALOG CREATION FROM A USER EXIT HELP Example --------
To create this dialog from a user exit, you must invoke a
call to the UG/Open API, UF_STYLER_create_dialog. An example
is shown below.
All dialog files must be located in
$UGII_USER_DIR/application or
$UGII_SITE_DIR/application or
$UGII_VENDOR_DIR/application directory
1) Remove the conditional definitions:
#ifdef DISPLAY_FROM_USER_EXIT
#endif DISPLAY_FROM_USER_EXIT
2) Add a user exit to the function name below, for example, ufusr.
3) Consider how your shared library will be unloaded. Take a look
at the generated function ufusr_ask_unload.
--------------------------------------------------------------*/
#ifdef DISPLAY_FROM_USER_EXIT
extern void <enter a valid user exit here> (char *param, int *retcode, int rlen)
{
int response = 0;
int error_code = 0;
if ( ( UF_initialize() ) != 0 )
return;
if ( ( error_code = UF_STYLER_create_dialog ( "test.dlg",
TEST_cbs, /* Callbacks from dialog */
TEST_COUNT, /* number of callbacks*/
NULL, /* This is your client data */
&response ) ) != 0 )
{
char fail_message[133];
/* Get the user function fail message based on the fail code.*/
UF_get_fail_message(error_code, fail_message);
UF_UI_set_status (fail_message);
printf ( "%s\n", fail_message );
}
UF_terminate();
return;
}
/*--------------------------------------------------------------------------
This function specifies how a shared image is unloaded from memory
within Unigraphics. This function gives you the capability to unload an
internal UG/Open application or user exit from Unigraphics. You can
specify any one of the three constants as a return value to determine
the type of unload to perform: immediately after user function
execution, via an unload selection dialog, or when Unigraphics terminates
terminates. If you choose UF_UNLOAD_SEL_DIALOG, then you have the
option to unload your image by selecting File->Utilities->Unload Shared
Image.
NOTE: A program which associates UG/Open applications with the menubar
MUST NOT use this option since it will UNLOAD your UG/Open application image
--------
from the menubar.
--------------------------------------------------------------------------*/
extern int ufusr_ask_unload (void)
{
/* unload immediately after application exits*/
return ( UF_UNLOAD_IMMEDIATELY );
/*--------------------------------------------------------------------------
You have the option of coding the cleanup routine to perform any housekeeping
chores that may need to be performed. If you code the cleanup routine, it is
automatically called by Unigraphics.
--------------------------------------------------------------------------*/
extern void ufusr_cleanup (void)
{
return;
}
#endif /* DISPLAY_FROM_USER_EXIT */