473,411 Members | 2,272 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,411 software developers and data experts.

Marshal & Hwnd - Please Help.

I have the next code

byte[] data = new byte[14];
Marshal.Copy(this.Hwnd, data, 0, 4);

this code compiled well, but when i execute the code receive a error.

How can copy this.Hwnd (Handle of MessageWindow type IntPtr) to the first 4
bytes in data ?

Thanks.
Nov 15 '05 #1
3 3027
Hi,
Your code tries to copy 4 bytes of data from the location pointed by IntPtr
(this.Hwnd).
If you want to copy the IntPtr value (not the data it points) you could use
such approach:

byte[] data = new byte[14];
int ptrValue= this.Hwnd.ToInt32();
data[0] = (byte)ptrValue;
data[1] = (byte)ptrValue >> 8;
data[2] = (byte)ptrValue >> 16;
data[3] = (byte)ptrValue >> 24;

--
Andrew Gnenny
pulsar2003@/no-spam/email.ru (Please remove /no-spam/ for reply)
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE
"Juan Irigoyen" <ju***********@ono.com> wrote in message
news:zr*********************@news.ono.com...
I have the next code

byte[] data = new byte[14];
Marshal.Copy(this.Hwnd, data, 0, 4);

this code compiled well, but when i execute the code receive a error.

How can copy this.Hwnd (Handle of MessageWindow type IntPtr) to the first 4 bytes in data ?

Thanks.

Nov 15 '05 #2
Sorry this code have n error, Cannot implicity convert type 'int' to 'byte'

"Andrew Gnenny" <pulsar2003@/no-spam/email.ru> escribió en el mensaje
news:3f********@nexus.validio.com.ua...
Hi,
Your code tries to copy 4 bytes of data from the location pointed by IntPtr (this.Hwnd).
If you want to copy the IntPtr value (not the data it points) you could use such approach:

byte[] data = new byte[14];
int ptrValue= this.Hwnd.ToInt32();
data[0] = (byte)ptrValue;
data[1] = (byte)ptrValue >> 8;
data[2] = (byte)ptrValue >> 16;
data[3] = (byte)ptrValue >> 24;

--
Andrew Gnenny
pulsar2003@/no-spam/email.ru (Please remove /no-spam/ for reply)
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE
"Juan Irigoyen" <ju***********@ono.com> wrote in message
news:zr*********************@news.ono.com...
I have the next code

byte[] data = new byte[14];
Marshal.Copy(this.Hwnd, data, 0, 4);

this code compiled well, but when i execute the code receive a error.

How can copy this.Hwnd (Handle of MessageWindow type IntPtr) to the
first 4
bytes in data ?

Thanks.


Nov 15 '05 #3
Try this code:
byte[] data = new byte[14];
int ptrValue= this.Hwnd.ToInt32();
data[0] = (byte)ptrValue;
data[1] = (byte)(ptrValue >> 8);
data[2] = (byte)(ptrValue >> 16);
data[3] = (byte)(ptrValue >> 24);

--
Andrew Gnenny
pulsar2003@/no-spam/email.ru (Please remove /no-spam/ for reply)
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE
"Juan Irigoyen" <ju***********@ono.com> wrote in message
news:7b*********************@news.ono.com...
Sorry this code have n error, Cannot implicity convert type 'int' to 'byte'
"Andrew Gnenny" <pulsar2003@/no-spam/email.ru> escribió en el mensaje
news:3f********@nexus.validio.com.ua...
Hi,
Your code tries to copy 4 bytes of data from the location pointed by

IntPtr
(this.Hwnd).
If you want to copy the IntPtr value (not the data it points) you could

use
such approach:

byte[] data = new byte[14];
int ptrValue= this.Hwnd.ToInt32();
data[0] = (byte)ptrValue;
data[1] = (byte)ptrValue >> 8;
data[2] = (byte)ptrValue >> 16;
data[3] = (byte)ptrValue >> 24;

--
Andrew Gnenny
pulsar2003@/no-spam/email.ru (Please remove /no-spam/ for reply)
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE
"Juan Irigoyen" <ju***********@ono.com> wrote in message
news:zr*********************@news.ono.com...
I have the next code

byte[] data = new byte[14];
Marshal.Copy(this.Hwnd, data, 0, 4);

this code compiled well, but when i execute the code receive a error.

How can copy this.Hwnd (Handle of MessageWindow type IntPtr) to the

first
4
bytes in data ?

Thanks.



Nov 15 '05 #4

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

Similar topics

4
by: Ed Landau | last post by:
In VB6.0, I can put an image on a form and assign it's .picture property at run-time. In VBA (within MS Access), when I put down an image control on a form, it asks me for the source to the image...
0
by: Johannes Unfried | last post by:
Problem Best practice needed to marshal STL data from managed code to unmanaged code & vice vers Details managed code is written in managed C++ & accesses the unmanaged code (i.e. lives in a...
5
by: Adrian | last post by:
Hello, I'm currently converting a program at which needs to be able to dial and disconnect a specified DUN entry. The VB6 code is as follows and works fine, showing the dialog box for username...
5
by: Matthew Hood | last post by:
Here's a interesting question for the guru's out there. I've created a VB.NET class library with a couple of forms that I have successfully got to work from within MS Access using COM interop and...
1
by: pangel83 | last post by:
I've been trying for days to write a piece of VB.NET code that will read from winamp's memory space the paths of the files from the current winamp playlist. The GETPLAYLISTFILE command of the...
9
by: Lloyd Dupont | last post by:
If I write a pure C# application, only using the standart publi API, no interop, the same binary should work well on32 bit, 64 bits and perhaps on the compact framework as well if I link against...
0
by: tristanlbailey | last post by:
I have been attempting to solve this problem for a few weeks now, but I'm not having much luck... I would like to create a seamless fading effect on each form/window in my program; one that, when...
4
by: Larry Smith | last post by:
Hi there, Does anyone know if this (example) is safe: internal static extern int GetWindowRect(IntPtr hWnd, ref RECT rect); int rc = GetWindowRect(hWnd, ref rect); if (rc == 0)
1
by: bladepif | last post by:
Hello, I have a C++ dll that I can not link to may project, because it gives me an error that it is not a valid assembly or COM. I have 3 functions in this dll I need to use. - Initialize -...
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...
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
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...
0
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...

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.