473,778 Members | 1,958 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 "unspecifie d error"
if I tried to add the data before converting to a byte[] in
"deNewContextOb ject.Properties["meetingBlo b"].Add((object)bl ob.pData);".

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

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

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

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

// Pass it by reference
// OK, now it's time to "reconsitut e" the structure
blob = (CUnityDS.Blob) Marshal.PtrToSt ructure(ptr,
typeof(CUnityDS .Blob));
CUnityDS.DE_ERR ORS errcode = CUnityDS.DE_ERR ORS.DE_MEMORY_A LLOCATION_FAILU RE;
//EncodeAsnUser is a C unmanaged code that puts data from userContextData
struct to IntPtr
errcode = CUnityDS.LibWra p.EncodeAsnUser (ref blob, userContextData );
//Getting unspeficied error with the following line becuase it needs a
byte[] and not IntPtr
deNewContextObj ect.Properties["meetingBlo b"].Add((object)bl ob.pData);
--
Thanks.
Jun 15 '07 #1
6 4466
Lit

System.Runtime. InteropServices .Marshal.Copy(I ntPtr source, byte[]
destination, int start, int length)
"Pucca" <Pu***@discussi ons.microsoft.c omwrote in message
news:B1******** *************** ***********@mic rosoft.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 "unspecifie d
error"
if I tried to add the data before converting to a byte[] in
"deNewContextOb ject.Properties["meetingBlo b"].Add((object)bl ob.pData);".

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

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

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

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

// Pass it by reference
// OK, now it's time to "reconsitut e" the structure
blob = (CUnityDS.Blob) Marshal.PtrToSt ructure(ptr,
typeof(CUnityDS .Blob));
CUnityDS.DE_ERR ORS errcode =
CUnityDS.DE_ERR ORS.DE_MEMORY_A LLOCATION_FAILU RE;
//EncodeAsnUser is a C unmanaged code that puts data from userContextData
struct to IntPtr
errcode = CUnityDS.LibWra p.EncodeAsnUser (ref blob, userContextData );
//Getting unspeficied error with the following line becuase it needs a
byte[] and not IntPtr
deNewContextObj ect.Properties["meetingBlo b"].Add((object)bl ob.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(I ntPtr source, byte[]
destination, int start, int length)
"Pucca" <Pu***@discussi ons.microsoft.c omwrote in message
news:B1******** *************** ***********@mic rosoft.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 "unspecifie d
error"
if I tried to add the data before converting to a byte[] in
"deNewContextOb ject.Properties["meetingBlo b"].Add((object)bl ob.pData);".

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

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

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

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

// Pass it by reference
// OK, now it's time to "reconsitut e" the structure
blob = (CUnityDS.Blob) Marshal.PtrToSt ructure(ptr,
typeof(CUnityDS .Blob));
CUnityDS.DE_ERR ORS errcode =
CUnityDS.DE_ERR ORS.DE_MEMORY_A LLOCATION_FAILU RE;
//EncodeAsnUser is a C unmanaged code that puts data from userContextData
struct to IntPtr
errcode = CUnityDS.LibWra p.EncodeAsnUser (ref blob, userContextData );
//Getting unspeficied error with the following line becuase it needs a
byte[] and not IntPtr
deNewContextObj ect.Properties["meetingBlo b"].Add((object)bl ob.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***@discussi ons.microsoft.c omwrote in message
news:50******** *************** ***********@mic rosoft.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***@discussi ons.microsoft.c omwrote in message
news:50******** *************** ***********@mic rosoft.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
4487
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 System.Text.UnicodeEncoding enc = new System.Text.UnicodeEncoding(); now i am using enc.GetString(value) and the value retured is one byte less if the size of the byte array is Odd. In case of files having even number of bytes, the convertion is happening correctly and...
6
10230
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 the data converted from the byte array into a string , is not what i expect. example: - the data returned from the socket is (byte array) "Usuario Sin Atribuciones Para Esta Función"
3
10364
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, etc. I need: short = byte+byte, short = byte+byte, etc.
4
3304
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 errors. After reading the ole object from db, I saved it to C: as file1.bmp and displayed on the web. But it can not be displayed. After I manually sent the file to wordpad, it shows
6
53725
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 do I convert it to: dim myStr as string = "11,22,33,44"
65
21484
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. #include <string.h> #include <stdio.h> /* Convert an ipv4 address to long integer */ /* "192.168.1.1" --> 3232235777 */ unsigned long iptol(char *ip){
10
4903
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 performance in my case.
6
5285
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 Convert.FromBase64String seem like the closest thing I can find to what I'm looking for baked into the base class library. Can anyone suggest a better way to do this? TIA - Bob
0
10782
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 inside an image, hide your complete image as text ,search for a particular image inside a directory, minimize the size of the image. However this is not a new concept, there is a concept called Steganography which enables to conceal your secret...
0
9629
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9470
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10127
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7475
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6723
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5370
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5500
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4033
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2865
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.