Femap开发 - API调用

  1 #include <iostream>
  2 #include <objbase.h>
  3 #include "Femap.h"
  4 #import "femap.tlb" named_guids rename("GetProp","GetFemapProp")
  5 
  6 /**
  7  * Femap的四种集成方式:
  8  *    ① 以独立的方式运行两个应用(femap和自己的app)feAppVisible(True)
  9  *    ② 把femap作为一个隐藏的服务器运行
 10  *    ③ 把自己的app作为femap的一个附加程序
 11  *    ④ 把femap嵌入到自己的app
 12  *    
 13 */
 14 int main() {
 15     // 初始化COM的运行环境,Windows提供的API函数,告诉windows以单线程的方式创建com对象。
 16     HRESULT isInitResult = CoInitialize(NULL);
 17     if(S_OK == isInitResult)
 18     {
 19         std::cout << "线程中的com库初始化成功!" << std::endl;
 20     }
 21     else
 22     {
 23         std::cout << "该线程中COM库已经被初始化!" << std::endl;
 24     }
 25 
 26     CLSID clsid;
 27     // 根据给定的程序标识符从注册表找出对应的类标识符:计算机\HKEY_CLASSES_ROOT\femap.model\CLSID
 28     // 可以作为判断是否安装femap的依据
 29     HRESULT getClassIdResult = CLSIDFromProgID(L"femap.model", &clsid);
 30     switch (getClassIdResult)
 31     {
 32     case CO_E_CLASSSTRING:
 33         std::cout << "类标识符不存在!" << std::endl;
 34         break;
 35     case REGDB_E_WRITEREGDB:
 36         std::cout << "写入类标识符到注册表时出错!" << std::endl;
 37         break;
 38     case REGDB_E_CLASSNOTREG:
 39         std::cout << "找不到对应类标识符!" << std::endl;
 40         break;
 41     default:
 42         //S_OK
 43         std::cout << "类标识符检索成功!" << std::endl;
 44         break;
 45     }
 46 
 47     // OLE自动化协议暴露出来的接口
 48     IDispatch* pDispApp;
 49 
 50     // CoCreateInstance函数需要一个CLSID参数,在此基础上创建相应组件的一个实例,并返回此组件的某个接口
 51     if (SUCCEEDED(CoCreateInstance(clsid, NULL, CLSCTX_SERVER, IID_IUnknown, (void**)&pDispApp)))
 52     {
 53         // 获取FEMAP application object的对象指针?
 54         femap::ImodelPtr m_pFemapModel = pDispApp;
 55 
 56 
 57         // Your OEM unlock code here
 58         // m_pFemapModel->feUnlockOEM(-1);
 59 
 60         // 设置femap窗口是否可见
 61         m_pFemapModel->feAppVisible(TRUE);
 62 
 63         
 64 
 65         // 通过对象指针获取femap的信息
 66         std::cout << "***** Femap Information *****" << std::endl << std::endl;
 67 
 68         std::cout << "ExePath = " + m_pFemapModel->ExePath << std::endl;
 69         std::cout << "FullScratchName: " + m_pFemapModel->FullScratchName << std::endl;
 70         std::cout << "InitializationPath = " + m_pFemapModel->InitializationPath << std::endl;
 71         std::cout << "ConfigurationPath = " + m_pFemapModel->ConfigurationPath << std::endl;
 72         std::cout << "SerialNumber = " + m_pFemapModel->SerialNumber << std::endl;
 73 
 74 
 75         // 获取femap的授权类型
 76         int        nLicenseType = 0;
 77         m_pFemapModel->feLicenseMethod(&nLicenseType);
 78         std::cout << "License Method = ";
 79         switch (nLicenseType)
 80         {
 81             case 0:    std::cout << "None"; break;
 82             case 1: std::cout << "Dongle"; break;
 83             case 2: std::cout << "Node/Curve Limited Demo"; break;
 84             case 3: std::cout << "??"; break;
 85             case 4: std::cout << "FLEXLlm Network"; break;
 86             case 5: std::cout << "API-Only"; break;
 87         }
 88         std::cout << std::endl;
 89 
 90 
 91 
 92         // 打开文件(File->Open)
 93         femap::zReturnCode result = m_pFemapModel->feFileOpen(true, "");
 94         if (result == femap::FE_OK)
 95         {
 96             std::cout << "Success to open file!" << std::endl;
 97         }
 98         else if(result == femap::FE_FAIL)
 99         {
100             std::cout << "Unable to open file!" << std::endl;
101         }
102         else if (result == femap::FE_NOT_EXIST)
103         {
104             std::cout << "Specified file does not exist!" << std::endl;
105         }
106         else
107         {
108             std::cout << "Unknown error!" << std::endl;
109         }
110         // 忽略修改,保存文件
111         m_pFemapModel->feFileClose(false);
112         m_pFemapModel->Release();
113     }
114 
115     //CoUninitialize关闭当前线程的COM库,卸载线程加载的所有dll,释放任何其他的资源,关闭在线程上维护所有的RPC连接
116     CoUninitialize();
117 }

 

posted @ 2021-11-18 09:35  禅元天道  阅读(226)  评论(0编辑  收藏  举报