473,569 Members | 2,611 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(dlli mport) bool System_Write(in t nSys, BYTE* pByte);
in this case, How can i define a function for this dll function?

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

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

__declspec(dlli mport) 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.co m

"bluewing" <kr*****@dreamw iz.com> wrote in message
news:11******** *************@t 31g2000cwb.goog legroups.com...
Oh, I made a mistake...

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

__declspec(dlli mport) 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
947
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 type in C# or VB.NET) be garbage collected? Similarily, if C# or VB.NET pass SAFEARRAY to the COM object via COM method invocation, will this...
4
3844
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 that doesn't offer dynamic memory allocation (to be clear: no malloc, no realloc), and with rather tight memory constraints. Writing my own...
4
13824
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
5630
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 System.Data.Common.DbDataAdapter.Update(DataSet dataSet, String srcTable) at System.Data.Common.DbDataAdapter.Update(DataSet dataSet) at...
1
2671
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 P/Invoke", which is unfortunately in C++ with managed extensions; I am working in C#. As with Kate's example I want to marshal from a System.DateTime...
0
4660
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 number of different types of data coming in. I have a databuffer for each type of data coming in.
0
1072
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 is the function in vc 6.0 ocx.Function name is myRetrieve Image. BOOL CICACtrl::RetrieveImage(long iEventID, long iImageID, const VARIANT FAR&...
11
5652
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 tried byte (array of byte) but I get error "There is no marshaling support for nested arrays." regards
2
15915
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 ToRaw1() { byte byteArray = new byte; IntPtr pointer = Marshal.AllocHGlobal(Size); Marshal.StructureToPtr(this, pointer, false);...
0
7700
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7924
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8125
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7676
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6284
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5219
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1221
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
938
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.