473,473 Members | 1,901 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Fixed length buffers

I'm doing some Pinvoke stuff. How do I deal with functions that
pass/receive structures that have fixed length char buffers?

I see this:

public struct MyArray // This code must appear in an unsafe block
{
public fixed char pathName[128];
}

in the docs, but this is upposed to be for c#2.0. I am presuming C#2.0
is not what I am using with VS .Net circa 2003. Is that right?

Any advice much appreciated...

Paul

Nov 17 '05 #1
4 1744
In article <11*********************@o13g2000cwo.googlegroups. com>, Paul wrote:
I'm doing some Pinvoke stuff. How do I deal with functions that
pass/receive structures that have fixed length char buffers?

I see this:

public struct MyArray // This code must appear in an unsafe block
{
public fixed char pathName[128];
}

in the docs, but this is upposed to be for c#2.0. I am presuming C#2.0
is not what I am using with VS .Net circa 2003. Is that right?

Any advice much appreciated...

Paul


// change charset to proper type for your application...
[StructLayout (LayoutKind.Sequential, CharSet=CharSet.Ansi)]
public struct MyArray
{
[MarshalAs (UnmanagedType.ByValTStr, SizeConst=128)]
public string pathName;
}

If you have a specific declaration, it would be much easier to answer :)

--
Tom Shelton [MVP]
Nov 17 '05 #2
In article <11*********************@o13g2000cwo.googlegroups. com>, Paul wrote:
I'm doing some Pinvoke stuff. How do I deal with functions that
pass/receive structures that have fixed length char buffers?

I see this:

public struct MyArray // This code must appear in an unsafe block
{
public fixed char pathName[128];
}

in the docs, but this is upposed to be for c#2.0. I am presuming C#2.0
is not what I am using with VS .Net circa 2003. Is that right?

Any advice much appreciated...

Paul


// change charset to proper type for your application...
[StructLayout (LayoutKind.Sequential, CharSet=CharSet.Ansi)]
public struct MyArray
{
[MarshalAs (UnmanagedType.ByValTStr, SizeConst=128)]
public string pathName;
}

If you have a specific declaration, it would be much easier to answer :)

--
Tom Shelton [MVP]
Nov 17 '05 #3
You da man! Works great. Thanks Tom.

Nov 17 '05 #4
You da man! Works great. Thanks Tom.

Nov 17 '05 #5

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

Similar topics

26
by: Adrian Parker | last post by:
I'm using the code below in my project. When I print all of these fixed length string variables, one per line, they strings in questions do not properly pad with 0s. strQuantity prints as " ...
0
by: Paul | last post by:
I'm doing some Pinvoke stuff. How do I deal with functions that pass/receive structures that have fixed length char buffers? I see this: public struct MyArray // This code must appear in an...
2
by: ldawson | last post by:
From the same C++ source code, I'm attempting to generate both an unmanaged DLL and a managed assembly. This will eliminate interop as the calling code is slowly migrated to .NET. However, C++...
4
by: Scott Lemen | last post by:
Hi, Some Win APIs expect a structure with a fixed length string. How is it defined in VB .Net 2003? When I try to use the FixedLengthString class I get an "Array bounds cannot appear in type...
5
by: David Garamond | last post by:
The MySQL manual recommends that we create a "fixed-length row" if possible, for speed (especially scanning speed). A fixed-length row is a row which is comprised of only fixed-length fields. A...
4
by: taskswap | last post by:
I'm converting an application that relies heavily on a binary network protocol. Within this protocol are a lot of byte arrays of character data, like: public unsafe struct MsgAddEntry {...
1
by: O.B. | last post by:
In the example below, I'm trying to convert a fixed byte array to a string. I get an error about needing to use "fixed" but I have no clue where to apply it. Help? using System; using...
1
by: Rick Knospler | last post by:
I am trying to convert a vb6 project to vb.net. The conversion worked for the most part except for the fixed length strings and fixed length string arrays. Bascially the vb6 programmer stored all...
6
by: =?Utf-8?B?TFBldGVy?= | last post by:
Hi, I would copy the characters of a string variable to a fixed character buffer in a struct (and vice versa) in C#. public struct S { ... public fixed char cBuff; ...
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
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
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...

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.