home *** CD-ROM | disk | FTP | other *** search
- /****************************************************************************\
- * *
- * StrucSam.js -- Examples of using the functions in StrucMem.dll. *
- * *
- * This script demonstrates the use of the six functions in StrucMem.dll. *
- * These functions are prototyped in StrucMem.js. There are constants defined *
- * in StrucMem.h (in the Include directory). *
- * *
- * Updated 10/22/96 by IntraBuilder Samples Group *
- * $Revision: 1.3 $ *
- * *
- * Copyright (c) 1996, Borland International, Inc. All rights reserved. *
- * *
- \****************************************************************************/
- //
- // Get the constant declarations for the types and sizes
- //
- #include strucmem.h
-
- //
- // Prototype the functions in strucmem.dll
- //
- _sys.scripts.run("strucmem.js");
-
- //
- // Create a structure like this:
- //
- // typedef struct _POLYTEXT {
- // int x;
- // int y;
- // UINT n;
- // LPCTSTR lpstr;
- // UINT uiFlags;
- // RECT rcl;
- // int *pdx;
- // } POLYTEXT;
- //
-
- // Compute the length manually and initialize string
-
- var str = new StringEx().replicate(" ",40);
-
- // Assign the values one by one
-
- var offset = 0;
-
- // set x to 123
- offset += SetStructNumber(str,offset,TYPE_INT,str.length,123);
-
- // set y to 234
- offset += SetStructNumber(str,offset,TYPE_INT,str.length,234);
-
- // set n to 345
- offset += SetStructNumber(str,offset,TYPE_UINT,str.length,345);
-
- // set lpstr to existing variable strVar
- var strVar = "Hi Mom";
- offset += SetStructCharPointer(str,offset,str.length,strVar);
-
- // set uiFlags to 456
- offset += SetStructNumber(str,offset,TYPE_UINT,str.length,456);
-
- // The rect object contains four longs. Set them to 1,2,3 and 4
- var rect = new StringEx().replicate(" ",16);
- SetStructNumber(rect,0,TYPE_LONG,rect.length,1);
- SetStructNumber(rect,SIZEOF_LONG,TYPE_LONG,rect.length,2);
- SetStructNumber(rect,SIZEOF_LONG*2,TYPE_LONG,rect.length,3);
- SetStructNumber(rect,SIZEOF_LONG*3,TYPE_LONG,rect.length,4);
- offset += SetStructString(str,offset,str.length,rect,rect.length);
-
- // set *pdx to existing variable strPdx representing an int 567
- var strPdx = new StringEx().replicate(" ",4);
- SetStructNumber(strPdx,0,TYPE_INT,strPdx.length,567);
- offset += SetStructVoidPointer(str,offset,str.length,strPdx);
-
- //
- // str now contains the structure contents and can be passed to an external
- // function. It might theoretically look like this:
- //
- // extern int SomeFunction(void*) "somedll.dll"
- // x = SomeFunction(str);
- //
- // If you are supposed to pass an empty structure to the dll and it writes
- // the data then you can do this:
- //
- // str = new StringEx().replicate(" ",40);
- // x = SomeFunction(str);
- //
- // Then to parse the structure string you do as follows. Note: it is
- // not necessary to parse the entire structure string. If you only
- // want to see one member, you can calculate the offset and then get
- // just that one member.
- //
-
- poly = new Object();
- offset = 0;
-
-
- // get x (should be 123)
- poly.x = GetStructNumber(str,offset,TYPE_INT);
- offset += SIZEOF_INT;
-
- // get y (should be 234)
- poly.y = GetStructNumber(str,offset,TYPE_INT);
- offset += SIZEOF_INT;
-
- // get n (should be 345)
- poly.n = GetStructNumber(str,offset,TYPE_UINT);
- offset += SIZEOF_UINT;
-
- // get lpstr. Initialize to string large enough to hold expected result
- var strVar2 = new StringEx().replicate(" ",100);
-
- #ifdef __asian__
- var len = GetStructWCharPointer(str,offset,0,strVar2,strVar2.length);
- #else
- var len = GetStructCharPointer(str,offset,0,strVar2,strVar2.length);
- #endif
-
- poly.lpstr = strVar2.substring(0,len-1);
- offset += SIZEOF_POINTER;
-
- // get uiFlags (shoudl be 456);
- poly.uiFlags = GetStructNumber(str,offset,TYPE_UINT);
- offset += SIZEOF_UINT;
-
- // The rect object contains four longs. Get each one to 1,2,3 and 4
- poly.rect = new Object();
- var rect = new StringEx().replicate(" ",16);
- GetStructString(str,offset,str.length,rect,rect.length);
- poly.rect.left = GetStructNumber(rect,0,TYPE_LONG);
- poly.rect.right = GetStructNumber(rect,SIZEOF_LONG,TYPE_LONG);
- poly.rect.top = GetStructNumber(rect,SIZEOF_LONG*2,TYPE_LONG);
- poly.rect.bottom = GetStructNumber(rect,SIZEOF_LONG*3,TYPE_LONG);
- offset += 16;
-
- // get *pdx (copy pointer content to var, then parse as int)
- var strPdx2 = new StringEx().replicate(" ",4);
- GetStructVoidPointer(str,offset,4,strPdx2,strPdx2.length);
- poly.pdx = GetStructNumber(strPdx2,0,TYPE_INT);
-
- _sys.inspect(poly);
-