help please-----please help about array in DLL 
Author Message
 help please-----please help about array in DLL

 Some weeks ago I posted a query about passing arrays from
 Smalltalk/V Windows to a DLL library written in C. Since then
 I have tried a number of things to access a simple array
 (e.g: array of integer or array of float) and got nowhere.
 I sometimes can access the first element of the array but that's all.
 The major problem is that I don't know the C structure of a Smalltalk array.  
 A typical set-up I try is this:

 in object.h
 ------------
      struct arrayObj  
        { struct headerObj head;
          short arrayX[20];
        } |
          |
          +--> or struct object arrayX[20], or struct floatObj arrayX[20]......

 in my test DLL
 --------------
  VOID Pascal testFunc (struct arrayObj far *array1)
      {
        array1->arrayX[0] = 5;
        array1->arrayX[1] = 6;
      }  |
         |
         +---> or array1->arrayX[0].dig = 5.5; when using struct floatObj.

 in Smalltalk
 -------------
   after openning TESTDLL
      | ar |
  ar := Array new: 20.
  ar at: 1 put: 1.
  ar at: 2 put: 2.
  TESTDLL testMethod: ar.
  ar inspect.

where
 testMethod: anArray
 <testFunc: self none>

 When I inspect ar I usually get 'Unrecoverable Application Error', and
 that means for me, rebooting the machine (a 386 SX) a long and tedious
 process. I have been lucky so far I haven't corrupted the memory, I think.
 There is an example vaguely explained in userprim.txt, but I don't
 understand it. I am embarking on a speech recognition project, and
 would like to use Smalltalk/V Windows, but I have been stuck for
 somtimes with this problem.
 If there is anyone out there who knows how it is done or if there is
 some literature on the subject, please let me know.

 ----- many, many thanks to all ----------------------------

 R. Wathelet.



Sun, 28 Aug 1994 13:56:01 GMT  
 help please-----please help about array in DLL

Quote:

> Some weeks ago I posted a query about passing arrays from
> Smalltalk/V Windows to a DLL library written in C. Since then
> I have tried a number of things to access a simple array
> (e.g: array of integer or array of float) and got nowhere.
> I sometimes can access the first element of the array but that's all.
> The major problem is that I don't know the C structure of a Smalltalk array.  
> A typical set-up I try is this:

> in object.h
> ------------
>      struct arrayObj  
>    { struct headerObj head;
>          short arrayX[20];
>    } |
>      |
>          +--> or struct object arrayX[20], or struct floatObj arrayX[20]......

> in my test DLL
> --------------
>  VOID PASCAL testFunc (struct arrayObj far *array1)
>      {
>    array1->arrayX[0] = 5;
>        array1->arrayX[1] = 6;
>      }  |
>     |
>     +---> or array1->arrayX[0].dig = 5.5; when using struct floatObj.

> in Smalltalk
> -------------
>   after openning TESTDLL
>      | ar |
>  ar := Array new: 20.
>  ar at: 1 put: 1.
>  ar at: 2 put: 2.
>  TESTDLL testMethod: ar.
>  ar inspect.

>where
> testMethod: anArray
> <testFunc: self none>

> When I inspect ar I usually get 'Unrecoverable Application Error', and
> that means for me, rebooting the machine (a 386 SX) a long and tedious
> process. I have been lucky so far I haven't corrupted the memory, I think.
> There is an example vaguely explained in userprim.txt, but I don't
> understand it. I am embarking on a speech recognition project, and
> would like to use Smalltalk/V Windows, but I have been stuck for
> somtimes with this problem.
> If there is anyone out there who knows how it is done or if there is
> some literature on the subject, please let me know.

> ----- many, many thanks to all ----------------------------

> R. Wathelet.

You can't change Smalltalk/V objects the way you manipulate C-structs.
Of course, best advice I can give you is don't change Smalltalk/V
objects in the DLL, do all manipulation in the Smalltalk.  In all
practical terms, you can do that in probably 99% of the case.  

The major problem with this example is that Smalltalk integer/float
is different from C int/float, thus you have to convert C int 5 or 6
into SmalltalkV objects, thus your code would be something like this:

 VOID PASCAL TestFunction (struct object *array1   )
   {
       struct object *firstNum,*secondNum;

       firstNum = array1->arrayX[0];
       secondNum = array2->arrayX[1];
       SEG(firstNum) = 5;
       SEG(secondNum) = 6;
       array1->arrayX[0] = firstNum;
       array2->arrayX[1] = secondNum;
   }

This kind of code is of course not really elegant, better solution is
to isolate Smalltalk int/float objects from C int/float types, that is
store your array in either in purely in smalltalk object types and
do all assignment in the smalltalk or use byte-format type objects such as
'String' class or 'ByteArray' and do manipulation in DLL which of course
will lead to better optimization in case of large numeric manipulations.
The design will be different on context of each application.
If you want more help, please describe exactly what you want to accomplish.

Hope this helps.

------------------
Sehyo Chang
Wizard's Castle



Mon, 29 Aug 1994 02:25:59 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. please, please, please, please, help

2. will someone please, please, please, please HELP me?!!

3. VSE 3.1 Repository Problem: Please help (please please?)

4. PLEASE PLEASE PLEASE HELP !!!!!!!!!!!!

5. please,please please do help us

6. HELP !..PLEASE,PLEASe,PLEAse,PLEase,PLease,Please,please.....

7. Calling DLLs from TCL using ffidl or dll - please help

8. Ord Function HELP Please HELP HELP HELP

9. ***HELP***HELP***HELP***Please.

10. HELP HELP HELP PLEASE Ordinal Function

11. Help Help Help Please

12. Please Please Help - Clarion External Report Wrtter

 

 
Powered by phpBB® Forum Software