473,387 Members | 1,545 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,387 software developers and data experts.

need to send a pointer in C#

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
13 1661
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
"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
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
"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
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
"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
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
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
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
..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
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
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

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Jerry Polyak | last post by:
Can someone give me a pointer, please. I am getting the following errors: Notice: Undefined index: sender_name in c:\program files\apache group\apache\htdocs\allinone_form.php on line 12 ...
40
by: ian | last post by:
Hi, I'm a newbie (oh no I can here you say.... another one...) How can I get Python to send emails using the default windows email client (eg outlook express)? I thought I could just do the...
3
by: Lenard Lindstrom | last post by:
Posted in a previous thread was some Python code for accessing Window's Simple MAPI api using the ctypes module. http://groups-beta.google.com/group/comp.lang.python/msg/56fa74cdba9b7be9 This...
5
by: Confused User | last post by:
I am working on device that utilizes a Motorola 68HC16 microcontroller. I am using an old unsupported piece of crap Whitesmith's / Intermetrics / Tasking compiler. The embedded compiler business...
66
by: genestarwing | last post by:
QUESTION: Write a program that opens and read a text file and records how many times each word occurs in the file. Use a binary search tree modified to store both a word and the number of times it...
16
by: pamelafluente | last post by:
I am still working with no success on that client/server problem. I need your help. I will submit simplified versions of my problem so we can see clearly what is going on. My model: A client...
3
by: growse | last post by:
Right, I've got a 2 c# programs here. Lets call them A and B. My aim is to send a simple string from B to A. A is always running. I've overridden the WndProc method to give me messages that are...
0
by: Ralstoj | last post by:
Hi I am programing in Autocad with VB Autodesk have not given users access to new note function in Autocad CIVIL3d API. I am trying to work round this by creating notes using the sendkey...
33
by: STILL LEARNING | last post by:
I'm not sure if this can even be done, but what prompts the question is my desire to be able to create an "Uber Link" script/code of some sort, such that even if the html page contains nothing but...
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
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
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,...
0
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...
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.