UG二次開發:UF_load_library的用法範例

來源:互聯網
上載者:User

UF_load_library可以用來載入共用庫檔案並發現指定的入口地址。

從功能上來說類似於GetProcAddress,不過用UF_load_library則不需要去手工載入dll檔案,一步到位。

 

範例源碼如下:

/*****************************************************************************ufd_load_library.c本檔案將示範如何使用以下的 UG/Open API 函數(s):    UF_load_libraryUF_unload_library描述:    UF_load_library 載入library_name指定的共用庫,並發現由symbol_name指定的進入點。不難看出它有些類似於GetProcAddress,但使用更簡單,當然也僅僅適應於UF/Open API範疇。環境:    VS2008編譯,在NX 4.0/NX 6.0上測試通過。曆史:   日期            作者              備忘2010-11-02       zale_lzj            建立*****************************************************************************/#include <stdio.h>#include <uf.h>#include <uf_defs.h>#include <uf_exit.h>#include <uf_part.h>#include <uf_ui.h>#pragma comment(lib, "libufun.lib")#pragma comment(lib, "libugopenint.lib")#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[133], messg[300];        logical response;UF_UI_is_listing_window_open(&response);if (!response)UF_UI_open_listing_window();        UF_get_fail_message(irc, err);        sprintf_s(messg, 300, "\n%s\nerror %d at line %d in %s\n%s",            err, irc, line, file, call);        UF_UI_write_listing_window(messg);UF_UI_write_listing_window("\n");    }    return(irc);}static void do_it(void){typedef void (*load_ufusr_f_p_t)(char* param, int* retcode, int paramLen);load_ufusr_f_p_t load_ufusr_ptr = NULL;char* file_path = "C:\\Program Files\\UGS\\NX 4.0\\TOOLING_BASE\\application\\ugmold_view.dll";int irc = UF_CALL(UF_load_library(file_path, "ufusr", (UF_load_f_p_t*)&load_ufusr_ptr));if (load_ufusr_ptr != NULL){int retcode;load_ufusr_ptr("", &retcode, 0);}if (irc != 0){uc1601("failed load", 1);UF_CALL(UF_unload_library(file_path)); // 注意該語句只能在失敗時被調用,否則UG會退出return;}}void ufusr(char *param, int *retcode, int paramLen){    if (UF_CALL(UF_initialize())) return;if (UF_PART_ask_display_part() != NULL_TAG)do_it();elseuc1601("No active part", 1);    UF_terminate();}int ufusr_ask_unload(void){    return (UF_UNLOAD_IMMEDIATELY);}void ufusr_cleanup (void){    return;}

以上代碼將調用Mold Wizard裡的可見度管理功能。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.