📄 hicut.cpp
字号:
// HiCut.cpp : Defines the initialization routines for the DLL.
//
#include "StdAfx.h"
#include "HiCut.h"
#include "index.h"
#include "LoginDialog.h"
#include "odbcinst.h"
#include "Afxsock.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//
// Note!
//
// If this DLL is dynamically linked against the MFC
// DLLs, any functions exported from this DLL which
// call into MFC must have the AFX_MANAGE_STATE macro
// added at the very beginning of the function.
//
// For example:
//
// extern "C" BOOL PASCAL EXPORT ExportedFunction()
// {
// AFX_MANAGE_STATE(AfxGetStaticModuleState());
// // normal function body here
// }
//
// It is very important that this macro appear in each
// function, prior to any calls into MFC. This means that
// it must appear as the first statement within the
// function, even before any object variable declarations
// as their constructors may generate calls into the MFC
// DLL.
//
// Please see MFC Technical Notes 33 and 58 for additional
// details.
//
/////////////////////////////////////////////////////////////////////////////
// CHiCutApp
//static UF_MB_cb_status_t Load_Library(
// UF_MB_widget_t widget,
// UF_MB_data_t client_data,
// UF_MB_activated_button_p_t call_button );
static int get_button_id( char *prompt, char *name, int *id )
{
int response = 0;
int len = 0;
UF_UI_lock_ug_access( UF_UI_FROM_CUSTOM );
response = uc1600( prompt, name, &len );
UF_UI_unlock_ug_access( UF_UI_FROM_CUSTOM );
if ( response == 5 || ( response == 3 && len > 0 ) )
{
int status;
response = 5;
status = UF_MB_ask_button_id( name, id );
//print_error( "UF_MB_ask_button_id", status );
if ( status != 0 )
{
char msg[133];
response = 3;
sprintf(msg, "%s button not found", name );
UF_UI_lock_ug_access( UF_UI_FROM_CUSTOM );
uc1601( msg, 0 );
UF_UI_unlock_ug_access( UF_UI_FROM_CUSTOM );
}
else
{
printf( " %s(%d)\n", name, *id );
}
}
return( response );
}
void DisplayDialog()
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());//利用该函数获得dll要使用的资源
////////////////////////////
if (!AfxSocketInit())
{
AfxMessageBox("Failed to Initialize Sockets");
}
CString sPath;
GetModuleFileName(NULL,sPath.GetBufferSetLength(MAX_PATH+1),MAX_PATH);//文件名存入sPath
sPath.ReleaseBuffer ();//释放sPath当中剩下的内存.
int nPos;
nPos=sPath.ReverseFind ('\\');//寻找SPath中最后一个'\\'的位置数.
sPath=sPath.Left (nPos);//返回sPath的前nPos个字符串.
nPos=sPath.ReverseFind('\\');
sPath=sPath.Left (nPos);
CString lpszFile = sPath + "\\UGALLIANCE\\site\\startup\\切削参数库.mdb";//得到数据库文件的路径
char* szDesc;
int mlen;
szDesc=new char[256];
sprintf(szDesc,"DSN=%s? DESCRIPTION=TOC support source? DBQ=%s? FIL=MicrosoftAccess? DEFAULTDIR=%s?? ","HiCut_data",lpszFile,sPath);
mlen = strlen(szDesc);//返回szDesc的字符数
for (int i=0; i<mlen; i++)//将szDesc中的'?'字符转换成'\0'.
{
if (szDesc[i] == '?')
szDesc[i] = '\0';
}
////建立DSN连接,出错则连接失败
if (FALSE == SQLConfigDataSource(NULL,ODBC_ADD_DSN,"Microsoft Access Driver (*.mdb)\0",(LPCSTR)szDesc))
AfxMessageBox("数据库连接失败");
////////////////////////////
CLoginDialog logindlg;
logindlg.DoModal();
}
static UF_MB_cb_status_t Load_Library(
UF_MB_widget_t widget,
UF_MB_data_t client_data,
UF_MB_activated_button_p_t call_button )
{
DisplayDialog();
return( UF_MB_CB_CONTINUE);
}
//----------------------------------------------------------------------------
// Activation Methods
//----------------------------------------------------------------------------
// Unigraphics Startup
// This entry point activates the application at Unigraphics startup
////注册
static UF_MB_action_t actionTable[]=
{
{"Load_Library",Load_Library,NULL},
{NULL,NULL,NULL}
};
//////////////////////////////////////////////////////////////////////////
extern void ufsta( char *param, int *returnCode, int rlen )//主函数
{
/* Initialize the API environment */
int errorCode = UF_initialize();
////////////
if ( 0 == errorCode )
{
/* TODO: Add your application code here */
DisplayDialog();
//UF_MB_add_actions(actionTable);
/* Terminate the API environment */
errorCode = UF_terminate();
}
}
extern int ufusr_ask_unload( void )
{
return( UF_UNLOAD_UG_TERMINATE );
}
/*--------------------------------------------------------------------------
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;
}
/////////////////////////////////////////////////////////////////////////////
// CMFCApp
BEGIN_MESSAGE_MAP(CHiCutApp, CWinApp)
//{{AFX_MSG_MAP(CHiCutApp)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CHiCutApp construction
CHiCutApp::CHiCutApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CHiCutApp object
CHiCutApp theApp;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -