admin 发表于 2018-7-12 11:12:47

【NX二次开发源码分享】关闭NX后,做点儿事


【NX二次开发源码分享】关闭NX后,做点儿事

/*

    ufusr_ask_unload is invoked immediately following the completion of ufusr
    (or ufsta when the dll is run from a startup folder) to find out when you
    want the dll to be unloaded.If ufusr_ask_unload returns
    UF_UNLOAD_UG_TERMINATE, the ufusr_cleanup is called right before the dll is
    unload when NX is terminating.To prove to yourself that this works, set
    the environment variable UGII_KEEP_SYSTEM_LOG=1 so that the syslog will not
    automatically be cleaned up when NX terminates.Start NX.Use Help-> NX
    Log File and make a note of the full path to the syslog which will be shown
    as its own first line.Run the dll built from this code (nothing noticable
    will happen.)Exit NX.Find the syslog and open it in any text editor to
    see this line near the bottom:

NX is shutting down - running ufusr_cleanup

*/
#include <stdio.h>
#include <string.h>
#include <uf.h>
#include <uf_ui.h>
#include <uf_exit.h>

#include <stdarg.h>

static void ECHO(char *format, ...)
{
    char msg;
    va_list args;
    va_start(args, format);
    vsprintf(msg, format, args);
    va_end(args);
    UF_UI_open_listing_window();
    UF_UI_write_listing_window(msg);
    UF_print_syslog(msg, FALSE);
}

#define UF_CALL(X) (report_error( __FILE__, __LINE__, #X, (X)))

static int report_error( char *file, int line, char *call, int irc)
{
    if (irc)
    {
      char err;

      UF_get_fail_message(irc, err);
      ECHO("*** ERROR code %d at line %d in %s:\n",
            irc, line, file);
      ECHO("+++ %s\n", err);
      ECHO("%s;\n", call);
    }

    return(irc);
}

/*ARGSUSED*/
void ufusr(char *param, int *retcode, int paramLen)
{
}

/*ARGSUSED*/
void ufsta(char *param, int *retcode, int paramLen)
{
}

int ufusr_ask_unload(void)
{
    return (UF_UNLOAD_UG_TERMINATE);
}

void ufusr_cleanup(void)
{
    ECHO("NX is shutting down - running ufusr_cleanup\n");

    /* put your code here */
}

licxsw 发表于 2019-12-25 08:49:24

请问这个函数是怎么用的?有什么用?

admin 发表于 2020-2-13 08:43:55

licxsw 发表于 2019-12-25 08:49
请问这个函数是怎么用的?有什么用?

入口函数 改成 ufusr_cleanup

意思是 NX 程序退出后,你可以做些事情 ,具体做啥可以自己写,就是个入口

licxsw 发表于 2023-1-10 20:46:56

测试了 ufusr_cleanup入口处复制文件到指定目录下,不成功
页: [1]
查看完整版本: 【NX二次开发源码分享】关闭NX后,做点儿事