C++调用C#接口dll,对dll进行注册
来源:互联网 发布:linux xargs命令 编辑:程序博客网 时间:2024/06/04 23:36
经常会有从一个应用程序同步数据到另一个应用程序的功能。比如说应用A是C++写的,所要同步的程序是用C#完成的。应用B提供了接口供第三方应用同步,接口是用C#编程的dll,那么如何成功的调用dll呢?在调用之前必须的对dll进行注册。
C# DLL为:testSync.dll
注册testSync.dll
BOOL RegisterSyncDll(){ CONST TCHAR* Dll_NAME= _T("testSync.dll"); //在exe同目录下获取dll路径CString strAppExePath;AfxGetModuleFileName(AfxGetInstanceHandle(), strAppExePath);strAppExePath = strAppExePath.Left(strAppExePath.ReverseFind(_T('\\')) + 1);CString strDllPath = strAppExePath + Dll_NAME; //获取.net framework安装路径TCHAR szSystemPath[260] = _T("");SHGetFolderPath(NULL, CSIDL_WINDOWS, NULL, 0, szSystemPath);CString strSyntemPath = szSystemPath;CString str2RegasmPath = strSyntemPath + _T("\\Microsoft.NET\\Framework\\v2.0.50727\\regasm.exe");CString str4RegasmPath = strSyntemPath + _T("\\Microsoft.NET\\Framework\\v4.0.30319\\regasm.exe"); //判断当前使用的.net framwork 版本.判断方法各不相同CString strRegasmExe;if (GetFileAttributes(str2RegasmPath) != INVALID_FILE_ATTRIBUTES){strRegasmExe = str2RegasmPath;}else if (GetFileAttributes(str4RegasmPath) != INVALID_FILE_ATTRIBUTES){strRegasmExe = str4RegasmPath;}if (strRegasmExe.IsEmpty()){ CString strNetFrameWork = RT_LoadString(_T("Message"), _T("IDS_INSTALL_NETFRAMEWOK"), NULL, _T( "Please install .net framework 2.0 or later" ); AfxMessageBox(strNetFrameWork); return FALSE;} //根据版本得出CmdLineCString strCmdLine = _T("\"") + strRegasmExe + _T("\" /c \"") + strDllPath + _T("\"");for (int i = 0; i < 2; i++){STARTUPINFO si;RtlZeroMemory(&si, sizeof(si) );si.cb = sizeof(si);si.dwFlags = STARTF_USESHOWWINDOW;si.wShowWindow = SW_HIDE;PROCESS_INFORMATION pi;RtlZeroMemory( &pi, sizeof(pi) );if (!CreateProcess( NULL, // No module name (use command line)(LPTSTR)(LPCTSTR)strCmdLine, // Command lineNULL, // Process handle not inheritableNULL, // Thread handle not inheritableFALSE, // Set handle inheritance to FALSE0, // No creation flagsNULL, // Use parent's environment blockNULL, // Use parent's starting directory &si, // Pointer to STARTUPINFO structure&pi ) // Pointer to PROCESS_INFORMATION structure) {return FALSE;}WaitForSingleObject(pi.hProcess, INFINITE );CloseHandle(pi.hProcess );CloseHandle(pi.hThread );}return TRUE;}
0 0
- C++调用C#接口dll,对dll进行注册
- C#调用C++ MFC C接口DLL
- C#调用C++DLL
- C#调用C++dll
- C#调用C++dll
- C#调用C++DLL
- c#调用c++DLL
- C# 调用C++dll
- C#调用C++DLL
- C#调用C++DLL
- C#调用C++DLL
- C#调用C++Dll
- C#调用C++DLL
- C#怎么调用dll接口
- 对C#调用C++ dll文件进行总结
- C#调用C、C++dll
- c#调用c++dll接口及回调函数
- C#调用C的DLL
- Java调用webservice接口方法
- 如何将Map转换成Gson json
- android 各类demo链接
- Java中abstract class 和 interface 的解释和他们的异同点(转)
- 杰出程序员永远都不会说的几句话
- C++调用C#接口dll,对dll进行注册
- linux修改系统时间
- Android之shape与selector实现圆角
- C语言通过关键字从文本中提取有效信息
- 轻量级web server Tornado代码分析
- poj 2021 Relative Relatives 排序
- 位运算 加减乘除 负值判断
- 用Java Socket开发小型服务器,支持上千个并发
- 使用Tornado进行网络异步编程