File tree Expand file tree Collapse file tree 1 file changed +20
-2
lines changed 
runtime/src/main/java/com4j Expand file tree Collapse file tree 1 file changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -356,14 +356,32 @@ public int comEnumValue() {
356356        }
357357    }
358358
359+     /** 
360+      * Determine the correct size of {@link Variant}. 
361+      * 
362+      * The size of the variant depends on whether this is 
363+      * a 32 or 64 bit system due to pointers in the structure 
364+      * definition.  See https://docs.microsoft.com/en-gb/windows/desktop/api/oaidl/ns-oaidl-tagvariant 
365+      */ 
366+     private  static  int  variantSize () {
367+ 	/* Typical os.arch values: `x86_64`, `amd64` */ 
368+         String  model  = System .getProperty ("os.arch" );
369+         if  (model .indexOf ("64" ) != -1 ) {
370+             return  24 ;
371+         }
372+         return  16 ;
373+     }
374+ 
375+     private  static  final  int  variantSize  = variantSize ();
376+ 
359377    /** 
360378     * Creates an empty {@link Variant}. 
361379     */ 
362380    public  Variant () {
363-         image  = ByteBuffer .allocateDirect (16 );
381+         image  = ByteBuffer .allocateDirect (variantSize );
364382        image .order (ByteOrder .LITTLE_ENDIAN );
365383        // The initial content of a buffer is, in general, undefined. See the documentation of java.nio.Buffer. 
366-         byte [] b  = new  byte [16 ]; // this initializes the array with zeros 
384+         byte [] b  = new  byte [variantSize ]; // this initializes the array with zeros 
367385        image .put (b ); // this prints the zeros to the buffer to guarantee, that the buffer is initialized with zeros. 
368386        image .position (0 );
369387    }
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments