Click here to Skip to main content
16,004,919 members
Home / Discussions / Java
   

Java

 
AnswerRe: Is it possible to make games using Java for Nokia phones? Pin
Richard MacCutchan19-Oct-09 9:03
mveRichard MacCutchan19-Oct-09 9:03 
GeneralRe: Is it possible to make games using Java for Nokia phones? Pin
Nagy Vilmos19-Oct-09 21:34
professionalNagy Vilmos19-Oct-09 21:34 
GeneralRe: Is it possible to make games using Java for Nokia phones? Pin
Richard MacCutchan19-Oct-09 22:15
mveRichard MacCutchan19-Oct-09 22:15 
GeneralRe: Is it possible to make games using Java for Nokia phones? Pin
Nagy Vilmos19-Oct-09 23:13
professionalNagy Vilmos19-Oct-09 23:13 
QuestionThreading issue Pin
Amrutha.v17-Oct-09 5:32
Amrutha.v17-Oct-09 5:32 
AnswerRe: Threading issue Pin
427748017-Oct-09 21:32
427748017-Oct-09 21:32 
AnswerRe: Threading issue Pin
Luc Pattyn19-Oct-09 2:49
sitebuilderLuc Pattyn19-Oct-09 2:49 
QuestionTurning a float[] into a Variant? Pin
Judah Gabriel Himango15-Oct-09 18:01
sponsorJudah Gabriel Himango15-Oct-09 18:01 
Be forewarned: this is a difficult question; folks on StackOverflow, Eclipse forums, Sun forums, and ComEclipse support, and others have been stumped by it. If you can answer this, you're a certified programming god.

---

How can I create an SWT Variant object that contains a float array?

Since SWT's Variant type doesn't support this out of the box, here's my attempt to make this work:

public static Variant CreateVariantForArray(float[] array)
	{
		if(array == null){
			return null;
		}
		
	    short FADF_FIXEDSIZE = 0x10;
	    short FADF_HAVEVARTYPE = 0x80;
	    short fFeatures = (short) (FADF_FIXEDSIZE | FADF_HAVEVARTYPE);
	    int elementSize = 4;
	    
	    // Copy the array into unmanaged memory.
	    int pvData = OS.GlobalAlloc(OS.GMEM_FIXED | OS.GMEM_ZEROINIT,
	        4 * array.length);
	    OS.MoveMemory(pvData, array, 4 * array.length);
        
	    // Create a safearray in memory
	    // 12 bytes for cDims, fFeatures and cbElements + 4 bytes for pvData +
	    // number of dimensions * (size of safearraybound)
	    int sizeofSafeArray = 12 + 4 + 1 * 8;
	    int pSafeArray = OS.GlobalAlloc(OS.GMEM_FIXED | OS.GMEM_ZEROINIT,
	        sizeofSafeArray);
	    // Copy the data into the safe array
	    int offset = 0;
	    OS.MoveMemory(pSafeArray + offset, new short[] { 1 }, 2); // number of dimensions
	    offset += 2;
	    OS.MoveMemory(pSafeArray + offset, new short[] { fFeatures }, 2); // features
	    offset += 2;
	    OS.MoveMemory(pSafeArray + offset, new int[] { elementSize }, 4); // size of an element in array
	    offset += 4;
	    OS.MoveMemory(pSafeArray + offset, new int[] { 0 }, 4); // number of times array has been locked
	    offset += 4;
	    OS.MoveMemory(pSafeArray + offset, new int[] { pvData }, 4); // pointer to the data
	    offset += 4;
	    OS.MoveMemory(pSafeArray + offset, new int[] { array.length }, 4); // elements in dimension
	    offset += 4;
	    OS.MoveMemory(pSafeArray + offset, new int[] { 0 }, 4); // lower bound of dimension
	    offset += 4;
	    // Create a variant in memory to hold the safearray
	    int pVariant = OS.GlobalAlloc(OS.GMEM_FIXED | OS.GMEM_ZEROINIT, Variant.sizeof);
	    short vt = (short) (OLE.VT_ARRAY | OLE.VT_R4);
	    OS.MoveMemory(pVariant, new short[] { vt }, 2);
	    OS.MoveMemory(pVariant + 8, new int[] { pSafeArray }, 4);
	    return new Variant(pVariant, OLE.VT_VARIANT);
	}


It doesn't work. Any idea why? Or better yet, got any code that takes a float[] and gives back a Variant?



Religiously blogging on the intarwebs since the early 21st century: Kineti L'Tziyon
Judah Himango



AnswerRe: Turning a float[] into a Variant? Pin
427748016-Oct-09 6:19
427748016-Oct-09 6:19 
GeneralRe: Turning a float[] into a Variant? Pin
Judah Gabriel Himango16-Oct-09 6:28
sponsorJudah Gabriel Himango16-Oct-09 6:28 
GeneralRe: Turning a float[] into a Variant? Pin
427748016-Oct-09 6:36
427748016-Oct-09 6:36 
GeneralRe: Turning a float[] into a Variant? Pin
Judah Gabriel Himango16-Oct-09 6:38
sponsorJudah Gabriel Himango16-Oct-09 6:38 
GeneralRe: Turning a float[] into a Variant? Pin
427748016-Oct-09 9:24
427748016-Oct-09 9:24 
GeneralRe: Turning a float[] into a Variant? Pin
Judah Gabriel Himango16-Oct-09 9:40
sponsorJudah Gabriel Himango16-Oct-09 9:40 
GeneralRe: Turning a float[] into a Variant? Pin
427748016-Oct-09 10:05
427748016-Oct-09 10:05 
GeneralRe: Turning a float[] into a Variant? Pin
Judah Gabriel Himango16-Oct-09 10:09
sponsorJudah Gabriel Himango16-Oct-09 10:09 
Questioncode coverage Pin
Shakirin Amin15-Oct-09 8:47
Shakirin Amin15-Oct-09 8:47 
AnswerRe: code coverage Pin
Richard MacCutchan15-Oct-09 9:24
mveRichard MacCutchan15-Oct-09 9:24 
GeneralRe: code coverage Pin
Shakirin Amin16-Oct-09 4:42
Shakirin Amin16-Oct-09 4:42 
GeneralRe: code coverage Pin
Richard MacCutchan16-Oct-09 5:00
mveRichard MacCutchan16-Oct-09 5:00 
GeneralRe: code coverage Pin
Shakirin Amin16-Oct-09 6:17
Shakirin Amin16-Oct-09 6:17 
GeneralRe: code coverage Pin
Richard MacCutchan16-Oct-09 6:37
mveRichard MacCutchan16-Oct-09 6:37 
GeneralRe: code coverage Pin
David Skelly16-Oct-09 6:16
David Skelly16-Oct-09 6:16 
GeneralRe: code coverage Pin
427748016-Oct-09 6:22
427748016-Oct-09 6:22 
GeneralRe: code coverage Pin
Shakirin Amin16-Oct-09 7:00
Shakirin Amin16-Oct-09 7:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.