Ok, I see your point. 

It is indeed weird, I didn't notice that, my appologies.
If you look at Volume.LockBox() for example you see this:

public GraphicsStream LockBox(Box box, LockFlags flags)
{
 return this.LockBoxInternal(ref box, flags, 0);
}

Indeed weird why the box has to be passed by value and is then passed on
by ref. (LockBoxInternal accepts as 1st parameter _D3DBOX * )

One thing might be that manipulation of the passed in data is done on
the *copy*, not on the original, which might confuse people who are not
used to pointer arithmetic. To pass by value, you assure yourself you
have a copy, not the original. But that's just a wild guess.

                FB
 

> Frans Bouma wrote:
> >         Although there is one weird thing:
> > (and you know more on this than I do I think): the D3D structs are 
> > redefined in these formats:
> > 
> > [StructLayout(LayoutKind.Sequential, Size=24, Pack=1), 
> > CLSCompliant(false), MiscellaneousBits(65), DebugInfoInPDB] public 
> > struct _D3DBOX {
> >   
> > }
> > 
> > Without contents. 
> > 
> > Perhaps in combination with unmanaged code, I'm not sure.
> 
> I think this is because D3DBOX is an unmanaged type and IIRC 
> the content of the structure isn't available in the type 
> library. From a managed perspective it is just a bunch of 
> bytes (24 bytes, as you can see in the StructLayout 
> attribute). In the Managed DirectX SDK there is probably a 
> value type with the same layout and the wrapper just casts 
> the pointer types. Something like this:
> 
> [StructLayout(LayoutKind.Sequential, Size=24, Pack=1)] struct Box {
>   uint Left;
>   uint Top;
>   uint Right;
>   uint Bottom;
>   uint Front;
>   uint Back;
> }
> 
> unsafe void SomeRandomBoxApi(Box b)
> {
>   pComObject.SomeRandomBoxApi((_D3DBOX*)&b);
> }
> 
> Now the question is, since SomeRandomBoxApi takes a pointer 
> to a _D3DBOX (which is equivalent to a pointer to a Box), why 
> pass in the Box by value?
> 
> This would be (much?) more efficient:
> 
> unsafe void SomeRandomBoxApi(ref Box b)
> {
>   fixed(Box* p = &b)
>   {
>     pComObject.SomeRandomBoxApi((_D3DBOX*)p);
>   }
> }

===================================
This list is hosted by DevelopMentorŪ  http://www.develop.com
Some .NET courses you may be interested in:

NEW! Guerrilla ASP.NET, 17 May 2004, in Los Angeles
http://www.develop.com/courses/gaspdotnetls

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to