473,795 Members | 3,428 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem translating 4 lines C# code to C++

Hello,
can anybody tell me what it would look like in C++?

byte[] bRawData = new byte[raw.hid.dwSizHi d];
int pRawData = buffer.ToInt32( ) + Marshal.SizeOf( typeof(RAWINPUT )) +
1; // buffer is of type IntPtr
Marshal.Copy(ne w IntPtr(pRawData ), bRawData, 0, raw.hid.dwSizHi d - 1);
int rawData = bRawData[0] | bRawData[1] << 8;

the full code is taken from the following article:

http://msdn.microsoft.com/en-us/library/ms996387.aspx
Jul 31 '08 #1
3 1946
On 2008-07-31 23:45, stax76 wrote:
Hello,
can anybody tell me what it would look like in C++?

byte[] bRawData = new byte[raw.hid.dwSizHi d];
Use a char array for bytes, since you will do some bit-shifting you
probably want unsigned char. But to be safe you should check how
shifting affects C# bytes, but it seems in this case that the result is
an integer type larger (more bits) than a byte.

unsigned char* bRawData = new unsigned char[raw.hid.dwSizHi d];
int pRawData = buffer.ToInt32( ) + Marshal.SizeOf( typeof(RAWINPUT )) +
1; // buffer is of type IntPtr
In you case buffer should be of type unsigned char* or perhaps void*,
what this code does is getting a pointer which points to some offset
from the beginning of the buffer containing the data you want. RAWINPUT
should be a struct or a class.

unsigned char* pRawData = buffer + sizeof(RAWINPUT ) + 1;
Marshal.Copy(ne w IntPtr(pRawData ), bRawData, 0, raw.hid.dwSizHi d - 1);
Looks like they copy the interesting parts from the buffer into the
array, use memcpy().
int rawData = bRawData[0] | bRawData[1] << 8;
Here they combine the values of bRawData[0] and bRawData[1] so that the
value in bRawData[1] is in bis 8-15 and bRawData[0] is in bits 0-8. This
line should work as it is.
the full code is taken from the following article:

http://msdn.microsoft.com/en-us/library/ms996387.aspx
Since you are not doing .Net development looking at the .Net
documentation might not be the best idea, it is better looking at the
Win32 documentation:

http://msdn.microsoft.com/en-us/libr...85(VS.85).aspx

Check the Raw Input section for more information relevant to your problem.

--
Erik Wikström
Jul 31 '08 #2
Thanks, that helped a lot. After trying very hard I've got it working
but it's not understandable since there is no docu for the hid data
structure, looks as follows:

int a1 = raw->data.hid.bRawD ata[1];
int a2 = 0;

if (raw->data.hid.dwSiz eHid == 3)
a2 = raw->data.hid.bRawD ata[2];

switch(a1 | a2 << 8)
{
...
}
Aug 1 '08 #3

"stax76" <fr*********@ya hoo.dewrote in message
news:c0******** *************** ***********@k37 g2000hsf.google groups.com...
Thanks, that helped a lot. After trying very hard I've got it working
but it's not understandable since there is no docu for the hid data
structure, looks as follows:

int a1 = raw->data.hid.bRawD ata[1];
int a2 = 0;

if (raw->data.hid.dwSiz eHid == 3)
a2 = raw->data.hid.bRawD ata[2];
Why aren't you just:
a1 = raw->data.hid.bRawD ata[raw->data.hid.dwSiz eHid - 1];

although I'm not sure how you're using a2 given the original algorithm.
switch(a1 | a2 << 8)
{
...
}

Aug 1 '08 #4

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

Similar topics

0
2176
by: Jax | last post by:
I am using a class that inherits from the DataGridTextBoxColumn. It adds a combo box into the column where it displays a selection of choices. The problem I have is that when this comboBox loses focus I lose the selected text. And this next line isn't setting the text in the cell. // code within the custom DataGridComboBoxColumn class this.TextBox.Text = this.ComboBox.SelectedItem.ToString();
10
2279
by: A.M | last post by:
Hi, I am having difficulty with shell scripting in Python. I use the following command to run a DOS command and put the return value in a Python variable:
9
1947
by: lombardm | last post by:
I am trying to decipher/translate some code that I have no experience with. I am trying to find out how the checksum is computed for a Megellan Explorist GPS Waypoint (POI) file. Below is the first 3 lines of a typical file. I understand everything except how the "a*23" at the end of the line is arrived at.
5
4987
by: Andrus | last post by:
I have database containing translations. I'm creating VS 2005 WinForms application which should use this database to translate menu items to user language. I replaced lines in myform.designer.cs like Text = "File"; to call my translating routine
0
9672
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
9519
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
10437
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10164
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
10001
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7538
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
6780
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
5437
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...
2
3723
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.