From f83919c0a2493876e4060fa89c831714c98f5406 Mon Sep 17 00:00:00 2001 From: thinking Date: Fri, 16 Mar 2018 20:02:18 +0800 Subject: [PATCH 1/2] load module name --- bin/Debug/mainmoduleconfig.json | 8 ++++---- bin/mainmoduleconfig.json | 8 ++++---- comenv/comenv.cpp | 24 ++++++++++++++++++------ comenv/comenv.h | 1 + 4 files changed, 27 insertions(+), 14 deletions(-) diff --git a/bin/Debug/mainmoduleconfig.json b/bin/Debug/mainmoduleconfig.json index 71d8b5ee..90d44516 100644 --- a/bin/Debug/mainmoduleconfig.json +++ b/bin/Debug/mainmoduleconfig.json @@ -1,7 +1,7 @@ { "commodule":{ "basecom": [ - {"components_path":"infoanalysis.dll","clsidinclude": + {"components_path":"infoanalysis","clsidinclude": [ { "clsid":"{E2C3154C-AFC7-4875-8BCC-CB116CA0CF45}", @@ -12,7 +12,7 @@ } ] }, - {"components_path":"asynio.dll","clsidinclude": + {"components_path":"asynio","clsidinclude": [ { "clsid":"{B6DDB9B0-186F-4199-A0B3-7BA5026F5888}", @@ -23,7 +23,7 @@ } ] }, - {"components_path":"maincom.dll","clsidinclude": + {"components_path":"maincom","clsidinclude": [ { "clsid":"{764607A4-158C-4539-BD37-30B6983BE387}", @@ -36,7 +36,7 @@ } ], "maincom": - {"components_path":"comenv.dll","clsidinclude": + {"components_path":"comenv","clsidinclude": [ { "clsid":"{C8CA7580-8E65-49e6-A66A-B087C7EF523D}", diff --git a/bin/mainmoduleconfig.json b/bin/mainmoduleconfig.json index 991aed84..f1dda6af 100644 --- a/bin/mainmoduleconfig.json +++ b/bin/mainmoduleconfig.json @@ -1,7 +1,7 @@ { "commodule":{ "basecom": [ - {"components_path":"libinfoanalysis.so","clsidinclude": + {"components_path":"infoanalysis","clsidinclude": [ { "clsid":"{E2C3154C-AFC7-4875-8BCC-CB116CA0CF45}", @@ -12,7 +12,7 @@ } ] }, - {"components_path":"libasynio.so","clsidinclude": + {"components_path":"asynio","clsidinclude": [ { "clsid":"{B6DDB9B0-186F-4199-A0B3-7BA5026F5888}", @@ -23,7 +23,7 @@ } ] }, - {"components_path":"libsshchannel.so","clsidinclude": + {"components_path":"sshchannel","clsidinclude": [ { "clsid":"{4A27FA11-BEA7-46E8-9F32-EC0C9F6E1A9E}", @@ -36,7 +36,7 @@ } ], "maincom": - {"components_path":"libcomenv.so","clsidinclude": + {"components_path":"comenv","clsidinclude": [ { "clsid":"{C8CA7580-8E65-49e6-A66A-B087C7EF523D}", diff --git a/comenv/comenv.cpp b/comenv/comenv.cpp index e577ef49..7187c458 100644 --- a/comenv/comenv.cpp +++ b/comenv/comenv.cpp @@ -432,10 +432,8 @@ HRESULT ComEnv::InsertCacheList(char* pClsid, char* pName, char* pParam, char* p } -HRESULT ComEnv::RegisterModule(const TCHAR* pCompoents_path) +tstring ComEnv::ModuleToPath(const TCHAR* pCompoents_path) { - retrtpv(pCompoents_path,E_FAIL); - HRESULT hr = S_OK; tstring stringpath = GetCurrentRunPath(m_hInstance); @@ -444,13 +442,27 @@ HRESULT ComEnv::RegisterModule(const TCHAR* pCompoents_path) stringpath += _T("\\"); #elif __GNUC__ stringpath += _T("//"); + stringpath += _T("lib"); +#endif // __GNUC__ + stringpath += pCompoents_path; + +#ifdef _MSC_VER + stringpath += _T(".dll"); +#elif __GNUC__ + stringpath += _T(".so"); #endif // __GNUC__ + return stringpath; +} +HRESULT ComEnv::RegisterModule(const TCHAR* pCompoents_path) +{ + retrtpv(pCompoents_path,E_FAIL); + HRESULT hr = S_OK; - stringpath += pCompoents_path; + tstring modpath = ModuleToPath(pCompoents_path); CComLoader comLoader; - BOOL bLoad = comLoader.LoadCom(stringpath.c_str()); + BOOL bLoad = comLoader.LoadCom(modpath.c_str()); if(!bLoad) { return E_FAIL; @@ -468,7 +480,7 @@ HRESULT ComEnv::RegisterModule(const TCHAR* pCompoents_path) { CLSID clsid = comLoader.GetAt(lplugin); LPCSTR lpProgId = comLoader.ProgIDFromCLSID(clsid); - m_pOlManager->Register(clsid, stringpath.c_str()); + m_pOlManager->Register(clsid, modpath.c_str()); if(pOlManagerEx && lpProgId && *lpProgId) pOlManagerEx->SetProgId(clsid, lpProgId); } diff --git a/comenv/comenv.h b/comenv/comenv.h index db62ff64..14239e4d 100644 --- a/comenv/comenv.h +++ b/comenv/comenv.h @@ -100,6 +100,7 @@ private: HRESULT LoadProjectSetting(); + tstring ModuleToPath(const TCHAR* pCompoents_path); HRESULT RegisterModule(const TCHAR* pCompoents_path); HRESULT InsertCacheList(char* pClsid, -- Gitee From ac0879b420748a33d3fb059d2240d6bbd91e1673 Mon Sep 17 00:00:00 2001 From: thinking Date: Fri, 16 Mar 2018 20:18:05 +0800 Subject: [PATCH 2/2] modnametomodpath --- include/compat/getpath.hpp | 277 ++++++++++++++++++++----------------- main/main.cpp | 128 ++++++++--------- 2 files changed, 206 insertions(+), 199 deletions(-) diff --git a/include/compat/getpath.hpp b/include/compat/getpath.hpp index 899276c4..3ed36ffe 100644 --- a/include/compat/getpath.hpp +++ b/include/compat/getpath.hpp @@ -1,127 +1,150 @@ -#ifndef _COMPAT_GETPATH_H_ -#define _COMPAT_GETPATH_H_ - -#include -#include - -#define TAG_XML_BUF "<" -#define TAG_JSON_BUF "{" - -inline static bool IsXmlBuf(const char* lpFile) -{ - if (NULL == lpFile || 0x00 == (*lpFile)) - return false; - if (0 == string_stricmp(lpFile, TAG_XML_BUF)) - { - return true; - } - return false; -} -inline static bool IsJsonBuf(const char* lpFile) -{ - if (NULL == lpFile || 0x00 == (*lpFile)) - return false; - if (0 == string_stricmp(lpFile, TAG_JSON_BUF)) - { - return true; - } - return false; -} - - -inline static bool FileIsExist(LPCTSTR lpFile) -{ - if(NULL == lpFile || 0x00 == (*lpFile )) - return false; - -#ifndef __GNUC__ - DWORD dwAttributes = GetFileAttributes(lpFile); - if(0xFFFFFFFF == dwAttributes || dwAttributes&FILE_ATTRIBUTE_DIRECTORY) - return false; -#else - int fd = access (lpFile, F_OK); - if(fd < 0) - return false; -#endif - - - return true; -} - -#ifdef __cplusplus -inline static tstring GetCurrentRunPath(HINSTANCE hInstance) -{ - - tstring strrunpath; - strrunpath.clear(); -#ifndef __GNUC__ - TCHAR szBuf[MAX_PATH*2 + 1] = {0x00}; - ::GetModuleFileNameW(hInstance, szBuf, MAX_PATH*2); - - if(tstring_strlen(szBuf) <= 0) - return _T(""); - - tstring strBuf = szBuf; - size_t npos = strBuf.rfind(_T("\\")); - strrunpath = strBuf.substr(0, npos); - -#else - - TCHAR szBuf[MAX_PATH*2 + 1] = {0x00}; - - int npos = -1; - - //int nCount = readlink("/proc/self/exe", szBuf, MAX_PATH*2); - - - pid_t cur_pid = getpid(); - char cur_exe_link[256] = {0}; - sprintf(cur_exe_link, "/proc/%u/exe", cur_pid); - int nCount = readlink(cur_exe_link, szBuf, MAX_PATH*2); - - - if(nCount < 0 || nCount > MAX_PATH) - { - return ""; - } - szBuf[nCount] = _T('0'); - - if(string_strlen(szBuf) <= 0) - return _T(""); - - std::string strBuf; - strBuf.assign(szBuf); - npos = strBuf.find_last_of('/'); - strrunpath = strBuf.substr(0, npos); - -#endif - - - return strrunpath; -} - -#ifndef __GNUC__ - #define path_slash _T("\\") -#else - #define path_slash _T("/") -#endif - - -inline static tstring GetCurAbsolutepath(tstring curpath,tstring dir) -{ - curpath +=path_slash; - curpath += dir; - return curpath; -} - -#endif - - - - - - - - - -#endif +#ifndef _COMPAT_GETPATH_H_ +#define _COMPAT_GETPATH_H_ + +#include +#include + +#define TAG_XML_BUF "<" +#define TAG_JSON_BUF "{" + +inline static bool IsXmlBuf(const char* lpFile) +{ + if (NULL == lpFile || 0x00 == (*lpFile)) + return false; + if (0 == string_stricmp(lpFile, TAG_XML_BUF)) + { + return true; + } + return false; +} +inline static bool IsJsonBuf(const char* lpFile) +{ + if (NULL == lpFile || 0x00 == (*lpFile)) + return false; + if (0 == string_stricmp(lpFile, TAG_JSON_BUF)) + { + return true; + } + return false; +} + + +inline static bool FileIsExist(LPCTSTR lpFile) +{ + if(NULL == lpFile || 0x00 == (*lpFile )) + return false; + +#ifndef __GNUC__ + DWORD dwAttributes = GetFileAttributes(lpFile); + if(0xFFFFFFFF == dwAttributes || dwAttributes&FILE_ATTRIBUTE_DIRECTORY) + return false; +#else + int fd = access (lpFile, F_OK); + if(fd < 0) + return false; +#endif + + + return true; +} + +#ifdef __cplusplus +inline static tstring GetCurrentRunPath(HINSTANCE hInstance) +{ + + tstring strrunpath; + strrunpath.clear(); +#ifndef __GNUC__ + TCHAR szBuf[MAX_PATH*2 + 1] = {0x00}; + ::GetModuleFileNameW(hInstance, szBuf, MAX_PATH*2); + + if(tstring_strlen(szBuf) <= 0) + return _T(""); + + tstring strBuf = szBuf; + size_t npos = strBuf.rfind(_T("\\")); + strrunpath = strBuf.substr(0, npos); + +#else + + TCHAR szBuf[MAX_PATH*2 + 1] = {0x00}; + + int npos = -1; + + //int nCount = readlink("/proc/self/exe", szBuf, MAX_PATH*2); + + + pid_t cur_pid = getpid(); + char cur_exe_link[256] = {0}; + sprintf(cur_exe_link, "/proc/%u/exe", cur_pid); + int nCount = readlink(cur_exe_link, szBuf, MAX_PATH*2); + + + if(nCount < 0 || nCount > MAX_PATH) + { + return ""; + } + szBuf[nCount] = _T('0'); + + if(string_strlen(szBuf) <= 0) + return _T(""); + + std::string strBuf; + strBuf.assign(szBuf); + npos = strBuf.find_last_of('/'); + strrunpath = strBuf.substr(0, npos); + +#endif + + + return strrunpath; +} + +#ifndef __GNUC__ + #define path_slash _T("\\") +#else + #define path_slash _T("/") +#endif + + +inline static tstring GetCurAbsolutepath(tstring curpath,tstring dir) +{ + curpath +=path_slash; + curpath += dir; + return curpath; +} + + + +inline static tstring ModNameToModPath(const TCHAR* pName) +{ + tstring stringpath; + stringpath.clear(); + +#ifdef _MSC_VER + stringpath += _T("\\"); +#elif __GNUC__ + stringpath += _T("//"); + stringpath += _T("lib"); +#endif // __GNUC__ + stringpath += pName; +#ifdef _MSC_VER + stringpath += _T(".dll"); +#elif __GNUC__ + stringpath += _T(".so"); +#endif // __GNUC__ + + return stringpath; +} + +#endif + + + + + + + + + +#endif diff --git a/main/main.cpp b/main/main.cpp index 9c0547dc..18cb5ff6 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -1,72 +1,56 @@ -#include "stdafx.h" -#include -#include -#include -#include - - - -int WINAPI WinMain( HINSTANCE hInstance, - HINSTANCE hPrevInstance, - LPSTR lpCmdLine, - int nCmdShow) -{ - - - HRESULT hr = S_OK; - CComLoader loader; - _lComPtr pIComEnv; - tstring stringcomenv; - tstring stringpath = GetCurrentRunPath(NULL); - - tstring stringconfig; - -#ifndef __GNUC__ - stringpath += _T("\\"); -#else - stringpath += _T("//"); -#endif - - stringcomenv = stringpath; - stringconfig = stringpath; - stringconfig += _T("mainmoduleconfig.json"); - -#ifndef __GNUC__ - stringcomenv += _T("comenv.dll"); -#else - stringcomenv += _T("libcomenv.so"); -#endif - - printf("11\n"); - BOOL bRet = loader.LoadCom(stringcomenv.c_str()); - - if (bRet == TRUE) - loader.CreateInstance(CLSID_ComEnv,NULL,NULL,re_uuidof(IComEnv),(void**)&pIComEnv.m_p); - - if (pIComEnv.m_p != NULL) - { - hr = pIComEnv->InitEnv(TRUE, hInstance, stringconfig.c_str(), NULL, NULL); - if (hr == S_OK) - { - pIComEnv->Run(); - } - } - return 1; -} - - -#ifdef _MSC_VER - - -#endif - - -#ifdef __GNUC__ - - int main(int argc,char* argv[]) - { - return WinMain(0,0,argv[0],0); - } -#endif - - +#include "stdafx.h" +#include +#include +#include +#include + +int WINAPI WinMain( HINSTANCE hInstance, + HINSTANCE hPrevInstance, + LPSTR lpCmdLine, + int nCmdShow) +{ + HRESULT hr = S_OK; + CComLoader loader; + _lComPtr pIComEnv; + tstring stringcomenv; + tstring stringpath = GetCurrentRunPath(NULL); + tstring stringconfig; + stringpath += path_slash; + stringcomenv = stringpath; + stringconfig = stringpath; + stringconfig += _T("mainmoduleconfig.json"); + stringcomenv += ModNameToModPath(_T("comenv")); + + printf("11\n"); + BOOL bRet = loader.LoadCom(stringcomenv.c_str()); + + if (bRet == TRUE) + loader.CreateInstance(CLSID_ComEnv,NULL,NULL,re_uuidof(IComEnv),(void**)&pIComEnv.m_p); + + if (pIComEnv.m_p != NULL) + { + hr = pIComEnv->InitEnv(TRUE, hInstance, stringconfig.c_str(), NULL, NULL); + if (hr == S_OK) + { + pIComEnv->Run(); + } + } + return 1; +} + + +#ifdef _MSC_VER + + +#endif + + +#ifdef __GNUC__ + + int main(int argc,char* argv[]) + { + return WinMain(0,0,argv[0],0); + } +#endif + + -- Gitee