[prev in list] [next in list] [prev in thread] [next in thread] 

List:       ms-java-com
Subject:    Re: Custom Marshalling pointer to pointer to "struct"
From:       Tom Stuart <tstuart () CONCEPT5 ! COM>
Date:       1999-02-25 22:46:01
[Download RAW message or body]


Thanks for the response, Chad.  I'm glad you jumped in.  I've just
started working with COM.  The "struct" in question appears as a
parameter in a method for a JCW class.   I created a new class
whose only purpose was to handle the marshalling of this parameter,
and added the toJava and toExternal  methods, but couldn't quite see
how it would all fit together.  For instance, in some example code you
produced, the toJava and toExternal methods contain an "int ppStruct"
parameter which seems to be  a pointer to a  pointer to a native structure.
I'm confused about where this value comes from since the methods are
invoked automatically by the VM.  So, I started with something like the
following:

public class TheMyStructClassCustomMarshaller
{
   public static MyStructClass toJava( int ppStruct, int Flags )
   {
      // Is this the correct order?

      int pStruct = DllLib.read4( ppStruct );
      return  ComLib.ptrToStruct( Class.forName("MyStructClass"), pStruct );
   }

  public static void toExternal( MyStructClass myStruct, int Flags, int
ppStruct )
  {
        //  code similar to below
  }

That is about as far as I got.  This is a slightly different scenario, I
think.
I specify this class in the "customMarshal"  parameter of the @com.parameters
directive for any method with the "**MyStructClass" pattern in it.
Is this approach workable?  What am I missing?



Chad Verbowski wrote:

> Actually to be totally correct you would need to allocate/free the 4 bytes
> for ptrPtrStructFoo in a constructor, and some sort of destructor.
>
> -----Original Message-----
> From: Chad Verbowski [mailto:chadv@MICROSOFT.COM]
> Sent: Thursday, February 25, 1999 12:38 PM
> To: Java-COM@DISCUSS.MICROSOFT.COM
> Subject: Re: Custom Marshalling pointer to pointer to "struct"
>
> You could try something like this:
>
> /**
>  * @com.struct()
>  */
> public class MyStruct{
>
>         private int ptrPtrStructFoo;
>
>         public FooStruct getFooStruct(){
>
>                 return com.ms.dll.DllLib.ptrToStruct(FooStruct.class,
>                         com.ms.dll.DllLib.read4(ptrPtrStructFoo));
>         }
>
>         public void setFooStruct(FooStruct f){
>                 int handle = com.ms.dll.Root.alloc(f);
>                 com.ms.dll.DllLib.write4(ptrPtrStructFoo,
>                         com.ms.dll.DllLib.addrOf(handle));
>                 com.ms.dll.Root.free(handle);
>         }
> }
>
> -----Original Message-----
> From: Tom Stuart [mailto:tstuart@CONCEPT5.COM]
> Sent: Thursday, February 25, 1999 12:12 PM
> To: Java-COM@DISCUSS.MICROSOFT.COM
> Subject: Custom Marshalling pointer to pointer to "struct"
>
> I'm having difficulty determining a good way to custom marshal a
> pointer to a pointer to a "struct".  I just read Chad's new paper on
> "Using COM Objects from Java", and that is certainly helpful,
> but I still have some areas of uncertainty.  It this particular case,
> the jactivex tool was unable to create the appropriate com directives,
> and complained about  "Too many indirections".  It was able to
> generate com directives for the "structure" itself, but was thrown by
> the double pointer pattern.  Does anyone know of an effective approach
> for dealing with this situation?  I am not even sure what the "type"
> should be in the "@com.parameter" directive.
>
> ----------------------------------------------------------------
> Users Guide http://www.microsoft.com/workshop/essentials/mail.asp
> contains important info including how to unsubscribe.  Save time, search
> the archives at http://discuss.microsoft.com/archives/index.html
>
> ----------------------------------------------------------------
> Users Guide http://www.microsoft.com/workshop/essentials/mail.asp
> contains important info including how to unsubscribe.  Save time, search
> the archives at http://discuss.microsoft.com/archives/index.html
>
> ----------------------------------------------------------------
> Users Guide http://www.microsoft.com/workshop/essentials/mail.asp
> contains important info including how to unsubscribe.  Save time, search
> the archives at http://discuss.microsoft.com/archives/index.html

----------------------------------------------------------------
Users Guide http://www.microsoft.com/workshop/essentials/mail.asp
contains important info including how to unsubscribe.  Save time, search
the archives at http://discuss.microsoft.com/archives/index.html

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic