By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,567 Members | 1,609 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,567 IT Pros & Developers. It's quick & easy.

need to send a pointer in C#

P: n/a
I need to send a pointer value to a fuction :( This is what it is
expecting.

BaseEffect.SetValue(Microsoft.DirectX.Direct3D.Eff ectHandle, void*,
int)

The problem is the void* part.

I'm tring to send an array of floats but the compiler doesn't like it.
Anyway I could push it through without having to resort to "unsafe"?

Nov 16 '05 #1
Share this Question
Share on Google+
13 Replies


P: n/a
Anyway I could push it through without having to resort to "unsafe"?


No, you always need unsafe to use pointers.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 16 '05 #2

P: n/a
"Mattias Sjögren" <ma********************@mvps.org> wrote in message
news:ul**************@TK2MSFTNGP12.phx.gbl...
Anyway I could push it through without having to resort to "unsafe"?


No, you always need unsafe to use pointers.


Is that quite true, Mattias? What about the IntPtr Structure?

Chris.
Nov 16 '05 #3

P: n/a
Is that quite true, Mattias? What about the IntPtr Structure?


That's not a pointer (not in the C# meaning anyway), it's a
pointer-sized integer.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 16 '05 #4

P: n/a
"Mattias Sjögren" <ma********************@mvps.org> wrote in message
news:#a**************@TK2MSFTNGP15.phx.gbl...
Is that quite true, Mattias? What about the IntPtr Structure?


That's not a pointer (not in the C# meaning anyway), it's a
pointer-sized integer.


...that can be used to represent a pointer without going unmanaged, right?
Couldn't it be used to represent the pointer void* in the following method?

BaseEffect.SetValue(Microsoft.DirectX.Direct3D.Eff ectHandle, void*, int)

Chris.
Nov 16 '05 #5

P: n/a
I tried sending it "new IntPtr(myobject)" but the compiler still did
not like. I don't really understand what is going on behind the scenes
enough to troubleshoot.

Nov 16 '05 #6

P: n/a
"vidalsasoon" <kj*****@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
I tried sending it "new IntPtr(myobject)" but the compiler still did
not like. I don't really understand what is going on behind the scenes
enough to troubleshoot.


Neither do I, I'm afraid. Wouldn't it be nice if Microsoft made the .NET
Framework source code available from within the VS.NET IDE <g> ?

Chris.
Nov 16 '05 #7

P: n/a
There is no SetValue method overload that takes a void*.
However, there is one overload that takes a System.Void
public void SetValue(
EffectHandle parameter,
void data,
int dataSize
);

Willy.

"vidalsasoon" <kj*****@gmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
I need to send a pointer value to a fuction :( This is what it is
expecting.

BaseEffect.SetValue(Microsoft.DirectX.Direct3D.Eff ectHandle, void*,
int)

The problem is the void* part.

I'm tring to send an array of floats but the compiler doesn't like it.
Anyway I could push it through without having to resort to "unsafe"?

Nov 16 '05 #8

P: n/a
Well, compiler is expecting "void*". Besides, sending data as "void" in
C# makes my brain hurt.

I'll have to resort to unsafe call it seems. :(

Nov 16 '05 #9

P: n/a
There is no SetValue method overload that takes a void*.
However, there is one overload that takes a System.Void


Huh? Void can't be used as a parameter type. I don't know anything
about DirectX, but if the assembly really contains a method with such
a signature, it would be invalid and not callable.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 16 '05 #10

P: n/a
..that can be used to represent a pointer
Absolutely.

without going unmanaged
I suppose you mean unsafe. You're still calling out to unmanaged code.

Couldn't it be used to represent the pointer void* in the following method?


Well the parameter type already is void*, and to call such a method
you need to use unsafe. The alternative would be to modify the method
signature to accept an IntPtr instead of void*, but in the OP case
that didn't seem like an option.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 16 '05 #11

P: n/a
vidalsasoon, Mattias,

You are absolutely right, I took this literally from:

http://msdn.microsoft.com/library/en...asp?frame=true

Included in the DirectX SDK February 2005 Update. public void SetValue(
EffectHandle parameter,
void data,
int dataSize
);

The docs are wrong ( seems like DirectX docs stay in preliminary state), the
2nd argument is simply an byte[] and the third the size of this array.

Willy.

"Mattias Sjögren" <ma********************@mvps.org> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
There is no SetValue method overload that takes a void*.
However, there is one overload that takes a System.Void


Huh? Void can't be used as a parameter type. I don't know anything
about DirectX, but if the assembly really contains a method with such
a signature, it would be invalid and not callable.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

Nov 16 '05 #12

P: n/a
One problem with the idea of pointers in .Net is that the CLR will, at its
own discretion, move items around in managed memory. If you send the
address of a value in the CLR to another application, the item may not be at
that address by the time the receiving application goes to read it. Just
because there are ways to get pointers does not make them safe. The only
way to use a pointer in .Net is to use the
System.Runtime.InteropServices.Marshal class to move values outside of the
CLR managed memory space and into unmanaged memory.

DalePres
MCAD, MCDBA, MCSE
"Mattias Sjögren" <ma********************@mvps.org> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
Is that quite true, Mattias? What about the IntPtr Structure?


That's not a pointer (not in the C# meaning anyway), it's a
pointer-sized integer.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

Nov 16 '05 #13

P: n/a

"vidalsasoon" <kj*****@gmail.com> wrote in message
news:11*********************@l41g2000cwc.googlegro ups.com...
Well, compiler is expecting "void*". Besides, sending data as "void" in
C# makes my brain hurt.

I'll have to resort to unsafe call it seems. :(


A bunch of the D3D methods are using pointers internaly and some are taking
pointer arguments , as such these methods are marked unsafe and NON CLS
compliant. Wonder how VB.NET will handle this.

Following illustrates how one can pass a float array as void*

float[] buffer = new float[2];
buffer[0] = 1.0F;
buffer[1] = 2.0F;

unsafe
{
fixed(float* cptr = &buffer[0])
{
MyEffect.SetValue(..., (void*) cptr, sizeof(float) *
buffer.Length);
}
}

Willy.


Nov 16 '05 #14

This discussion thread is closed

Replies have been disabled for this discussion.