473,378 Members | 1,438 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

how can i pass char* or string to byte*[] in C#

sorry i am poor in English.
i am trying to call functions from a "dll"(maybe developed in C++), there is
a struct in this function,which is defined like this:
typedef struct{
..........
BYTE * BS[5];
..........
}DBDIS;
this struct is used as parameter in some functions,and in fact every element
in this array is char*,it's a pointer to the first character in a string.
my problem:how can i pass char* or string to this array in C#
thanks.
Nov 16 '05 #1
2 2812

"????" <@discussions.microsoft.com> wrote in message
news:38**********************************@microsof t.com...
sorry i am poor in English.
i am trying to call functions from a "dll"(maybe developed in C++), there
is
a struct in this function,which is defined like this:
typedef struct{
..........
BYTE * BS[5];
..........
}DBDIS;
this struct is used as parameter in some functions,and in fact every
element
in this array is char*,it's a pointer to the first character in a string.
my problem:how can i pass char* or string to this array in C#
thanks.


I think you need to marshall it as an array of char:
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi)]
struct DBDIS
{
[MarshalAs(UnmanagedType.LPArray, SizeConst=5)]
char[] BS;
}

David

Nov 16 '05 #2
it doesn't work,David.
each element in BS(DLL struct) is a pointer to a null terminated string(C++),
although it's a byte*[].
how can i convert this C++ struct to a C# struct.
thanks David.

"David Browne" wrote:

"????" <@discussions.microsoft.com> wrote in message
news:38**********************************@microsof t.com...
sorry i am poor in English.
i am trying to call functions from a "dll"(maybe developed in C++), there
is
a struct in this function,which is defined like this:
typedef struct{
..........
BYTE * BS[5];
..........
}DBDIS;
this struct is used as parameter in some functions,and in fact every
element
in this array is char*,it's a pointer to the first character in a string.
my problem:how can i pass char* or string to this array in C#
thanks.


I think you need to marshall it as an array of char:
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi)]
struct DBDIS
{
[MarshalAs(UnmanagedType.LPArray, SizeConst=5)]
char[] BS;
}

David

Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: jagmeena | last post by:
Hello, I am sure this problem has been addressed before, however, I could'nt get a suitable solution to my problem. Hence I am posting here. Thanks a lot for all your help. The code I have is ...
8
by: Ekim | last post by:
my question is as follows: I've got a DLL in which I have a method GetBuffer (this one is extern, exported, is called from outside this program) which shall pass a char-buffer to the...
2
by: Peter Nilsson | last post by:
In a post regarding toupper(), Richard Heathfield once asked me to think about what the conversion of a char to unsigned char would mean, and whether it was sensible to actually do so. And pete has...
11
by: Walter Dnes (delete the 'z' to get my real address | last post by:
I've noticed a few threads (full of sound and fury, signifying nothing) here recently about allocation of large memory blocks. I'm about to start on a personal pet project where I'll be using...
1
by: wbaccay | last post by:
I have a byte of binary data received from a NetworkStream (C# code) that I need to pass to the IWMWriter object in a DLL written in Managed extensions for C++ (since the Windows Media SDK is not...
16
by: Ekim | last post by:
hello, I'm allocating a byte-Array in C# with byte byteArray = new byte; Now I want to pass this byte-Array to a managed C++-function by reference, so that I'm able to change the content of the...
15
by: Kueishiong Tu | last post by:
How do I convert a Byte array (unsigned char managed) to a char array(unmanaged) with wide character taken into account?
2
by: Steve Bottoms | last post by:
Is there any way to pass a login name/password when calling System.Web.Mail.SMTPMail? Can't find anything in the docs or KB... If not, any suggestions to get this functionality short of building...
20
by: =?Utf-8?B?ZW1pdG9qbGV5ZXM=?= | last post by:
Hi everyone: i read from the documentation of a dll that there is a struct that uses char for storing an IP address. How can it be? and how come i can get to representate the same value in a...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.