/*****************************************************************************
**
** NX8 Open Wizard8.cpp
**
** Description:
** Contains Unigraphics entry points for the application.
**
*****************************************************************************/
/* Include files */
#if ! defined ( __hp9000s800 ) && ! defined ( __sgi ) && ! defined ( __sun )
# include <strstream>
# include <iostream>
using std::ostrstream;
using std::endl;
using std::ends;
using std::cerr;
#else
# include <strstream.h>
# include <iostream.h>
#endif
#include <uf.h>
#include<atlbase.h>
#include <uf_ui.h>
#include <uf_exit.h>
#include <string>
#include <io.h>
#include <iostream>
#include <fstream>
using namespace std;
#include<Windows.h>
#include <uf_defs.h>
#include <NXOpen/NXException.hxx>
#include <NXOpen/Session.hxx>
#include <NXOpen/Part.hxx>
#include <NXOpen/PartCollection.hxx>
#include <NXOpen/Preferences_SessionPreferences.hxx>
#include <NXOpen/Preferences_SessionVisualizationEmphasis.hxx>
#include <NXOpen/Session.hxx>
#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],
msg[133];
sprintf(msg, "*** ERROR code %d at line %d in %s:\n+++ ",
irc, line, file);
UF_get_fail_message(irc, err);
UF_print_syslog(msg, FALSE);
UF_print_syslog(err, FALSE);
UF_print_syslog("\n", FALSE);
UF_print_syslog(call, FALSE);
UF_print_syslog(";\n", FALSE);
if (!UF_UI_open_listing_window())
{
UF_UI_write_listing_window(msg);
UF_UI_write_listing_window(err);
UF_UI_write_listing_window("\n");
UF_UI_write_listing_window(call);
UF_UI_write_listing_window(";\n");
}
}
return(irc);
}
/*****************************************************************************
** Activation Methods
*****************************************************************************/
/* Explicit Activation
** This entry point is used to activate the application explicitly, as in
** "File->Execute UG/Open->User Function..." */
std::string TCHAR2STRING(TCHAR* STR)
{
int iLen = WideCharToMultiByte(CP_ACP, 0, STR, -1, NULL, 0, NULL, NULL);
char* chRtn = new char[iLen * sizeof(char)];
WideCharToMultiByte(CP_ACP, 0, STR, -1, chRtn, iLen, NULL, NULL);
std::string str(chRtn);
return str;
}
获取当前DLL路径
std::string ask_current_dll_file()
{
TCHAR szdllpath[257];
GetModuleFileName(_AtlBaseModule.GetModuleInstance(), szdllpath, 256);
std::string DLLlujin = TCHAR2STRING(szdllpath);
int last1 = (int)DLLlujin.find_last_of("\\");
DLLlujin = DLLlujin.substr(0, last1 + 1);
return DLLlujin;
}
typedef void (WINAPI* MyFun)(char const*);
extern DllExport void ufusr( char *parm, int *returnCode, int rlen )
{
/* Initialize the API environment */
if( UF_CALL(UF_initialize()) )
{
/* Failed to initialize */
return;
}
/* TODO: Add your application code here */
string dllPath = ask_current_dll_file();
dllPath += "define.macro";
uc1601((char*)dllPath.c_str(),1);
/*auto libugui = LoadLibrary((LPCWSTR)"libugui.dll");
if (libugui==NULL)
{
uc1601("c",1);
}*/
MyFun fun = NULL;
HINSTANCE hHandle = NULL;
hHandle = LoadLibraryA("libugui.dll");
// ?MACRO_playback_from_usertool@@YAXPEBD@Z
fun = (MyFun)::GetProcAddress(hHandle, "?MACRO_playback_from_usertool@@YAXPEBD@Z");
if (fun != NULL)
{
fun(dllPath.c_str());
}
/* Terminate the API environment */
UF_CALL(UF_terminate());
}
/*****************************************************************************
** Utilities
*****************************************************************************/
/* Unload Handler
** This function specifies when to unload your application from Unigraphics.
** If your application registers a callback (from a MenuScript item or a
** User Defined Object for example), this function MUST return
** "UF_UNLOAD_UG_TERMINATE". */
extern int ufusr_ask_unload( void )
{
return( UF_UNLOAD_IMMEDIATELY );
}
调用NX宏录制 .macro文件
于 2023-04-25 11:04:53 首次发布