Newsgroups: comp.lang.smalltalk
Path: cantaloupe.srv.cs.cmu.edu!rochester!cornellcs!newsstand.cit.cornell.edu!news.kei.com!newsfeed.internetmci.com!in2.uu.net!spool.mu.edu!torn!nott!cu23.crl.aecl.ca!cp1423.crl.aecl.ca!mortonr
From: mortonr@crl.aecl.ca
Subject: Re: How to call c functions?
X-Nntp-Posting-Host: cp1423.crl.aecl.ca
Message-ID: <mortonr.4.00106419@crl.aecl.ca>
Lines: 51
Sender: usenet@cu23.crl.aecl.ca (USENET News System)
Organization: AECL-Research
X-Newsreader: Trumpet for Windows [Version 1.0 Rev A]
References:  <48q7qf$4t2@worak.kaist.ac.kr>
Date: Mon, 20 Nov 1995 21:23:21 GMT

In article <48q7qf$4t2@worak.kaist.ac.kr> wshan@clarinet.kaist.ac.kr.kaist.ac.kr (Wook-Sin Han ) writes:
>From: wshan@clarinet.kaist.ac.kr.kaist.ac.kr (Wook-Sin Han )
>Subject: How to call c functions?
>Date: 20 Nov 1995 15:45:18 GMT

>Is it possible to call c functions within smalltalk program..?

  In short...yup.  I've done it in Smalltalk/V v2.0 (MS-Windows
v3.11).  Essentially, you create a subclass of DynamicLinkLibrary 
called...TestDLL (for example, name it what you like) and create 
instance methods of the form:

setSeedstoX: seedX Y: seedY andZ: seedZ

    <api:SetSeed ushort ushort ushort ushort>
    self primitiveFailed

where "SetSeed" is the name of the C function in the DLL file
generated from your C compiler (whatever that is).  The "ushorts"
tell Smalltalk the data type of the parameters, and the last data
type is the type of the return value; ushort in this example.  
The reference manual for Smalltalk/V v2.0 has a list of relevant 
types which you could use.

You would then have code in another method (of a different class 
usually) of the form:

test  := TestDLL open.
test setSeedstoX: 10 Y: 20 andZ: 30.
        .
        .
        .
test close.

where "test" is a local variable to the method.  This would
result in the SetSeed C funtion being invoked with the actual 
parameters: 10, 20, and 30 whenever the setSeedstoX: method 
was invoked.

Regards,
Rob Morton
Atomic Energy of Canada Ltd.
Chalk River Laboratories
Chalk River, ON
Canada K0J 1J0
(613) 584-8811 ext. 6331
(613) 584-3311 ext. 6331
fax: (613) 584-1770
email: mortonr@crl.aecl.ca


