472,353 Members | 1,715 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,353 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 4361
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...
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...
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...
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: ...
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 ...
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...
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...
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()...
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...
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python...

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.