473,624 Members | 2,651 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2797
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.co m

"Kathy Tran" <Kathy Tr**@discussion s.microsoft.com> wrote in message
news:C4******** *************** ***********@mic rosoft.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("Pika API.dll")]
unsafe public static extern int PK_AUDIO_InputA ddBuffer(SEvent Q *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.co m

"Kathy Tran" <Kathy Tr**@discussion s.microsoft.com> wrote in message
news:C4******** *************** ***********@mic rosoft.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.co m

"Kathy Tran" <Kathy Tr**@discussion s.microsoft.com> wrote in message
news:E9******** *************** ***********@mic rosoft.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("Pika API.dll")]
unsafe public static extern int PK_AUDIO_InputA ddBuffer(SEvent Q *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.co m

"Kathy Tran" <Kathy Tr**@discussion s.microsoft.com> wrote in message
news:C4******** *************** ***********@mic rosoft.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**@discussion s.microsoft.com> wrote in message
news:E9******** *************** ***********@mic rosoft.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("Pika API.dll")]
unsafe public static extern int PK_AUDIO_InputA ddBuffer(SEvent Q *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.co m

"Kathy Tran" <Kathy Tr**@discussion s.microsoft.com> wrote in message
news:C4******** *************** ***********@mic rosoft.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_t ag
{
PK_PCHAR lpData;
PK_U32 dwBufferLength;
PK_U32 dwBytesRecorded ;
PK_U32 dwUser;
PK_U32 dwFlags;
PK_U32 dwTimeStamp;
struct TBufferHeader_t ag *lpNext;
PK_U32 reserved;
} TBufferHeader, *PBufferHeader;

Syntax
PK_STATUS PK_AUDIO_InputA ddBuffer
(
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.co m

"Kathy Tran" <Kathy Tr**@discussion s.microsoft.com> wrote in message
news:E9******** *************** ***********@mic rosoft.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("Pika API.dll")]
unsafe public static extern int PK_AUDIO_InputA ddBuffer(SEvent Q *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.co m

"Kathy Tran" <Kathy Tr**@discussion s.microsoft.com> wrote in message
news:C4******** *************** ***********@mic rosoft.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_t ag
{
PK_PCHAR lpData;
PK_U32 dwBufferLength;
PK_U32 dwBytesRecorded ;
PK_U32 dwUser;
PK_U32 dwFlags;
PK_U32 dwTimeStamp;
struct TBufferHeader_t ag *lpNext;
PK_U32 reserved;
} TBufferHeader, *PBufferHeader;
The functon my program are going to call is
Syntax
PK_STATUS PK_AUDIO_InputA ddBuffer
(
IN TResourceHandle hPort, // TResourceHandle is an int
IN PBufferHeader pBuffer
);

I am trying to use
[DllImport("Pika API.dll")]
unsafe public static extern int PK_AUDIO_InputA ddBuffer(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.co m

"Kathy Tran" <Kathy Tr**@discussion s.microsoft.com> wrote in message
news:E9******** *************** ***********@mic rosoft.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("Pika API.dll")]
unsafe public static extern int PK_AUDIO_InputA ddBuffer(SEvent Q *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.co m

"Kathy Tran" <Kathy Tr**@discussion s.microsoft.com> wrote in message
news:C4******** *************** ***********@mic rosoft.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.AlocHGl obal and Marshal.Structu reToPtr 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_t ag
{
PK_PCHAR lpData;
PK_U32 dwBufferLength;
PK_U32 dwBytesRecorded ;
PK_U32 dwUser;
PK_U32 dwFlags;
PK_U32 dwTimeStamp;
struct TBufferHeader_t ag *lpNext;
PK_U32 reserved;
} TBufferHeader, *PBufferHeader;
The functon my program are going to call is
Syntax
PK_STATUS PK_AUDIO_InputA ddBuffer
(
IN TResourceHandle hPort, // TResourceHandle is an int
IN PBufferHeader pBuffer
);

I am trying to use
[DllImport("Pika API.dll")]
unsafe public static extern int PK_AUDIO_InputA ddBuffer(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.co m

"Kathy Tran" <Kathy Tr**@discussion s.microsoft.com> wrote in message
news:E9******** *************** ***********@mic rosoft.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("Pika API.dll")]
unsafe public static extern int PK_AUDIO_InputA ddBuffer(SEvent Q *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.co m
>
>
>
> "Kathy Tran" <Kathy Tr**@discussion s.microsoft.com> wrote in message
> news:C4******** *************** ***********@mic rosoft.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
10114
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 code... TCHAR myArray; DoStuff(myArray);
5
3433
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 apparently accessible with the given subscript (as in the lvalue expression a given the declaration
9
2308
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
4453
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 accomplish. // - - - - - - - - begin code - - - - - - - typedef int sm_t; typedef int bg_t; sm_t sm; bg_t bg;
204
12981
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 = {0,1,2,4,9};
1
3089
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
10706
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 receive a byte array as one of its parameters. The project is marked for COM interop, and that all proceeds normally. When I reference the type library in the VB6 project, and write the code to call the function that returns the byte array, it works
1
617
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 platform which has the following properties: 1) char's are 8-Bit. ( "char" is synomonous with "byte" ). 2) int's are 32-Bit. ( sizeof(int) == 4 ). 3) Pointers are 64-Bit. ( sizeof(int*) == 8 ).
12
3871
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 looked sensible, but it didn't work right. Here is a simple example of what I'm trying to accomplish: // I have a hardware peripheral that I'm trying to access // that has two ports. Each port has 10 sequential // registers. Create a...
26
4849
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 about the syntax of calling the same. #include <stdio.h> void fp1()
0
8249
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
8179
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,...
1
8348
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
8493
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...
0
7176
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5570
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
4084
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...
1
2613
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
1
1797
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.