IBM Smalltalk allows other languages to call Smalltalk through the EsEntryPoint mechanism. An EsEntryPoint is an object that prototypes a function in another language such as C. An EsEntryPoint contains the Smalltalk receiver and selector as well as the types of the parameters and any return value.
For example, to create an EsEntryPoint for the WindowProc function in Windows, you can use the following code in the class OSEventManager:
initializeWindowClass "Private - Get the standard window procedure and register the window class in the OS." | windowProc address | "Get the address of the window proc and install the receiver and selector. This message is sent from the window proc for every OS message." windowProc :=
EsEntryPoint receiver: self selector: #windowProc:msg:with:with: callingConvention: 'c' arrayBased: false parameterTypes: #(uint32 uint32 uint32 uint32) returnType: #int32.
windowProc failAddress: DefWindowProc address. address := windowProc address. "Register the Smalltalk window procedure." WindowClass := 'WINDOWPROC'. Hab winRegisterClass: WindowClass pfnWndProc: address flStyle: CsSizeredraw cbWindowData: 4.
To use an EsEntryPoint, create it and send it the message address. The result is an integer that can be passed out to a PlatformFunction that requires a function pointer as a parameter. When the external language calls the function pointer, IBM Smalltalk converts the parameters into Smalltalk objects and sends the message designated by the receiver and selector of the EsEntryPoint. The receiver parameter can be any Smalltalk object. The selector parameter must be a Symbol. parameterTypes is an array of type names and returnType is a single type name. The callingConvention parameter must be a string that is one of the valid IBM Smalltalk calling conventions. For details about platform-specific calling conventions, see Platform requirements.
There are two kinds of EsEntryPoints, depending on the value of arrayBased parameter when an EsEntryPoint is created. If arrayBased is false, the selector must take the same number of parameters as the number of parameters in the parameterTypes array; that is, one per external language parameter. If arrayBased is true, the selector must take one parameter, which is an array of all the parameters.
Note: | When using an EsEntryPoint, you do not need to make any of the objects (the receiver, selector, or the EsEntryPoint itself) fixed. |