如何将VC7中的char * 数组转换为c#中的byte[],大家赶快支援!!

u_u_u 2003-01-17 11:35:06
如何将VC7中的char * 数组转换为c#中的byte[],大家赶快支援!!
需要在VC7中调用C#中的方法int setValue( byte[] buf ),苦苦思索,找不到办法,只好紧急求援,拜托大家了!
...全文
44 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
u_u_u 2003-01-21
  • 打赏
  • 举报
回复
to masterz(MS MVP)

谢谢,搞定,我的联系方法为u_u_u@sohu.com,有空联系。
masterz 2003-01-18
  • 打赏
  • 举报
回复
C# class:
using System;

namespace ClassLibrary1
{
/// <summary>
/// Summary description for Class1.
/// </summary>
public class Class1
{
public Class1()
{
//
// TODO: Add constructor logic here
//
}
public void MyMethod(byte[] buf)
{
int array_len=buf.GetLength(0);
Console.WriteLine("array length of parameter {0} ",array_len);
}
}
}

VC.NET usage
// This is the main project file for VC++ application project
// generated using an Application Wizard.

#include "stdafx.h"

#using <mscorlib.dll>
#include <tchar.h>
#using <ClassLibrary1.dll>
#using <System.Windows.Forms.dll>
using namespace System;
using namespace ClassLibrary1;
using namespace System::Windows::Forms;
// This is the entry point for this application
int _tmain(void)
{
Console::WriteLine(S"Hello masterz");
char ManageArray __gc[] = new char __gc[5];
for(int i=0;i<5;i++)
ManageArray[i]=i;
Class1 *cs = new Class1();
cs->MyMethod(ManageArray);
MessageBox::Show("This code snippet shows how to pass array to C#");
return 0;
}
u_u_u 2003-01-18
  • 打赏
  • 举报
回复
请高手赐教
saucer 2003-01-17
  • 打赏
  • 举报
回复
is your char* type of __wchar_t __gc[], if yes, try

byte[] blist = System.Text.Encoding.Default.GetBytes(YourCharPointer);
ahu9870 2003-01-17
  • 打赏
  • 举报
回复
gz
u_u_u 2003-01-17
  • 打赏
  • 举报
回复
不是,只是一个二进制形式一段数据(如jpg图片),希望能传送到C#中进行处理。

7,540

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 VC.NET
社区管理员
  • VC.NET社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧