" Example of DLL call Didier BESSET 100020, 2313 (c) All rights reserved The following methods show how to call a DLL written in Borland C++ " "Opening the DLL The class (or global) variable LibraryCall will contain the instance of the DLL. This call must be performed only once but the DLL instance is not kept accross ST restart (i.e. what is saved in the image is a handle which has no meaning when the image is loaded anew)! One way around is to use an intialize at startup class which would reset the variable LibraryCall to nil and have in any reference to LibraryCall a check: LibraryCall isNil ifTrue: [xxx loadDLL] MyDLL is a subclass of DynamicLinkLibrary " loadDLL "Load the DLL" LibraryCall := MyDLL open: (File fileName: 'MYPRIM.DLL' in: Disk) "************* Methods for the object calling the DLL **************" " Performing the DLL call for an object of class XXX (i.e. your own construct). The last parameter of the DLL call is used to retrieve the result. Thus, it must be copied into non-ST memory. NB. I do it for every parameter which exceeds small sizes regardless of I/O" read: type track: track sector: sector "Answers the mirror track of the specified address" | result localBuffer answer| result := String new: (1 + (self class sectorSize: type)). localBuffer := WinAddress copyToNonSmalltalkMemory: result. answer := LibraryCall read: unit type: type track: track sector: sector buffer: (localBuffer asParameter). answer = 0 ifFalse:[ localBuffer free. ^answer]. WinAddress copyFrom: localBuffer to: result count: result size. localBuffer free. ^Array with: (result copyFrom: 2 to: result size) with: (result integerAt: 0 length: 1) "******* Corresponding DLL method for LibraryCall, an instance of a subclass of DynamicLinkLibrary *********" read: unit type: type track: track sector: sector buffer: aBuffer "Reads the physical record at the specified address - unit drive unit - type format type - track track address - sector sector - aBuffer a String object (no size check is done!) 1st byte contains the auxilliary field" ^self error: 'debugRead:type:track:sector:buffer: failed!' "******* Corresponding BORLAND C++ code (this code reads a SCSI device) ********" #define DLL_ENTRY unsigned short FAR PASCAL _export DLL_ENTRY OBDEBUGRD( short unit, short type, short track, short sector, char* buffer) { short error; if ( unit < 0 || unit > 7 ) return OMC_BadParam; error = OMCDriveReady( unit); if ( error != OMC_NoError ) return error; return OMCReadSector( unit, type, (long) track, sector, 1, buffer + 1, buffer); }