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

Array of pointer in C#

Hi,
Could you please help me how to declare an araay of pointer in C#.
In my program I declared an structure

public struct SEventQ
{
public uint uiUserData;
public uint uiEvent;
public uint uiParam0;
public uint uiParam1;
}

Now I want to delare an array of pointer look likes
unsafe SEventQ [] *EvQ = new SEventQ[10];
Thanks,

Kathy Tran
Nov 16 '05 #1
7 2780
Kathy,

Why do you want an array of pointers. Are you performing some sort of
interop which requires an array of pointers to these structures to be taken,
or do you need an array of structure?

If you wanted an array of pointers, I believe you would do:

SEventQ **EvQ;

However, you couldn't say "new SEventQ*", since you can't "create" a
pointer in that manner.

What is it that you are trying to do?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Kathy Tran" <Kathy Tr**@discussions.microsoft.com> wrote in message
news:C4**********************************@microsof t.com...
Hi,
Could you please help me how to declare an araay of pointer in C#.
In my program I declared an structure

public struct SEventQ
{
public uint uiUserData;
public uint uiEvent;
public uint uiParam0;
public uint uiParam1;
}

Now I want to delare an array of pointer look likes
unsafe SEventQ [] *EvQ = new SEventQ[10];
Thanks,

Kathy Tran

Nov 16 '05 #2
Hi Nicholas Paldino ,
Thanks for responding my question. I am performing some of interop which
requires an array of pointers to these structures to be taken. In my program
I want to go through an array of pointer, with each element in array I assign
some values in structure and then pass each element to un unmanaged code
function

[DllImport("PikaAPI.dll")]
unsafe public static extern int PK_AUDIO_InputAddBuffer(SEventQ *pEvent);

but I am very confusing and do not how to declare an array of pointer.

Thank,
Kathy Tran

"Nicholas Paldino [.NET/C# MVP]" wrote:
Kathy,

Why do you want an array of pointers. Are you performing some sort of
interop which requires an array of pointers to these structures to be taken,
or do you need an array of structure?

If you wanted an array of pointers, I believe you would do:

SEventQ **EvQ;

However, you couldn't say "new SEventQ*", since you can't "create" a
pointer in that manner.

What is it that you are trying to do?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Kathy Tran" <Kathy Tr**@discussions.microsoft.com> wrote in message
news:C4**********************************@microsof t.com...
Hi,
Could you please help me how to declare an araay of pointer in C#.
In my program I declared an structure

public struct SEventQ
{
public uint uiUserData;
public uint uiEvent;
public uint uiParam0;
public uint uiParam1;
}

Now I want to delare an array of pointer look likes
unsafe SEventQ [] *EvQ = new SEventQ[10];
Thanks,

Kathy Tran


Nov 16 '05 #3
Kathy,

What is the original declaration (in C/C++) of the method? The one that
you have is not an array of pointers, but rather, just a pointer to the
structure, which is the same as an array of structures (not an array of
pointers to a structure).
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Kathy Tran" <Kathy Tr**@discussions.microsoft.com> wrote in message
news:E9**********************************@microsof t.com...
Hi Nicholas Paldino ,
Thanks for responding my question. I am performing some of interop which
requires an array of pointers to these structures to be taken. In my
program
I want to go through an array of pointer, with each element in array I
assign
some values in structure and then pass each element to un unmanaged code
function

[DllImport("PikaAPI.dll")]
unsafe public static extern int PK_AUDIO_InputAddBuffer(SEventQ *pEvent);

but I am very confusing and do not how to declare an array of pointer.

Thank,
Kathy Tran

"Nicholas Paldino [.NET/C# MVP]" wrote:
Kathy,

Why do you want an array of pointers. Are you performing some sort
of
interop which requires an array of pointers to these structures to be
taken,
or do you need an array of structure?

If you wanted an array of pointers, I believe you would do:

SEventQ **EvQ;

However, you couldn't say "new SEventQ*", since you can't "create" a
pointer in that manner.

What is it that you are trying to do?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Kathy Tran" <Kathy Tr**@discussions.microsoft.com> wrote in message
news:C4**********************************@microsof t.com...
> Hi,
> Could you please help me how to declare an araay of pointer in C#.
> In my program I declared an structure
>
> public struct SEventQ
> {
> public uint uiUserData;
> public uint uiEvent;
> public uint uiParam0;
> public uint uiParam1;
> }
>
> Now I want to delare an array of pointer look likes
> unsafe SEventQ [] *EvQ = new SEventQ[10];
>
>
> Thanks,
>
> Kathy Tran


Nov 16 '05 #4
This MSDN article has examples for this kind of thing:

http://msdn.microsoft.com/msdnmag/issues/02/08/CQA/

I hope one of the examples helps.

- Jonathan W.
"Kathy Tran" <Kathy Tr**@discussions.microsoft.com> wrote in message
news:E9**********************************@microsof t.com...
Hi Nicholas Paldino ,
Thanks for responding my question. I am performing some of interop which
requires an array of pointers to these structures to be taken. In my
program
I want to go through an array of pointer, with each element in array I
assign
some values in structure and then pass each element to un unmanaged code
function

[DllImport("PikaAPI.dll")]
unsafe public static extern int PK_AUDIO_InputAddBuffer(SEventQ *pEvent);

but I am very confusing and do not how to declare an array of pointer.

Thank,
Kathy Tran

"Nicholas Paldino [.NET/C# MVP]" wrote:
Kathy,

Why do you want an array of pointers. Are you performing some sort
of
interop which requires an array of pointers to these structures to be
taken,
or do you need an array of structure?

If you wanted an array of pointers, I believe you would do:

SEventQ **EvQ;

However, you couldn't say "new SEventQ*", since you can't "create" a
pointer in that manner.

What is it that you are trying to do?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Kathy Tran" <Kathy Tr**@discussions.microsoft.com> wrote in message
news:C4**********************************@microsof t.com...
> Hi,
> Could you please help me how to declare an araay of pointer in C#.
> In my program I declared an structure
>
> public struct SEventQ
> {
> public uint uiUserData;
> public uint uiEvent;
> public uint uiParam0;
> public uint uiParam1;
> }
>
> Now I want to delare an array of pointer look likes
> unsafe SEventQ [] *EvQ = new SEventQ[10];
>
>
> Thanks,
>
> Kathy Tran


Nov 16 '05 #5
Hi Nicholas Paldino,
This is the original declaration in C

typedef struct TBufferHeader_tag
{
PK_PCHAR lpData;
PK_U32 dwBufferLength;
PK_U32 dwBytesRecorded;
PK_U32 dwUser;
PK_U32 dwFlags;
PK_U32 dwTimeStamp;
struct TBufferHeader_tag *lpNext;
PK_U32 reserved;
} TBufferHeader, *PBufferHeader;

Syntax
PK_STATUS PK_AUDIO_InputAddBuffer
(
IN TResourceHandle hPort, // TResourceHandle is an int
IN PBufferHeader pBuffer
);

My program will call the above function

Kathy Tran
"Nicholas Paldino [.NET/C# MVP]" wrote:
Kathy,

What is the original declaration (in C/C++) of the method? The one that
you have is not an array of pointers, but rather, just a pointer to the
structure, which is the same as an array of structures (not an array of
pointers to a structure).
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Kathy Tran" <Kathy Tr**@discussions.microsoft.com> wrote in message
news:E9**********************************@microsof t.com...
Hi Nicholas Paldino ,
Thanks for responding my question. I am performing some of interop which
requires an array of pointers to these structures to be taken. In my
program
I want to go through an array of pointer, with each element in array I
assign
some values in structure and then pass each element to un unmanaged code
function

[DllImport("PikaAPI.dll")]
unsafe public static extern int PK_AUDIO_InputAddBuffer(SEventQ *pEvent);

but I am very confusing and do not how to declare an array of pointer.

Thank,
Kathy Tran

"Nicholas Paldino [.NET/C# MVP]" wrote:
Kathy,

Why do you want an array of pointers. Are you performing some sort
of
interop which requires an array of pointers to these structures to be
taken,
or do you need an array of structure?

If you wanted an array of pointers, I believe you would do:

SEventQ **EvQ;

However, you couldn't say "new SEventQ*", since you can't "create" a
pointer in that manner.

What is it that you are trying to do?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Kathy Tran" <Kathy Tr**@discussions.microsoft.com> wrote in message
news:C4**********************************@microsof t.com...
> Hi,
> Could you please help me how to declare an araay of pointer in C#.
> In my program I declared an structure
>
> public struct SEventQ
> {
> public uint uiUserData;
> public uint uiEvent;
> public uint uiParam0;
> public uint uiParam1;
> }
>
> Now I want to delare an array of pointer look likes
> unsafe SEventQ [] *EvQ = new SEventQ[10];
>
>
> Thanks,
>
> Kathy Tran


Nov 16 '05 #6
Hi Nicholas Paldino ,
The original declaration is
typedef struct TBufferHeader_tag
{
PK_PCHAR lpData;
PK_U32 dwBufferLength;
PK_U32 dwBytesRecorded;
PK_U32 dwUser;
PK_U32 dwFlags;
PK_U32 dwTimeStamp;
struct TBufferHeader_tag *lpNext;
PK_U32 reserved;
} TBufferHeader, *PBufferHeader;
The functon my program are going to call is
Syntax
PK_STATUS PK_AUDIO_InputAddBuffer
(
IN TResourceHandle hPort, // TResourceHandle is an int
IN PBufferHeader pBuffer
);

I am trying to use
[DllImport("PikaAPI.dll")]
unsafe public static extern int PK_AUDIO_InputAddBuffer(uint
TResourceHandle, TBufferHeader *pBuffer);

But I got errors when I compiled
Cannot take the address or size of a variable of a managed type
(TBufferHeader)

Thanks for any help
Kathy Tran

"Nicholas Paldino [.NET/C# MVP]" wrote:
Kathy,

What is the original declaration (in C/C++) of the method? The one that
you have is not an array of pointers, but rather, just a pointer to the
structure, which is the same as an array of structures (not an array of
pointers to a structure).
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Kathy Tran" <Kathy Tr**@discussions.microsoft.com> wrote in message
news:E9**********************************@microsof t.com...
Hi Nicholas Paldino ,
Thanks for responding my question. I am performing some of interop which
requires an array of pointers to these structures to be taken. In my
program
I want to go through an array of pointer, with each element in array I
assign
some values in structure and then pass each element to un unmanaged code
function

[DllImport("PikaAPI.dll")]
unsafe public static extern int PK_AUDIO_InputAddBuffer(SEventQ *pEvent);

but I am very confusing and do not how to declare an array of pointer.

Thank,
Kathy Tran

"Nicholas Paldino [.NET/C# MVP]" wrote:
Kathy,

Why do you want an array of pointers. Are you performing some sort
of
interop which requires an array of pointers to these structures to be
taken,
or do you need an array of structure?

If you wanted an array of pointers, I believe you would do:

SEventQ **EvQ;

However, you couldn't say "new SEventQ*", since you can't "create" a
pointer in that manner.

What is it that you are trying to do?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Kathy Tran" <Kathy Tr**@discussions.microsoft.com> wrote in message
news:C4**********************************@microsof t.com...
> Hi,
> Could you please help me how to declare an araay of pointer in C#.
> In my program I declared an structure
>
> public struct SEventQ
> {
> public uint uiUserData;
> public uint uiEvent;
> public uint uiParam0;
> public uint uiParam1;
> }
>
> Now I want to delare an array of pointer look likes
> unsafe SEventQ [] *EvQ = new SEventQ[10];
>
>
> Thanks,
>
> Kathy Tran


Nov 16 '05 #7
what you have is not an array, it's a linked list. and your function
signature is wrong. My guess is that the resource handle should be an opaque
pointer that's marshalled as IntPtr. And you'd have to marshal the
TBufferHeader* as a IntPtr as well. In your structure definition, lpData
should be an IntPtr to a unmanaged buffer, and lpNext should be a IntPtr to
the next element in the linked list. problem is that you'd have to make a
lot of manual calls to Marshal.AlocHGlobal and Marshal.StructureToPtr to get
your data set up back and forth.

I'd suggest that you read and understand platform invoke fully before
attempting.
http://msdn.microsoft.com/library/de...lfunctions.asp

"Kathy Tran" wrote:
Hi Nicholas Paldino ,
The original declaration is
typedef struct TBufferHeader_tag
{
PK_PCHAR lpData;
PK_U32 dwBufferLength;
PK_U32 dwBytesRecorded;
PK_U32 dwUser;
PK_U32 dwFlags;
PK_U32 dwTimeStamp;
struct TBufferHeader_tag *lpNext;
PK_U32 reserved;
} TBufferHeader, *PBufferHeader;
The functon my program are going to call is
Syntax
PK_STATUS PK_AUDIO_InputAddBuffer
(
IN TResourceHandle hPort, // TResourceHandle is an int
IN PBufferHeader pBuffer
);

I am trying to use
[DllImport("PikaAPI.dll")]
unsafe public static extern int PK_AUDIO_InputAddBuffer(uint
TResourceHandle, TBufferHeader *pBuffer);

But I got errors when I compiled
Cannot take the address or size of a variable of a managed type
(TBufferHeader)

Thanks for any help
Kathy Tran

"Nicholas Paldino [.NET/C# MVP]" wrote:
Kathy,

What is the original declaration (in C/C++) of the method? The one that
you have is not an array of pointers, but rather, just a pointer to the
structure, which is the same as an array of structures (not an array of
pointers to a structure).
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Kathy Tran" <Kathy Tr**@discussions.microsoft.com> wrote in message
news:E9**********************************@microsof t.com...
Hi Nicholas Paldino ,
Thanks for responding my question. I am performing some of interop which
requires an array of pointers to these structures to be taken. In my
program
I want to go through an array of pointer, with each element in array I
assign
some values in structure and then pass each element to un unmanaged code
function

[DllImport("PikaAPI.dll")]
unsafe public static extern int PK_AUDIO_InputAddBuffer(SEventQ *pEvent);

but I am very confusing and do not how to declare an array of pointer.

Thank,
Kathy Tran

"Nicholas Paldino [.NET/C# MVP]" wrote:

> Kathy,
>
> Why do you want an array of pointers. Are you performing some sort
> of
> interop which requires an array of pointers to these structures to be
> taken,
> or do you need an array of structure?
>
> If you wanted an array of pointers, I believe you would do:
>
> SEventQ **EvQ;
>
> However, you couldn't say "new SEventQ*", since you can't "create" a
> pointer in that manner.
>
> What is it that you are trying to do?
>
>
> --
> - Nicholas Paldino [.NET/C# MVP]
> - mv*@spam.guard.caspershouse.com
>
>
>
> "Kathy Tran" <Kathy Tr**@discussions.microsoft.com> wrote in message
> news:C4**********************************@microsof t.com...
> > Hi,
> > Could you please help me how to declare an araay of pointer in C#.
> > In my program I declared an structure
> >
> > public struct SEventQ
> > {
> > public uint uiUserData;
> > public uint uiEvent;
> > public uint uiParam0;
> > public uint uiParam1;
> > }
> >
> > Now I want to delare an array of pointer look likes
> > unsafe SEventQ [] *EvQ = new SEventQ[10];
> >
> >
> > Thanks,
> >
> > Kathy Tran
>
>
>


Nov 16 '05 #8

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

Similar topics

58
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of...
5
by: Richard Delorme | last post by:
The n869 draft says: J.2 Undefined behavior The behavior is undefined in the following circumstances: -- An array subscript is out of range, even if an object is ...
9
by: Luke Wu | last post by:
Hello, I'm having some problems understanding 2 dimensional arrays. My problem relates to the following code: #include <stdio.h> #define M 3 #define N 3
11
by: truckaxle | last post by:
I am trying to pass a slice from a larger 2-dimensional array to a function that will work on a smaller region of the array space. The code below is a distillation of what I am trying to...
204
by: Alexei A. Frounze | last post by:
Hi all, I have a question regarding the gcc behavior (gcc version 3.3.4). On the following test program it emits a warning: #include <stdio.h> int aInt2 = {0,1,2,4,9,16}; int aInt3 =...
1
by: Jeff | last post by:
I am struggling with the following How do I marshal/access a pointer to an array of strings within a structure Than Jef ----------------------------------------------------------------
8
by: intrepid_dw | last post by:
Hello, all. I've created a C# dll that contains, among other things, two functions dealing with byte arrays. The first is a function that returns a byte array, and the other is intended to...
1
by: Tomás | last post by:
Some programmers treat arrays just like pointers (and some even think that they're exactly equivalent). I'm going to demonstrate the differences. Firstly, let's assume that we're working on a...
12
by: gcary | last post by:
I am having trouble figuring out how to declare a pointer to an array of structures and initializing the pointer with a value. I've looked at older posts in this group, and tried a solution that...
26
by: aruna.mysore | last post by:
Hi all, I have a specific problem passing a function pointer array as a parameter to a function. I am trying to use a function which takes a function pointer array as an argument. I am too sure...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...

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.