hi,

i was trying to write a c# code , were i need to pass ponitrtas an functin
argument . but when ever i am trying to do it i am getting error

"Cannot take the address or size of a variable of a managed type"

I am writing a piece of code were in which i am getting it can ayone help me
to remove it.
//////////////////////////////////////////////////////////////////////////////////////////////////////////


public unsafe class Node
{
public unsafe Node *pr;
public unsafe Node *ne;
}
***********************************************************
public unsafeclass Element : Node
{

public unsafe Element *fist;
public unsafe Element *lst;
public int length;

}
public unsafe void adBefore(Element *ptr, Element *pce)
{

{
ptr->pr=pce->pr;
if (pce->pr!=null)
pce->pr->ne=ptr; else
fist=ptr;
pce->pr=ptr;
ptr->ne=pce;
length++;
}
}


};
////////////////////////////////////////////////////////////////////////////////////////////////////

Hope anyone will provide a soln to me regarding this problem.

waiting for reply eagerly.

Regards

Naveen

Re: How to pass pointer as an function argument in C#? by David

David
Tue Aug 16 07:54:21 CDT 2005

Naveen,

I'm not sure exactly what you are trying to do, but have you looked at
the Ref keyword? I've not used it, so I may be off, but I believe it
passes objects by Reference, i.e., a pointer to it.

Check it out.

David
CTO
Soft360.com


Naveen koul wrote:
> hi,
>
> i was trying to write a c# code , were i need to pass ponitrtas an functin
> argument . but when ever i am trying to do it i am getting error
>
> "Cannot take the address or size of a variable of a managed type"
>
> I am writing a piece of code were in which i am getting it can ayone help me
> to remove it.
> //////////////////////////////////////////////////////////////////////////////////////////////////////////
>
>
> public unsafe class Node
> {
> public unsafe Node *pr;
> public unsafe Node *ne;
> }
> ***********************************************************
> public unsafeclass Element : Node
> {
>
> public unsafe Element *fist;
> public unsafe Element *lst;
> public int length;
>
> }
> public unsafe void adBefore(Element *ptr, Element *pce)
> {
>
> {
> ptr->pr=pce->pr;
> if (pce->pr!=null)
> pce->pr->ne=ptr; else
> fist=ptr;
> pce->pr=ptr;
> ptr->ne=pce;
> length++;
> }
> }
>
>
> };
> ////////////////////////////////////////////////////////////////////////////////////////////////////
>
> Hope anyone will provide a soln to me regarding this problem.
>
> waiting for reply eagerly.
>
> Regards
>
> Naveen
>
>
>
>
>
>
>
>
>
>
>

Re: How to pass pointer as an function argument in C#? by Alex

Alex
Tue Aug 16 14:40:25 CDT 2005

Why do you need pointers and unsafe code at all? Are you using this
togeteher with some unmanaged code?

--
Alex Feinman
---
Visit http://www.opennetcf.org
"Naveen koul" <Naveenkoul@discussions.microsoft.com> wrote in message
news:18FDAEB6-CAC4-49C4-9B2F-2330601ADA4F@microsoft.com...
> hi,
>
> i was trying to write a c# code , were i need to pass ponitrtas an functin
> argument . but when ever i am trying to do it i am getting error
>
> "Cannot take the address or size of a variable of a managed type"
>
> I am writing a piece of code were in which i am getting it can ayone help
> me
> to remove it.
> //////////////////////////////////////////////////////////////////////////////////////////////////////////
>
>
> public unsafe class Node
> {
> public unsafe Node *pr;
> public unsafe Node *ne;
> }
> ***********************************************************
> public unsafeclass Element : Node
> {
>
> public unsafe Element *fist;
> public unsafe Element *lst;
> public int length;
>
> }
> public unsafe void adBefore(Element *ptr, Element *pce)
> {
>
> {
> ptr->pr=pce->pr;
> if (pce->pr!=null)
> pce->pr->ne=ptr; else
> fist=ptr;
> pce->pr=ptr;
> ptr->ne=pce;
> length++;
> }
> }
>
>
> };
> ////////////////////////////////////////////////////////////////////////////////////////////////////
>
> Hope anyone will provide a soln to me regarding this problem.
>
> waiting for reply eagerly.
>
> Regards
>
> Naveen
>
>
>
>
>
>
>
>
>
>
>


Re: How to pass pointer as an function argument in C#? by Chris

Chris
Tue Aug 16 17:39:43 CDT 2005

I've done plenty of pointer parameter work - but it's rare that it's
necessary. Here I'm not convinced, plus you've not give un enough to
replicate the problem.

--
Chris Tacke
Co-founder
OpenNETCF.org
Are you using the SDF? Let's do a case study.
Email us at d c s @ o p e n n e t c f . c o m
http://www.opennetcf.org/donate


"Naveen koul" <Naveenkoul@discussions.microsoft.com> wrote in message
news:18FDAEB6-CAC4-49C4-9B2F-2330601ADA4F@microsoft.com...
> hi,
>
> i was trying to write a c# code , were i need to pass ponitrtas an functin
> argument . but when ever i am trying to do it i am getting error
>
> "Cannot take the address or size of a variable of a managed type"
>
> I am writing a piece of code were in which i am getting it can ayone help
> me
> to remove it.
> //////////////////////////////////////////////////////////////////////////////////////////////////////////
>
>
> public unsafe class Node
> {
> public unsafe Node *pr;
> public unsafe Node *ne;
> }
> ***********************************************************
> public unsafeclass Element : Node
> {
>
> public unsafe Element *fist;
> public unsafe Element *lst;
> public int length;
>
> }
> public unsafe void adBefore(Element *ptr, Element *pce)
> {
>
> {
> ptr->pr=pce->pr;
> if (pce->pr!=null)
> pce->pr->ne=ptr; else
> fist=ptr;
> pce->pr=ptr;
> ptr->ne=pce;
> length++;
> }
> }
>
>
> };
> ////////////////////////////////////////////////////////////////////////////////////////////////////
>
> Hope anyone will provide a soln to me regarding this problem.
>
> waiting for reply eagerly.
>
> Regards
>
> Naveen
>
>
>
>
>
>
>
>
>
>
>



Re: How to pass pointer as an function argument in C#? by Naveenkoul

Naveenkoul
Wed Aug 17 01:05:03 CDT 2005


hi,

this is just an sample code i have put here so that i get an idea how to get
this code working.
I have alredy an code in EVC++4.2 working and now i am trying to port it to
c#.my most of the code got working , but now when i am trying to create a
dll, this is were i am getting a problem.this code is just of the linked list.

Regards

Naveen
"Chris Tacke, eMVP" wrote:

> I've done plenty of pointer parameter work - but it's rare that it's
> necessary. Here I'm not convinced, plus you've not give un enough to
> replicate the problem.
>
> --
> Chris Tacke
> Co-founder
> OpenNETCF.org
> Are you using the SDF? Let's do a case study.
> Email us at d c s @ o p e n n e t c f . c o m
> http://www.opennetcf.org/donate
>
>
> "Naveen koul" <Naveenkoul@discussions.microsoft.com> wrote in message
> news:18FDAEB6-CAC4-49C4-9B2F-2330601ADA4F@microsoft.com...
> > hi,
> >
> > i was trying to write a c# code , were i need to pass ponitrtas an functin
> > argument . but when ever i am trying to do it i am getting error
> >
> > "Cannot take the address or size of a variable of a managed type"
> >
> > I am writing a piece of code were in which i am getting it can ayone help
> > me
> > to remove it.
> > //////////////////////////////////////////////////////////////////////////////////////////////////////////
> >
> >
> > public unsafe class Node
> > {
> > public unsafe Node *pr;
> > public unsafe Node *ne;
> > }
> > ***********************************************************
> > public unsafeclass Element : Node
> > {
> >
> > public unsafe Element *fist;
> > public unsafe Element *lst;
> > public int length;
> >
> > }
> > public unsafe void adBefore(Element *ptr, Element *pce)
> > {
> >
> > {
> > ptr->pr=pce->pr;
> > if (pce->pr!=null)
> > pce->pr->ne=ptr; else
> > fist=ptr;
> > pce->pr=ptr;
> > ptr->ne=pce;
> > length++;
> > }
> > }
> >
> >
> > };
> > ////////////////////////////////////////////////////////////////////////////////////////////////////
> >
> > Hope anyone will provide a soln to me regarding this problem.
> >
> > waiting for reply eagerly.
> >
> > Regards
> >
> > Naveen
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
>
>
>

Re: How to pass pointer as an function argument in C#? by ctacke/>

ctacke/>
Wed Aug 17 06:21:17 CDT 2005

C# does support passing pointers as parameters, but again, you've not give
solid reasoning. The CollectionBase namespace has linked lists without the
need for unsafe, difficult to read, difficult to maintain code. If you
insist on it, at least post a real, working example of the failure, not some
snippet that we'd have to write more code for.

-Chris


"Naveen koul" <Naveenkoul@discussions.microsoft.com> wrote in message
news:38CD9AE0-A214-48D2-8082-4F2689C7869F@microsoft.com...
>
> hi,
>
> this is just an sample code i have put here so that i get an idea how to
> get
> this code working.
> I have alredy an code in EVC++4.2 working and now i am trying to port it
> to
> c#.my most of the code got working , but now when i am trying to create a
> dll, this is were i am getting a problem.this code is just of the linked
> list.
>
> Regards
>
> Naveen
> "Chris Tacke, eMVP" wrote:
>
>> I've done plenty of pointer parameter work - but it's rare that it's
>> necessary. Here I'm not convinced, plus you've not give un enough to
>> replicate the problem.
>>
>> --
>> Chris Tacke
>> Co-founder
>> OpenNETCF.org
>> Are you using the SDF? Let's do a case study.
>> Email us at d c s @ o p e n n e t c f . c o m
>> http://www.opennetcf.org/donate
>>
>>
>> "Naveen koul" <Naveenkoul@discussions.microsoft.com> wrote in message
>> news:18FDAEB6-CAC4-49C4-9B2F-2330601ADA4F@microsoft.com...
>> > hi,
>> >
>> > i was trying to write a c# code , were i need to pass ponitrtas an
>> > functin
>> > argument . but when ever i am trying to do it i am getting error
>> >
>> > "Cannot take the address or size of a variable of a managed type"
>> >
>> > I am writing a piece of code were in which i am getting it can ayone
>> > help
>> > me
>> > to remove it.
>> > //////////////////////////////////////////////////////////////////////////////////////////////////////////
>> >
>> >
>> > public unsafe class Node
>> > {
>> > public unsafe Node *pr;
>> > public unsafe Node *ne;
>> > }
>> > ***********************************************************
>> > public unsafeclass Element : Node
>> > {
>> >
>> > public unsafe Element *fist;
>> > public unsafe Element *lst;
>> > public int length;
>> >
>> > }
>> > public unsafe void adBefore(Element *ptr, Element *pce)
>> > {
>> >
>> > {
>> > ptr->pr=pce->pr;
>> > if (pce->pr!=null)
>> > pce->pr->ne=ptr; else
>> > fist=ptr;
>> > pce->pr=ptr;
>> > ptr->ne=pce;
>> > length++;
>> > }
>> > }
>> >
>> >
>> > };
>> > ////////////////////////////////////////////////////////////////////////////////////////////////////
>> >
>> > Hope anyone will provide a soln to me regarding this problem.
>> >
>> > waiting for reply eagerly.
>> >
>> > Regards
>> >
>> > Naveen
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>>
>>
>>