473,378 Members | 1,378 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.

Data type for marshaling BYTE*


Hi, everybody!
I have to use Unmanaged Code DLL for my .Net Application.

This Dll has a few functions that returns BYTE* value.
but you know that C# does not have pointer type....
so, what data type should i take for marshaling BYTE* ?


One of the function is like this....

__declspec(dllimport) bool System_Write(int nSys, BYTE* pByte);
in this case, How can i define a function for this dll function?

Apr 3 '06 #1
3 1800
Oh, I made a mistake...

The unmanaged dll function I have to marshing is not that, but this...

__declspec(dllimport) BYTE* System_Read(int nSys);

I want to use this function in my dotnet application with C#

Apr 3 '06 #2
bluewing,

You will have to declare the function as returning IntPtr, and then you
can use the static methods on the Marshal class to read the bytes from
unmanaged memory into a managed array.

The thing is, how will you know how many bytes to marshal? The
signature doesn't have anything on it to indicate the length of the array.

You also have the issue of how to deallocate the memory for the array.
Once you marshal the bytes over, you would have to call some other method,
passing the IntPtr to deallocate the memory block that was allocated upon
return.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"bluewing" <kr*****@dreamwiz.com> wrote in message
news:11*********************@t31g2000cwb.googlegro ups.com...
Oh, I made a mistake...

The unmanaged dll function I have to marshing is not that, but this...

__declspec(dllimport) BYTE* System_Read(int nSys);

I want to use this function in my dotnet application with C#

Apr 3 '06 #3
Thank you.

Would you mind if i ask you some example code, or reference?
None of my C# books talk about accessing array by point and dealing
with array
between C# and unmanaged dll.

Apr 3 '06 #4

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

Similar topics

1
by: JC | last post by:
How does garbage collection work in C# and VB.NET for data returned from COM object? For example, a COM object written in C++ returns a SAFEARRAY to C# or VB.NET, will this SAFEARRAY (mapped to...
4
by: Thomas Paul Diffenbach | last post by:
Can anyone point me to an open source library of /statically allocated/ data structures? I'm writing some code that would benefit from trees, preferably self balancing, but on an embedded system...
4
by: Chua Wen Ching | last post by:
I saw this article here: http://www.arstdesign.com/articles/interopmarshaling.html But i had some problems doing this. Codes: /* C Structure typdef struct {
0
by: NicK chlam via DotNetMonster.com | last post by:
this is the error i get System.Data.OleDb.OleDbException: Syntax error in INSERT INTO statement. at System.Data.Common.DbDataAdapter.Update(DataRow dataRows, DataTableMapping tableMapping) at...
1
by: Bill Medland | last post by:
I am trying to do some P/Invoke custom marshaling and am looking for a little help on custom marshaling a value type. I am working based on Kate Gregory's "Arranging Custom Marshaling With...
0
by: Macca | last post by:
Hi, I am writing an asychronous socket server to handle 20+ simulataneous connections. I have used the example in MSDN as a base. The code is shown at end of question. Each connection has a...
0
by: KYAW KO KO | last post by:
Hi all, I am dot net new user.I am trying to use active x control from vc 6.0 in dot net.I have data marshaling problem in combination dot net and ocx from vc 6.0. The following...
11
by: Siol | last post by:
I'm trying to call a dll function from C# which has the following form: int some_function(int count, char **arg1, char **arg2) Which parameter type I need to use in C# for C++ char** type? I...
2
by: O.B. | last post by:
I have operation within a class that marshals the data into a byte array. Below are three different ways that work. Are there any downsides to using one over the the other? public virtual byte...
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
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: 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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.