C++/C#结构体转化-传string给C++
2015-11-10 14:47
519 查看
此例是把C#结构传给C++
C++:
typedef struct VidyoClientInEventGroupChat_
{
/*! Message (contents) to be sent to all remote participants */
char message[MAX_CHAT_MESSAGE_LEN];
} VidyoClientInEventGroupChat;
C#:
[StructLayout(LayoutKind.Sequential)]
public struct VidyoClientInEventGroupChat
{
unsafe fixed byte message[MAX_CHAT_MESSAGE_LEN];
public unsafe bool SetMessage(string message)
{
byte[] bytes = UnicodeStringToUtf8Array(message);
if (bytes.Length > MAX_CHAT_MESSAGE_LEN)
{
return false;
}
fixed (VidyoClientInEventGroupChat* p = &this)
for (int i = 0; i < bytes.Length; i++)
{
p->message[i] = bytes[i];
}
return true;
}
};
C++:
typedef struct VidyoClientInEventGroupChat_
{
/*! Message (contents) to be sent to all remote participants */
char message[MAX_CHAT_MESSAGE_LEN];
} VidyoClientInEventGroupChat;
C#:
[StructLayout(LayoutKind.Sequential)]
public struct VidyoClientInEventGroupChat
{
unsafe fixed byte message[MAX_CHAT_MESSAGE_LEN];
public unsafe bool SetMessage(string message)
{
byte[] bytes = UnicodeStringToUtf8Array(message);
if (bytes.Length > MAX_CHAT_MESSAGE_LEN)
{
return false;
}
fixed (VidyoClientInEventGroupChat* p = &this)
for (int i = 0; i < bytes.Length; i++)
{
p->message[i] = bytes[i];
}
return true;
}
};
相关文章推荐
- C/C++ Volatile关键词深度剖析
- C++/C#结构体转化-二维数组-bytes To Strings
- C语言中Static和Const关键字的的作用
- C++语言中四大转换算子static_cast ,const_cast,reinterpret_cast,dynamic_cast
- [C++] Type Conversion(类型转换)
- C++命名规则
- C++中将数据保存成jpg格式图片
- C语言拼接字符串和整型
- python调用C++编写的DLL
- C++中成员以其在类中声明的顺序构造
- C++轻量级日志类CLogger的使用(更新)
- C++中replace()函数使用方法汇总
- C++输入一个字符串,将其逆序输出
- 关于C++调用Python
- 浅谈C++中replace()方法
- 初识c++,复数类
- c++ 初始化两个vector对象,
- 一个好玩的计算题目(c++ 位运算)
- C++基础::自制异常定位器
- 黑马程序员——C语言基础01—C语言概述