工作中使用平台调用总结
2015-03-14 12:50
253 查看
1、托管代码向非托管代码传递字符串
非托管API:
extern "C" __declspec(dllexport)
int _cdeclWriteDataToFCSFile(char* FilePath);
托管:
[DllImport(_Business.dll, EntryPoint = "WriteDataToFCSFile",
CallingConvention = CallingConvention.Cdecl)]
publicexternstaticbool
WriteFCS(string FilePath,stringSampleLabel);
2、托管代码向非托管代码发送数组
非托管API:
extern "C" __declspec(dllexport)
int
_cdecl SendCommand(short ComCode,shortDstCode,short SrcCode,floatParam[],int nSize);
托管:
[DllImport(_dllName,EntryPoint ="SendCommand",CallingConvention =CallingConvention.Cdecl)]
public static
extern int SendCommand(short CmdCode,short DstDeviceCode,shortSrcDeviceCode,float[] Params,int
nSize);
3、非托管代码通过参数向托管代码传递一般类型值和数组
非托管API:
extern
"C"__declspec(dllexport)
int
_cdeclGetHardDeviceInfo(short* Order,float** OrderContent,int*nSize);//参数1返回短整型值,参数2返回浮点型数组,参数3返回整形值,该值表示参数2数组大小
托管:
[DllImport(_dllName,EntryPoint ="GetHardDeviceInfo",CallingConvention=CallingConvention.Cdecl)]
public static
extern boolGetResponse(refshortresponseCode,outIntPtrparameters,refintnSize);
//需要将数据从非托管内存指针复制到托管字符数组,关键代码如下:
if (nSize >= 0)
{
float[] paramsArray =
new float[nSize];
Marshal.Copy(parametersPtr,paramsArray, 0, nSize);
}
4、非托管代码通过返回值想托管代码传递数组
非托管API:
extern "C"__declspec(dllexport)
int* _cdecl GetTheArray(int*nSize);
托管:
[DllImport(_dllName,EntryPoint ="GetTheArray",CallingConvention =CallingConvention.Cdecl)]
unsafe publicstaticexternint* GetTheArray(ref int nSize);
使用方法举例:
unsafe
{
int* theArrayPtr;
string arrayMember =
"";
int int= 0;
theArrayPtr= BusinessCenterDLL.GetTheArray(ref nSize);
if(theArrayPtr!=
null)
{
for (int i = 0; i< nSize; i++)
{
originalCommand+= theArrayPtr[i].ToString();
originalCommand+= ",";
}
}
}
非托管API:
extern "C" __declspec(dllexport)
int _cdeclWriteDataToFCSFile(char* FilePath);
托管:
[DllImport(_Business.dll, EntryPoint = "WriteDataToFCSFile",
CallingConvention = CallingConvention.Cdecl)]
publicexternstaticbool
WriteFCS(string FilePath,stringSampleLabel);
2、托管代码向非托管代码发送数组
非托管API:
extern "C" __declspec(dllexport)
int
_cdecl SendCommand(short ComCode,shortDstCode,short SrcCode,floatParam[],int nSize);
托管:
[DllImport(_dllName,EntryPoint ="SendCommand",CallingConvention =CallingConvention.Cdecl)]
public static
extern int SendCommand(short CmdCode,short DstDeviceCode,shortSrcDeviceCode,float[] Params,int
nSize);
3、非托管代码通过参数向托管代码传递一般类型值和数组
非托管API:
extern
"C"__declspec(dllexport)
int
_cdeclGetHardDeviceInfo(short* Order,float** OrderContent,int*nSize);//参数1返回短整型值,参数2返回浮点型数组,参数3返回整形值,该值表示参数2数组大小
托管:
[DllImport(_dllName,EntryPoint ="GetHardDeviceInfo",CallingConvention=CallingConvention.Cdecl)]
public static
extern boolGetResponse(refshortresponseCode,outIntPtrparameters,refintnSize);
//需要将数据从非托管内存指针复制到托管字符数组,关键代码如下:
if (nSize >= 0)
{
float[] paramsArray =
new float[nSize];
Marshal.Copy(parametersPtr,paramsArray, 0, nSize);
}
4、非托管代码通过返回值想托管代码传递数组
非托管API:
extern "C"__declspec(dllexport)
int* _cdecl GetTheArray(int*nSize);
托管:
[DllImport(_dllName,EntryPoint ="GetTheArray",CallingConvention =CallingConvention.Cdecl)]
unsafe publicstaticexternint* GetTheArray(ref int nSize);
使用方法举例:
unsafe
{
int* theArrayPtr;
string arrayMember =
"";
int int= 0;
theArrayPtr= BusinessCenterDLL.GetTheArray(ref nSize);
if(theArrayPtr!=
null)
{
for (int i = 0; i< nSize; i++)
{
originalCommand+= theArrayPtr[i].ToString();
originalCommand+= ",";
}
}
}
相关文章推荐
- Android平台下使用lua调用Java代码经验总结
- Android平台下使用lua调用Java代码经验总结
- 工作总结-Xcode7中使用静态库环境配置手册
- cocos2d-js如何在android平台上使用js直接调用Java方法
- 在团800运维工作总结之jenkins使用
- Android 调用js,传对象到js里面使用addJavascriptInterface错误总结
- 使用Loadrunner 调用Webservice接口测试优化总结
- 工作总结-CocoaPods的安装使用和常见问题
- 说说我工作中使用的工具与平台:ActiTime、JIRA、Edraw、Axure
- 工作中使用Trepn Power Profiler的应用总结
- Linux平台Java调用so库-JNI使用例子
- Android 系统应用调用,intent 的使用方法总结
- 数据平台架构基于AWS的使用总结- Redshift优劣
- 高通平台工作总结(一)
- 高通平台工作总结(二)
- 使用平台调用(PInvoke)实现C#调用非托管C++代码
- WebView使用总结(应用函数与JS函数互相调用)
- 使用Loadrunner 调用Webservice接口测试优化总结
- 工作总结之:优化函数调用
- JniHelper调用java静态和非静态方法总结(即cocos2dx中调用android平台下显示第三方广告)