473,396 Members | 1,975 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,396 software developers and data experts.

How do I convert IntPrt data to byte[]?

Hi, I'm using VS2005, .net 2 and C# for windows application. I need to
convert a IntPtr to a byte[] to be able to add a meetingBlob data to the
meeting class object in Active Directory schema. I get a "unspecified error"
if I tried to add the data before converting to a byte[] in
"deNewContextObject.Properties["meetingBlob"].Add((object)blob.pData);".

public struct Blob
{
public IntPtr pData;
public int nLength;
public int nSize;
}

int nBytes = Marshal.SizeOf(typeof(CUnityDS.Blob));
IntPtr ptr = Marshal.AllocHGlobal(nBytes);

// create an instance of the Blob structure
CUnityDS.Blob blob = new CUnityDS.Blob();

// copy and pin the structure to that location
Marshal.StructureToPtr(blob, ptr, true);

// Pass it by reference
// OK, now it's time to "reconsitute" the structure
blob = (CUnityDS.Blob)Marshal.PtrToStructure(ptr,
typeof(CUnityDS.Blob));
CUnityDS.DE_ERRORS errcode = CUnityDS.DE_ERRORS.DE_MEMORY_ALLOCATION_FAILURE;
//EncodeAsnUser is a C unmanaged code that puts data from userContextData
struct to IntPtr
errcode = CUnityDS.LibWrap.EncodeAsnUser(ref blob, userContextData);
//Getting unspeficied error with the following line becuase it needs a
byte[] and not IntPtr
deNewContextObject.Properties["meetingBlob"].Add((object)blob.pData);
--
Thanks.
Jun 15 '07 #1
6 4439
Lit

System.Runtime.InteropServices.Marshal.Copy(IntPtr source, byte[]
destination, int start, int length)
"Pucca" <Pu***@discussions.microsoft.comwrote in message
news:B1**********************************@microsof t.com...
Hi, I'm using VS2005, .net 2 and C# for windows application. I need to
convert a IntPtr to a byte[] to be able to add a meetingBlob data to the
meeting class object in Active Directory schema. I get a "unspecified
error"
if I tried to add the data before converting to a byte[] in
"deNewContextObject.Properties["meetingBlob"].Add((object)blob.pData);".

public struct Blob
{
public IntPtr pData;
public int nLength;
public int nSize;
}

int nBytes = Marshal.SizeOf(typeof(CUnityDS.Blob));
IntPtr ptr = Marshal.AllocHGlobal(nBytes);

// create an instance of the Blob structure
CUnityDS.Blob blob = new CUnityDS.Blob();

// copy and pin the structure to that location
Marshal.StructureToPtr(blob, ptr, true);

// Pass it by reference
// OK, now it's time to "reconsitute" the structure
blob = (CUnityDS.Blob)Marshal.PtrToStructure(ptr,
typeof(CUnityDS.Blob));
CUnityDS.DE_ERRORS errcode =
CUnityDS.DE_ERRORS.DE_MEMORY_ALLOCATION_FAILURE;
//EncodeAsnUser is a C unmanaged code that puts data from userContextData
struct to IntPtr
errcode = CUnityDS.LibWrap.EncodeAsnUser(ref blob, userContextData);
//Getting unspeficied error with the following line becuase it needs a
byte[] and not IntPtr
deNewContextObject.Properties["meetingBlob"].Add((object)blob.pData);
--
Thanks.

Jun 15 '07 #2
Thank yuou Lit. The blob is returned to me but the length is not set. How
can I get the length of the IntPrt for the parameter? Thank you.
--
Thanks.
"Lit" wrote:
>
System.Runtime.InteropServices.Marshal.Copy(IntPtr source, byte[]
destination, int start, int length)
"Pucca" <Pu***@discussions.microsoft.comwrote in message
news:B1**********************************@microsof t.com...
Hi, I'm using VS2005, .net 2 and C# for windows application. I need to
convert a IntPtr to a byte[] to be able to add a meetingBlob data to the
meeting class object in Active Directory schema. I get a "unspecified
error"
if I tried to add the data before converting to a byte[] in
"deNewContextObject.Properties["meetingBlob"].Add((object)blob.pData);".

public struct Blob
{
public IntPtr pData;
public int nLength;
public int nSize;
}

int nBytes = Marshal.SizeOf(typeof(CUnityDS.Blob));
IntPtr ptr = Marshal.AllocHGlobal(nBytes);

// create an instance of the Blob structure
CUnityDS.Blob blob = new CUnityDS.Blob();

// copy and pin the structure to that location
Marshal.StructureToPtr(blob, ptr, true);

// Pass it by reference
// OK, now it's time to "reconsitute" the structure
blob = (CUnityDS.Blob)Marshal.PtrToStructure(ptr,
typeof(CUnityDS.Blob));
CUnityDS.DE_ERRORS errcode =
CUnityDS.DE_ERRORS.DE_MEMORY_ALLOCATION_FAILURE;
//EncodeAsnUser is a C unmanaged code that puts data from userContextData
struct to IntPtr
errcode = CUnityDS.LibWrap.EncodeAsnUser(ref blob, userContextData);
//Getting unspeficied error with the following line becuase it needs a
byte[] and not IntPtr
deNewContextObject.Properties["meetingBlob"].Add((object)blob.pData);
--
Thanks.


Jun 15 '07 #3
Pucca wrote:
Thank yuou Lit. The blob is returned to me but the length is not set. How
can I get the length of the IntPrt for the parameter? Thank you.
Marshal.SizeOf maybe.

Arne
Jun 16 '07 #4
"Pucca" <Pu***@discussions.microsoft.comwrote in message
news:50**********************************@microsof t.com...
Thank yuou Lit. The blob is returned to me but the length is not set.
How
can I get the length of the IntPrt for the parameter? Thank you.
--
Thanks.
Isn't nLength or nSize not the size of pData?

Willy.

Jun 16 '07 #5
Yes, that gives me the size of pData. Thanks.
--
Thanks.
"Arne Vajhøj" wrote:
Pucca wrote:
Thank yuou Lit. The blob is returned to me but the length is not set. How
can I get the length of the IntPrt for the parameter? Thank you.

Marshal.SizeOf maybe.

Arne
Jun 18 '07 #6
Hi Willy,
I thought it is. My code is calling a fucntion to encode the user structure
data into a blob. Well, as it turns out. I'm able to call it successfully
but the data is not encoded correctly into a blob. I just posted that
problem. It will be great if you can take a look at that. Thank you. (my
title of the problem is "Need Help declaring parameter variables for
DllImport c-code dll"). Thank you.
--
Thanks.
"Willy Denoyette [MVP]" wrote:
"Pucca" <Pu***@discussions.microsoft.comwrote in message
news:50**********************************@microsof t.com...
Thank yuou Lit. The blob is returned to me but the length is not set.
How
can I get the length of the IntPrt for the parameter? Thank you.
--
Thanks.

Isn't nLength or nSize not the size of pData?

Willy.

Jun 18 '07 #7

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

Similar topics

1
by: Swarup | last post by:
I am reading a file (txt, xml, gif, ico, bmp etc) byte by byte and filling it into a byte arry. Now i have to convert it into a string to store it in the database. I use...
6
by: Ricardo Quintanilla | last post by:
i have a code that sends data to a socket listening over as400 platform, the socket responds to me as a "byte array". then i need to convert the "byte array" into a string. the problem is that...
3
by: MuZZy | last post by:
Hi, I just wonder if someone can help me wit this - i have a byte array and need to convert it to short array, creating short numbers by combining bytes by pairs: My array: byte, byte, byte,...
4
by: dale zhang | last post by:
Hi, I am trying to save and read an image from MS Access DB based on the following article: http://www.vbdotnetheaven.com/Code/Sept2003/2175.asp Right now, I saved images without any...
6
by: moondaddy | last post by:
I'm writing an app in vb.net 1.1 and need to convert a byte array into a string, and then from a string back to a byte array. for example Private mByte() as New Byte(4){11,22,33,44} Now how...
65
by: kyle.tk | last post by:
I am trying to write a function to convert an ipv4 address that is held in the string char *ip to its long value equivalent. Here is what I have right now, but I can't seem to get it to work. ...
10
by: =?Utf-8?B?Um95?= | last post by:
What is the way to have best performance to copy a byte to a value such as long? I use BitConverter.ToInt64(binary, offset) But the performace is not good enough. I need to have the best...
6
by: Bob Altman | last post by:
Hi all, I'm looking for the fastest way to convert an array of bytes to String. I also need to convert a String back to its original Byte() representation. Convert.ToBase64String and...
0
Debadatta Mishra
by: Debadatta Mishra | last post by:
Introduction In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in java so that you can conceal sensitive information...
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: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...
0
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...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.