///////////////////////////////////////////////////////////////////////////// // 加载VCI组件 ///////////////////////////////////////////////////////////////////////////// void* CPlugIn::OpenVciLib(CString strInterface) { // 如果已经加载,则直接返回 if(HasLoad()) { return m_hVciHandle; } if(GetFileAttributes(m_strFile) == 0xFFFFFFFF) { OUTPUT(COLOR_ERROR, "File %s not exist!\r\n", m_strFile); return NULL; } if(m_hVciHandle == NULL) { #ifdef APPLICATION_SCRIPTDEV // 首先判断License,看是否有权限可以加载此插件 if(theApp.m_pILicense && (!IsVciLicense())) { if(theApp.m_pILicense->VerifyPluginLicense(m_strId, License::FUNC_ACTION_LOAD) != License::trOk) { OUTPUT(COLOR_ERROR, "Verify license of %s failed!\r\n", m_strId); return NULL; } // License有效性检查 theApp.m_pILicense->VerifyPluginLicense(m_strId, License::FUNC_ACTION_CHECKLICENSE); }else if(!IsVciLicense()) { OUTPUT(COLOR_ERROR, "Verify license of %s failed, not found platform license!\r\n", m_strId); return NULL; } #endif // 保存并设置当前路径 theApp.SaveAndSetCurPath(m_strFile); // 加载DLL模块 m_hVciHandle = LoadLibrary(m_strFile); // 恢复当前路径 theApp.RestoreCurPath(); } if(m_hVciHandle == NULL) { DWORD dwError = ::GetLastError(); OUTPUT(COLOR_ERROR, "Load %s fail, error code=%u!\r\n", m_strFile, dwError); } TRACE("INFO:Load VCI %s success!\n", m_strId); m_nLoadState = PLUGIN_LOAD_LIB; return m_hVciHandle; }
///////////////////////////////////////////////////////////////////////////// // 加载VCI组件 ///////////////////////////////////////////////////////////////////////////// void* CPlugIn::OpenVciLib(CString strInterface) { // 如果已经加载,则直接返回 if(HasLoad()) { return m_hVciHandle; } if(GetFileAttributes(m_strFile) == 0xFFFFFFFF) { OUTPUT(COLOR_ERROR, "File %s not exist!\r\n", m_strFile); return NULL; } if(m_hVciHandle == NULL) { // 保存并设置当前路径 theApp.SaveAndSetCurPath(m_strFile); // 加载DLL模块 m_hVciHandle = LoadLibrary(m_strFile); // 恢复当前路径 theApp.RestoreCurPath(); } if(m_hVciHandle == NULL) { DWORD dwError = ::GetLastError(); OUTPUT(COLOR_ERROR, "Load %s fail, error code=%u!\r\n", m_strFile, dwError); } TRACE("INFO:Load VCI %s success!\n", m_strId); m_nLoadState = PLUGIN_LOAD_LIB; return m_hVciHandle; }
///////////////////////////////////////////////////////////////////////////// // 创建VCI组件对象 ///////////////////////////////////////////////////////////////////////////// void* CPlugIn::CreateObject(CString strInstName) { // 检查进程标识,判断是否可以在本进程加载 if((m_strProcess != "") && (theApp.m_strProcessId != "") && (m_strProcess != theApp.m_strProcessId)) { return NULL; } // 如果未加载动态库,则先加载 if(!HasLoad()) { OpenVciLib(m_strClass); } // 动态库加载失败,则退出 if(m_hVciHandle == NULL) { return NULL; } if(strInstName != "") { for(int i=0; i<m_aVciObj.GetSize(); i++) { if(m_aVciObj[i].m_strInstName == strInstName) { m_aVciObj[i].m_nRefCount++; if(m_aVciObj[i].m_pVciObj == m_pVciObj) { m_nRefCount++; } return m_aVciObj[i].m_pVciObj; } } } #ifdef _DEBUG DWORD dwRevisionType = REVISION_TYPE_DEBUG; #else DWORD dwRevisionType = REVISION_TYPE_RELEASE; #endif; LPVOID pIVciControl = NULL; // 获取函数指针 TYPEOF_CreateObject fnCreateObject = (TYPEOF_CreateObject)GetProcAddress(m_hVciHandle, "CreateObject"); LPVOID lpVciObj = fnCreateObject(m_strClass, &pIVciControl, NULL); if(lpVciObj == NULL) { return NULL; } // 设置平台接口 if(pIVciControl) { ((IVciControl*)pIVciControl)->setIPlatUI(theApp.GetIPlatUI()); } // 设置语言 if(pIVciControl) { ((IVciControl*)pIVciControl)->SetLanguage( (LANGUAGE_PAGE_CHINESE == theApp.m_curLanguage) ? LANGUAGE_CHINESE : LANGUAGE_ENGLISH); } // 安装调试回调函数 if(pIVciControl) { TInitData_DebugOut InitData_DebugOut; InitData_DebugOut.lpfnDebugOut = callback_Vci_DebugOut; InitData_DebugOut.strComponentId = m_strId; InitData_DebugOut.lpVciInstance = NULL; InitData_DebugOut.nDeviceID = 0; ((IVciControl*)pIVciControl)->InstallHandler(DEBUG_OUT_EVENT, callback_Vci_DebugOut, (DWORD)(&InitData_DebugOut)); } if(m_strType == "interp") { IInterp* pIInterp = (IInterp*)lpVciObj; // 设置平台接口 pIInterp->SetIPlatUI(theApp.GetIPlatUI()); // 设置解释器名为VCI实例名 pIInterp->SetInterpName(strInstName); } CVciObject obj; obj.m_pVciObj = lpVciObj; obj.m_pIVciControl = pIVciControl; obj.m_strInstName = strInstName; obj.m_nRefCount = 1; m_aVciObj.Add(obj); // 初始化全局变量 if(m_pVciObj == NULL) { m_pVciObj = lpVciObj; m_pIVciControl = pIVciControl; m_nRefCount = 1; } // 执行组件的初始化操作(OWM组件在OWM的加载函数中执行初始化) if(pIVciControl && !IsVciOwm()) { ((IVciControl*)pIVciControl)->Init(m_strInitParam); } //CTime tBuild = GetPluginBuildTime(); //TRACE("PlugIn %s build date is %s.\n", m_strId, tBuild.Format("%Y-%m-%d %H:%M:%S")); return lpVciObj; }