Hi all, 2012/11/6 Igor Stasenko <siguctua@gmail.com>
On 2 November 2012 06:05, Torsten Bergmann <astares@gmx.de> wrote:
Hi Igor,
in Win32 often one passes NULL as argument (for instance if a function has an argument "handle to a window", then a hWnd of NULL can be given).
For instance when I have
shellExecute: hwnd operation: lpOperation file: lpFile parameters: lpParameters directory: lpDirectory show: nShowCmd <primitive: #primitiveNativeCall module: #NativeBoostPlugin>
^ self nbCall: #( HINSTANCE ShellExecuteA( HWND hwnd, LPCTSTR lpOperation, LPCTSTR lpFile, LPCTSTR lpParameters, LPCTSTR lpDirectory, INT nShowCmd)) module: 'Shell32.dll'
usually it controlled by options for code generator like #optCoerceNilToNull which will allow you to pass nil as valid argument.
What is missing, is that in your case you passing an instance of NBExternalObject, and NBExternalObjectType converter does not honors that option. This is easy to fix. I will add it as time allows me to do a pass on NativeBoost.
The NBFFICallout class(NBNativeCodeGen
class)>>handleFailureIn:nativeCode:
tells me that "an instance of NBWin32Window" is expected.
right, so what you can do is to synthesize an instance of NBWin32Window with handle value == 0. This will effectively behave as if you passed null argument. Sure it is not nearly elegant, so i mentioning it just for protocol :)
So currently I have to pass "NBWin32Window getFocus" as first argument. But often this is not necessary.
Another way of doing this is use convenience methods. Like with your function, you could have two methods for it, one which takes window argument, and another which doesn't:
shellExecute: lpOperation file: lpFile parameters: lpParameters directory: lpDirectory show: nShowCmd
^ self nbCall: #( HINSTANCE ShellExecuteA( 0, LPCTSTR lpOperation, LPCTSTR lpFile, LPCTSTR lpParameters, LPCTSTR lpDirectory, INT nShowCmd)) module: 'Shell32.dll'
yes I like this NB feature of directly put real values in external call definitions. But, having a NULL constant could also makes sense: ^ self nbCall: #( HINSTANCE ShellExecuteA( NULL, LPCTSTR lpOperation, LPCTSTR lpFile, LPCTSTR lpParameters, LPCTSTR lpDirectory, INT nShowCmd)) module: 'Shell32.dll' perhaps NULL is already there somewhere, I never look for it ;-) Luc
like that, you exposed API in proper way, i.e. without forcing users to pass meaningless nils every time :) and of course, in a second form (one which takes window handle as argument), you would expect a valid window handle, but not nil/null/whatever. That way it makes things less error prone.
I also havent found a constant pool with NULL or an accessor. Whats the prefered way to deal with NULL in NB?
Can you also please add me as a developer to http://www.squeaksource.com/NativeBoost My initials are "tbn"
done.
I would like to add several API functions for Win32 (ShellExecute, OutputDebugString, ...)
go ahead :)
Thx Torsten
-- Best regards, Igor Stasenko.