473,757 Members | 10,736 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C# Converting byte[] into C++ structs (ref thread255433)

1 New Member
Hello, Maestros.
Following on from the posts on creating structs from a byte[].
The methods described there work well. But I seem to have struck a snag that some might find interesting. The C/C++ structs that give problems all have the same issue: they all have at least one field something like this:
char character[25]

There does not appear to be any way to do this in c#. The closest I could get was
fixed sbyte character[25].
This does indeed get filled correctly, but of course with the byte value, not the ascii characters. What certainly doesn't work is
fixed char character[25], because a c/c++ char is not the same as a c# char (good ol unicode).

So my question is: is there a way to define a c/c++ char field[size] in a c# struct, with the result that the c# field holds a string of single-byte ascii chars just like a c/C++ one?

There are workarounds- I could create the struct using sbyte, then create another version of the struct with the sbytes converted to chars. But I am looking for something as simple as what I can do in C++ or Delphi! I am happy in my unsafeness! I am also happy to use the GC!

tia
>h
Sep 11 '07 #1
0 1033

Sign in to post your reply or Sign up for a free account.

Similar topics

1
1706
by: Majed | last post by:
hi, I'm trying to convert some .h files to API Declaration to use the function and structs. one of it is this: NTMS_GUID CurrentLibrary; // the current library NTMS_GUID MediaPool; // media pool that the media belongs to NTMS_GUID Location; // actual location of the media
2
12356
by: Al Bahr | last post by:
H I am try to convert C# to vb.net I don’t know what would be an equivalent statements in VB.net any help will be appreciated. bmiColors ' RGBQUAD structs... Blue-Green-Red-Reserved, repeat.. ' <summary ' Palette entry structur ' </summary bmiColors ' RGBQUAD structs... Blue-Green-Red-Reserved, repeat..
8
3409
by: Ben Terry | last post by:
What's the most efficient way to transfer data from a byte to a struct? The struct is rather complex--contains other structs as well as byte members. I've tried to use Marshal.Copy and an IntPtr to my struct address but I get the following error, perhaps due to the byte members of my struct: Cannot take the address or size of a variable of a managed type. Ben
0
1148
by: Al Bahr | last post by:
H I am try to convert C# to vb.net I don’t know what would be an equivalent statements in VB.net any help will be appreciated bmiColors ' RGBQUAD structs... Blue-Green-Red-Reserved, repeat.. ' <summary ' Palette entry structur ' </summary bmiColors ' RGBQUAD structs... Blue-Green-Red-Reserved, repeat..
6
8150
by: DaTurk | last post by:
Hi, I'm coding a layer into my application using CLI, between a unmanaged and a c# layer. So, I have to marshal some unmanaged c++ structures to structures usable in c#. My solution was to marshal the unmanaged C++ structures to CLI ref structs, these being usable in the c# layer. Why I did it this way is I want all of the business logic in the CLI layer. Because he c# layer is purely presentaion.
0
1457
by: shofu_au | last post by:
Hi Group, I am trying without much luck to pack messages into a byte buffer using get and set accessors. I have attached a simplified example of what I am trying to do using byte variables. (My real data is not byte variables.) I wish to be able to populate a field in the message header and then
1
1655
by: DaTurk | last post by:
Hi, I'm writing a CLI layer into my application, and I have several ref structs. Now, I've come into a situation that screams for a common interface, but because the structs are ref, I didn't see a reason why I couldn't have the structs implementing this interface. ANd it does work, but I'm concerned about the reprecussions of doing this. Is this good programming practice? And what will the resulting struct translate to in c#. I...
2
1915
by: =?Utf-8?B?U2V0aEluTUk=?= | last post by:
I am a total newb at .net, and I have not been able to search out a best practice answer to what must be a common problem. My app must process binary data from a UDP socket, a MSMQ queue and a file. In C, the data is in nested structs, with mixed types, floats, ints, char arrays, int arrays, variable length arrays of structs etc. My preference would be to access the data in a similar fashion to C, casting the byte array of received...
2
4359
by: jonpb | last post by:
Using .NET 3.5, I need to pass an array of structs as parameter to a C++ unmanaged function. The C++ dll stores some data in an unmanaged cache, the function writes the values into the array of structs. The array of structs are allocated by C#. If I pass the array without 'ref' it works fine on the C++ side, but after returning to C# the array struct values are all zero. If I pass with 'ref' the application crashes. If I use a class...
0
9489
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
9298
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
10072
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...
0
9906
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...
0
9737
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
7286
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
5329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3829
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
3399
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.