Jeff: Wow, this was a tricky one ! I tried your solution and it's OK. Thanks you so much for helping me: I wouldn't have found it by myself ... I will now try my new knowledge on other external libs. Take care, ==christophe > Howdy, Coussement: > > Always base your routines off the C version of these > functions, rather than the Visual Basic function that the > above describes. The addressing mode of the different > parameters isn't immediately clear when looking at the VB > declaration. > > So we open MSVC and find: > > BOOL GetUserName( > LPTSTR lpBuffer, // address of name buffer > LPDWORD nSize // address of size of name buffer > ); > > (ie, to decode the "Hungarian notation" above: long pointer to > string == char* and long pointer to DWORD == int* ) > > Okay, now this is probably one of the most important tricks > with REBOL/Command which is undocumented, though if you're a C > programmer, it should be fairly intuitive. This really needs > to be published into an addendum, probably, so here it goes: > > In C, a pointer to a struct is a pointer to the struct's first > element. In REBOL/Commands, all structs are passed by > reference. What's this mean? This means struct! values in > REBOL/Command allow you to make references to values, for > example, we need this int*. REBOL/Command doesn't directly > provide support for pointer to int, but it's easy to make it > using a struct! value to wrap our integer, for example: > > advapi32: load/library %advapi32.dll > > get-user-name: make routine! [ > name [string!] > l-ref [struct! [len [integer!]]] > return: [integer!] > ] advapi32 "GetUserNameA" > > insert/dup name: copy "" " " 255 ;-pad the buffer > l-ref: make struct! [len [integer!]] [255] > get-user-name name l-ref > trim name > == "jeff" > > -- To unsubscribe from this list, please send an email to [EMAIL PROTECTED] with "unsubscribe" in the subject, without the quotes.
[REBOL] Re: Problems with accessing external lib in /Command
CRS - Psy Sel/SPO, COUSSEMENT Christophe, CPN Wed, 07 Mar 2001 00:03:58 -0800
