• Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

AltME groups: search

Help · search scripts · search articles · search mailing list

results summary

worldhits
r4wp13
r3wp64
total:77

results window for this page: [start: 1 end: 77]

world-name: r4wp

Group: #Red ... Red language group [web-public]
DocKimbel:
23-Aug-2012
Your code works fine here (REBOL 2.7.6): 

>> lib: load/library %builds/test.dll
>> f1: make routine! [a [integer!] return: [integer!]] lib "f1"
>> f1 123
== 124
DocKimbel:
23-Aug-2012
Works fine here: 

>> lib: load/library %builds/temp.dll
>> f1: make routine! [a [integer!] return: [integer!]] lib "f1"
>> f1 123
== 124
Rebolek:
23-Aug-2012
Same under WXP (virtual) with both 2.7.6 and 2.7.8 . It's probably 
some bad day :)

>> lib: load/library %temp.dll
** Access Error: Cannot open temp.dll as library
** Near: lib: load/library %temp.dll
MagnussonC:
23-Aug-2012
lib: do load/library %temp.dll
** Script Error: MZ€ has no value
** Near: lib: do load/library %temp.dll
DocKimbel:
23-Aug-2012
Gregg: could you try to load this DLL using R2: http://box.lebeda.ws/~rebolek/temp.dll

lib: load/library %temp.dll
f1: make routine! [a [integer!] return: [integer!]] lib "f1"
DocKimbel:
23-Aug-2012
REBOL does not return an accurate error msg when failing to find 
a DLL file:

>> lib: load/library %xyz.dll
** Access Error: Cannot open xyz.dll as library
** Near: lib: load/library %xyz.dll


This can be misleading thinking that %xyz.dll exists but is invalid, 
while it doesn't exists at all. So for the people having issue with 
%temp.dll, check if the DLL is present in the working folder and 
that you have correctly CD to that folder in your REBOL session.
MagnussonC:
23-Aug-2012
>> lib: do load/library %temp.dll
>> f1 123
** Script Error: f1 has no value
** Where: halt-view
** Near: f1 123
DocKimbel:
23-Aug-2012
MagnussonC: you need to define the routine! first:

lib: do load/library %temp.dll
f1: make routine! [a [integer!] return: [integer!]] lib "f1"
f1 123
sqlab:
23-Aug-2012
same problem here

>> read %temp.dll

== {MZ€^@^A^@^@^@^D^@^P^@ÿÿ^@^@@^A^@^@^@^@^@^@@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@€^@^@^@^N
^_º^N...
>> lib:  load/library %temp.dll
** Access Error: Cannot open temp.dll as library
** Near: lib:  load/library %temp.dll
	
but
>> load/library %shell32.dll
>>
DocKimbel:
24-Aug-2012
Pekr and Rebolek: could you try to use ProcessMonitor (PM) to see 
if we can get a clue about what is blocking the DLL loading from 
R2?


1) Download it from: http://technet.microsoft.com/en-us/sysinternals/bb896645.aspx
2) Run it

3) Open a REBOL console and CD to the folder where the DLL is located

4) In PM, drag'n drop the "target" icon to the REBOL console window
5) Type in console: lib: load/library %temp.dll

6) Scroll down in the PM window to look for rebol.exe process entries, 
look for failure reports in Result and Detail columns...
Pekr:
25-Aug-2012
>> exists? %temp.dll
== true
>> lib: load/library %temp.dll
>>
Rebolek:
27-Aug-2012
I have this code for Red/System DLL:

f-1423181: func [a [integer!] return: [integer!]] [a + 1]
f-10584225: func [a [integer!] return: [integer!]] [a - 1]
#export [f-1423181 f-10584225]

and this code in R2 to load it which throws error:

>> lib: load/library %builds/routines.dll

>> foo: make routine!  [a [integer!] return: [integer!]] lib "f-1423181"

>> bar: make routine!  [a [integer!] return: [integer!]] lib "f-10584225"
** Access Error: Cannot open f-10584225

Is it Red/System or R2 problem?
DocKimbel:
7-Nov-2012
Kaj: that's right. If you want addresses to be resolved, we need 
to add a in-memory linker. It will basically just resolve all the 
addresses. But that would not work as is with the imports that expect 
to be statically linked. So, a custom dynamic loader would be required 
(same requirements as for implementing LOAD/LIBRARY and MAKE ROUTINE!).

world-name: r3wp

Group: All ... except covered in other channels [web-public]
Micha:
26-Apr-2007
why my code not work ? 


REBOL [ title: "hook Mouse" ]


user32: load/library %user32.dll

Kernel32: load/library %Kernel32.dll

; const

WH_MOUSE:  7
mouseHook: 0



GetCurrentThreadId:  make routine! [

  return: [integer!] ] Kernel32 "GetCurrentThreadId"



SetWindowsHookExW:  make routine! [  

 idHook [integer!]
 lpfn [callback! [int int  int return: [int]]]
 hmod [integer!]
 dwThreadId [integer!]
 return: [integer!] ] user32 "SetWindowsHookExA"



MouseProc: func [  code  wParam  lParam ] [ print code   ]



hThreadId: GetCurrentThreadId

SetWindowsHookExW WH_MOUSE  :mouseProc 0 hThreadId

halt
Group: Ann-Reply ... Reply to Announce group [web-public]
Micha:
4-Sep-2009
rebol[]
;------------------


system/words/&: func [

  "Return the memory address of a binary, string or struct as a binary 
  value"
		b [binary! string! struct!]
	][

  to-integer reverse  third make struct! [s [string!]] reduce [either 
  struct? b [third b][b]]
	]


;----------

  integer: make struct! [
        value   [integer!]
    ] none

;-------------------


kernel32: load/library %kernel32.dll


CreateThread:  make routine! [ 

pThreadAttributes [integer!] 

dwStackSize[integer!] 

lpStartAddress [callback [int  return: [int]]]

lpParameter[integer!] 

dwCreationFlags[integer!] 

 lpThreadId [integer!] 

 return: [integer! ] ] kernel32"CreateThread"

;----------

i: 0


thread:   func  [ n ][  i: i + 1   ]  

;-----------------

loop 10 [  
print t: CreateThread 0 0 :thread  0 0  & integer
wait 0.1
print i
]
halt
Maxim:
24-Aug-2010
replace the lib loading line with this:


k32-lib: load/library join to-file get-env "systemroot" %"/system32/Kernel32.dll"
AdrianS:
24-Aug-2010
not quite - the correct path is still prefixed with the directory 
of the rebol exe

** Access Error: Cannot open /C/dev/r2/C:\Windows/system32/Kernel32.dll
** Near: k32-lib: load/library join to-file get-env
Group: Core ... Discuss core issues [web-public]
shadwolf:
14-Jan-2005
I'm not an expert on struct! far of that (wel in C yes but in REBOL 
no and I think it's because I'm not using load/library capability 
until now) but that's a good discution to point to difficulties on 
this kind of task and I hope help rebol Core to have a bettre handling 
of that
Graham:
9-Jul-2005
win-lib: make object! [	
	user-lib: load/library %user32.dll
	SetWindowText: make routine! [
		handle			[integer!]
		Title			[string!]
		return:			[integer!]
	] user-lib "SetWindowTextA"
	
	set 'WindowTitle func [
		Title [string!] 
	] [
		SetWindowText get-modes system/ports/system 'window Title
	]
]

WindowTitle "eFishAnt Ink"
JaimeVargas:
29-Dec-2005
Rebol []

comment [
	; example usage:
	kernel: load/library %kernel32.dll

 routine-call kernel "MulDiv" [int] [3 [integer!] 2 [integer!] 1 [integer!]] 
 ; == 6
]

routine-call: func [
	library [library!]
	routine-name [string!]
	return-spec [block!]
	arguments [block!] 

 /typed {Arguments is block structure is: [argument-value [datatype] 
 ...]}
	/local routine spec call argument type typed-rule
] [
	spec: make block! length? arguments
	call: make block! (length? arguments) / 2 + 1
	insert call [return routine]
	typed-rule: copy []
	if typed [typed-rule: [set type skip]]
	parse reduce arguments [
		any [
			set argument skip
			typed-rule
			(
				insert/only tail spec 'argument
				insert/only tail spec either typed [
					type
				][
					reduce [type?/word get/any 'argument]
				]
				insert/only tail call get/any 'argument
			)
		]
	]
	insert tail spec [return:]
	insert/only tail spec return-spec
	routine: make routine! spec library routine-name
	do call
]

use [libc zero-char as-rebol-string malloc][
	libc: load/library %/usr/lib/libc.dylib ; osx variable

	zero-char: #"^@"

	as-rebol-string: func [
		[catch]
		s [string!] 
		/local pos
	][

  unless pos: find s zero-char [throw make error! "s is not a c-string"]
		s: head remove/part pos tail s
		replace/all s "\n" newline
		replace/all s "\t" tab
	]
	
	malloc: func [
        size [integer!] "size in bytes"
    ][
        head insert/dup copy {} zero-char size
    ]

	sprintf: func [
		spec {block structure is: [format values ...]}
		/local s
	][
		s: malloc 4096
		insert/only head spec 's
		routine-call libc "sprintf" [int] spec
		as-rebol-string s
	]
	
	printf: func [
		spec {block structure is: [format values ...]}
	][
		print sprintf spec
	]
]
Gregg:
15-Jul-2006
; Does this work for you Graham?

REBOL []

; GET-ENV is a standard REBOL function now

; environment variable APIs
; msvcrt.dll
; getenv _putenv _environ
; char *getenv( const char *varname );
; int _putenv( const char *envstring );

lib:  load/library %msvcrt.dll

get-env: make routine! [
	varname [string!]
	return: [string!]
] lib "getenv"

put-env: make routine! [
	env-string [string!]
	return:    [integer!]
] lib "_putenv"

remove-env-var: func [name [string!]] [put-env join name "="]

env-var-exists?: func [name [string!]] [
	either "^@" = get-env name [false][true]
]

tz-set: make routine! [
	return:    [integer!]
] lib "_tzset"

print get-env "path"
print get-env "lib"
print get-env "temp"
print get-env "test"

if 0 <> put-env "test=blah" [
	print "error writing environment variable"
]
print get-env "test"
remove-env-var "test"
print mold get-env "test"

print get-env "TZ"
tz-set

free lib

halt
Graham:
18-May-2008
win-lib: make object! [
	
	user-lib: load/library %user32.dll

	SetWindowText: make routine! [
		handle			[integer!]
		Title			[string!]
		return:			[integer!]
	] user-lib "SetWindowTextA"
	
	set 'WindowTitle func [
		Title [string!] 
	] [
		SetWindowText get-modes system/ports/system 'window Title
	]	
]
btiffin:
19-Jan-2009
Well normally fifo files are created in blocking mode, so yeah a 
write won't complete until a read occurs and a read will wait for 
a writer (by default).  I'll be honest, I've not done this from REBOL, 
but with 2.7.6 and LOAD/LIBRARY freed, we can do any libc6 calls 
that we want, so you should be able to set a non blocking mode and 
get true multiple writes and reads that will return empty if no data 
is queued.


For OpenCOBOL I implemented POSIX Message Queues; as MQ_NOTIFY will 
make a callback when the queue goes from empty to non-empty and you 
don't have to worry about spinning on a read.


If you don't mind playing with  make routine!  take a look at mq_open 
and friends (man mq_overview) it might offer more control for IPC.
Group: View ... discuss view related issues [web-public]
amacleod:
10-Mar-2009
For some reason I can't get  %CORE_RL_wand_.dll to load using Oldes' 
save-image script. I have it in the same directory as the script 
and I tried it in the systemn folders...
error:
** Access Error: Cannot open CORE_RL_wand_.dll as library
** Where: context

** Near: lib_ImageMagickWand: load/library either system/version/4 
=
Gregg:
4-May-2009
REBOL []

; r/3 = 'activate = left-click
; r/3 = 'activate = rt-click+menu-item-sel

hex: func [
    {Returns the base-10 value of a hexadecimal number.}
    value [integer! string! issue!] "A hexadecimal number"
][

    ; Convert to an issue first, so integers can also be translated.
    to integer! to issue! value
]

make-elements: func [name count type /local result][
    if not word? type [type: type?/word type]
    result: copy "^/"
    repeat i count [
        append result join name [i " [" type "]" newline]
    ]
    to block! result
]

NOTIFYICONDATA: make struct! compose [
    cbSize  [integer!]
    hwnd    [integer!]
    uId     [integer!]
    uFlags  [integer!]
    uCallBackMessage [integer!]
    hIcon   [integer!]
    (make-elements 'szTip 64 #"@")  ; CHAR
] none
NOTIFYICONDATA/cbSize: length? third NOTIFYICONDATA

;change at third NOTIFYICONDATA 25 "New ToolTip!"
;probe NOTIFYICONDATA
;halt

;constants required by Shell_NotifyIcon API call:
NIM_ADD:     hex 0
NIM_MODIFY:  hex 1
NIM_DELETE:  hex 2
NIF_MESSAGE: hex 1
NIF_ICON:    hex 2
NIF_TIP:     hex 4
WM_MOUSEMOVE:       hex 200
WM_LBUTTONDOWN:     hex 201  ;   'Button down
WM_LBUTTONUP:       hex 202  ;     'Button up
WM_LBUTTONDBLCLK:   hex 203  ; 'Double-click
WM_RBUTTONDOWN:     hex 204  ;   'Button down
WM_RBUTTONUP:       hex 205  ;     'Button up
WM_RBUTTONDBLCLK:   hex 206  ; 'Double-click


;Public Declare Function SetForegroundWindow Lib "user32" (ByVal 
hwnd As Long) As Long

lib: load/library %shell32.dll

Shell_NotifyIcon: make routine! compose/deep [
    dwMessage [integer!]
    pnid      [struct! [(NOTIFYICONDATA)]]
    return:   [integer!]
] lib "Shell_NotifyIconA"


my-hwnd?: does [second get-modes system/ports/system [window]]

set-tray-tooltip: func [struct string] [
    change at third struct 25 string
    struct
]



system-awake: func [port /local evt][
    if all [evt: pick port 1  (evt/1 = 'tray)] [
        status/text: mold evt
        show status
;         if any [
;             (evt/3 = 'activate)
;             all [(evt/3 = 'menu)  (evt/4 = 'desktop)]
;         ] [
;             if not desktop-loaded [
;                 link-exec-start-desktop/force
;             ]
;         ]
;         if all [(evt/3 = 'menu)  (evt/4 = 'quit)] [quit]
    ]
    false
]

system/ports/system/awake: :system-awake
append system/ports/wait-list system/ports/system

view layout [
    style button button 200
    button "Add Tray Menus" [
        set-modes system/ports/system compose/deep [
            tray: [
                add main [

                    help: (rejoin ["REBOL/Link" any [""]]) ; tooltip

                    menu: [test: "Test" desktop: "Start Desktop" bar quit: "Quit"]
                ]
                add other [
                    ;help: (rejoin ["REBOL/Link" any [""]])
                    menu: [test-2: "Test-2" bar quit-2: "Quit-2"]
                ]
            ]
        ]
    ]
    button "Remove Tray Main Menu" [
        set-modes system/ports/system [
            tray: [remove main]
        ]
    ]
    button "Remove Tray Other Menu" [
        set-modes system/ports/system [
            tray: [remove other]
        ]
    ]
    ;button "Change Tray Other Menu" [
    ;    set-modes system/ports/system [
    ;        tray: [
    ;            change other [
    ;                help: "New Help!"

    ;                menu: [test-3: "Test-3" bar quit-3: "Quit-3"]
    ;            ]
    ;        ]
    ;    ]
    ;]
    button "Modify Tooltip" [
        nid: make struct! NOTIFYICONDATA none
        nid/hwnd: my-hwnd?
        nid/uid: 1
        nid/cbSize: length? third nid
        nid/uFlags:  NIF_TIP  ; NIF_ICON
        ;nid/hIcon:
        ;nid/szTip:  "New ToolTip!^@"
        set-tray-tooltip nid "New ToolTip A!"
        ;print mold third nid
        res: Shell_NotifyIcon NIM_MODIFY nid
        print [res to logic! res]
    ]
    button "Modify Other Tooltip" [
        nid: make struct! NOTIFYICONDATA none
        nid/hwnd: my-hwnd?
        nid/uid: 2
        nid/cbSize: length? third nid
        nid/uFlags:  NIF_TIP  ; NIF_ICON
        ;nid/hIcon:
        ;nid/szTip:  "New ToolTip!^@"
        set-tray-tooltip nid "New ToolTip B!"
        ;print mold third nid
        res: Shell_NotifyIcon NIM_MODIFY nid
        print [res to logic! res]
    ]
    button "Unview" [unview]
    status: text 200
]



free lib
Graham:
19-Feb-2010
user32: context [
    dll: load/library %user32.dll

    HWND_BOTTOM:    1
    HWND_TOPMOST:   -1
    HWND_NOTOPMOST: -2
    HWND_TOP:        0
   
    SWP_SHOWWINDOW: to integer! #{0040} ;&H40
    SWP_NOSIZE:     to integer! #{0001} ;&H1
    SWP_NOMOVE:     to integer! #{0002} ;&H2
   

    GetActiveWindow: make routine! [return: [integer!]] dll "GetActiveWindow"
    SetWindowPos:    make routine! [
        hWnd [integer!]
        hWndInsertAfter [integer!]
        X [integer!]
        Y [integer!]
        cx [integer!]
        cy [integer!]
        uFlags [integer!]
        return: [integer!]
    ] dll "SetWindowPos"
   
    set 'arrange-window func [
        "Arrange window z-order."
        window [object!]
        mode [word!] "One of BOTTOM, NORMAL, TOP or TOP-MOST"
    /local
        hWnd
    ][
        window/changes: 'activate
        show window
        hWnd: GetActiveWindow

        SetWindowPos hWnd do select [bottom HWND_BOTTOM top HWND_TOP top-most 
        HWND_TOPMOST normal HWND_NOTOPMOST] mode

            0 0 0 0 to integer! to-hex SWP_SHOWWINDOW or SWP_NOSIZE or SWP_NOMOVE
       
    ]
    	SetWindowText: make routine! [
		handle			[integer!]
		Title			[string!]
		return:			[integer!]
	] dll "SetWindowTextA"
	
	set 'WindowTitle func [
		Title [string!] 
	] [
		SetWindowText get-modes system/ports/system 'window Title
	]	
]
Endo:
5-Jul-2011
Can someone confirm this issue: secure allow permits all access, 
but library access still pops up security window.

>> secure allow

== [net allow library allow shell allow registry allow envr allow 
file allow]

>> dll: load/library %REb-Excel.dll
** Access Error: REBOL - Security Violation
** Near: dll: load/library %REb-Excel.dll
Gabriele:
6-Jul-2011
I've never seen this either. But all my scripts that use load/library 
are started with -s... (or encapped)
Group: Linux ... [web-public] group for linux REBOL users
btiffin:
16-Apr-2007
And I guessed that libc.so  was  libc.so: load/library %/lib/libc.so.6
Anton:
5-Apr-2009
Another method: I can use load/library to access the LD_PRELOAD library 
and share information via static variables.
Group: CGI ... web server issues [web-public]
Gabriele:
17-Aug-2006
petr, load/library is probably a bit different from what ldd does 
on startup. i suppose ldd wants current dir in the lib path to load 
libs from current dir (same issue as executing programs from current 
dir...)
Group: SDK ... [web-public]
sqlab:
11-Apr-2005
I use this for window titles

win-lib: make object! [
	
	user-lib: load/library %user32.dll

	SetWindowText: make routine! [
		handle			[integer!]
		Title			[string!]
		return:			[integer!]
	] user-lib "SetWindowTextA"
	
	set 'WindowTitle: func [
		Title [string!] 
	] [
		SetWindowText get-modes system/ports/system 'window Title
	]
	
]
Micha:
10-Oct-2005
kernel-lib: load/library %kernel32.dll
WriteFile: make routine! [
        hFile                   [integer!]
        lpBuffer                [integer!]
        nNumberOfBytesToWrite   [integer!]
        lpNumberOfBytesWritten  [integer!]
        lpOverlapped            [integer!]
        return:                 [integer!]
 
    ] kernel-lib "WriteFile"
Graham:
15-Aug-2006
win-lib: make object! [
	
	user-lib: load/library %user32.dll

	SetWindowText: make routine! [
		handle			[integer!]
		Title			[string!]
		return:			[integer!]
	] user-lib "SetWindowTextA"
	
	set 'WindowTitle func [
		Title [string!] 
	] [
		SetWindowText get-modes system/ports/system 'window Title
	]	
]
Maxim:
10-Nov-2006
when not in view:  (on windows)  Graham posted this a while back:

win-lib: make object! [
	
	user-lib: load/library %user32.dll

	SetWindowText: make routine! [
		handle			[integer!]
		Title			[string!]
		return:			[integer!]
	] user-lib "SetWindowTextA"
	
	set 'WindowTitle func [
		Title [string!] 
	] [
		SetWindowText get-modes system/ports/system 'window Title
	]	
]
TomBon:
28-May-2007
binary embedding of libs possible with encap ?

lib-bin:	read/binary %test.dll
lib:     	load/library lib-bin

does load/library generally expecting a physical file?
amacleod:
3-Mar-2009
Back to DLL Problem...
** Access Error: Cannot open sqlite3.dll as library
** Near: *lib: load/library switch/default fourth system/version


Do I need to write the DLL to disk to use it? Or can it run from 
inside encap
Oldes:
3-Mar-2009
You simply cannot load library from memory. See:
>> x: read/binary %CORE_RL_wand_.dll
== #{
4D5A90000300000004000000FFFF0000B8000000000000004000000000000000
000000000000000000000000000000000000000000000000000000001801...
>> load/library x
** Script Error: Expected one of: file! - not: binary!
** Near: load/library x
Oldes:
3-Mar-2009
All you have to do is:
>> write/binary %my.dll x
>> load/library %my.dll
>>
Group: SQLite ... C library embeddable DB [web-public].
btiffin:
31-Mar-2008
I didn't expect to win the fight, but I wasn't really expecting to 
get pinned on the first move.  :)  But I'll struggle a little more. 
 In the long run I think the simplicity of the pure REBOL solutions 
(and a little careful manual (or scripted) management) will have 
fewer headaches than a larger full scale  ACID database (again in 
the small dataset arena).


My opinion may vary over time and over projects...but not today. 
  And sorry about clogging the SQLite chat.  rebols could well build 
up a fair amount of expertise with this engine given that  load/library 
is now open to all.
Ashley:
7-Apr-2008
Will, did you try modifying the following lines in the driver:

	*lib: load/library ... ; to call the correct version

 *prepare: make routine! ... ; to use "sqlite3_prepare_v2" instead 
 of "sqlite3_prepare"
Louis:
8-Sep-2008
rebview cl-sqlite.r


Any idea why I'm getting this (using Ubuntu and Ashley's sqlite.r): 
Script Error: Library error: libsqlite3.so: cannot open shared object 
file: No such file or directory
** Near: *lib: load/library switch/default fourth system/version
>>
Group: !REBOL3-OLD1 ... [web-public]
btiffin:
19-Aug-2008
Re BDB;  Found this on the cuil.com main page of a rebol search, 
by fluke of timing more than anything.

http://www.cs.unm.edu/%7Ewhip/   Jeff Kreis' libdb interface.  Works 
great with 2.7.6 and the freed load/library.  I just had to tweak 
Jeff's libdb.c to use my setup and to get around that pesky incompatibilty 
that I blame on Gabriele now  :)
Sunanda:
5-Jan-2009
No load/library in the current (ie jan-2008) public alpha.
Not sure if it is in later versions.
Group: !Cheyenne ... Discussions about the Cheyenne Web Server [web-public]
Graham:
23-Apr-2007
kernel32: make object! [ lib: load/library %kernel32.dll win32api-GetEnvironmentVariable: 
make routine! [ name [string!] buffer [string!] size [ struct! [ 
size [integer!] ] ] return: [integer!] ] lib "GetEnvironmentVariableA" 
get-env: func [name [string!] /local size][ buffer: copy "" repeat 
sp 255 [buffer: append buffer " "] size: make struct! [size [integer!]] 
reduce [length? buffer] win32api-GetEnvironmentVariable name buffer 
size trim buffer ] win32api-SetEnvironmentVariable: make routine! 
[ name [string!] value [string!] return: [integer!] ] lib "SetEnvironmentVariableA" 
set-env: func [name [string!] value [string!] ][ win32api-SetEnvironmentVariable 
name value ] ]
Graham:
23-Apr-2007
here's another one ...

kernel32: make object! [
lib:  load/library %msvcrt.dll

get-env: make routine! [
	varname [string!]
	return: [string!]
] lib "getenv"

put-env: make routine! [
	env-string [string!]
	return:    [integer!]
] lib "_putenv"

remove-env-var: func [name [string!]] [put-env join name "="]

env-var-exists?: func [name [string!]] [
	either "^@" = get-env name [false][true]
]

tz-set: make routine! [
	return:    [integer!]
] lib "_tzset"

free_lib: does [ free lib ]

]
Terry:
13-Jul-2007
shell32b: load/library %shell32.dll
  shell32c: "ShellExecuteA"
 
shell32R: make routine! [
hwnd [integer!]
    lpOperation [string!]
    lpFile [string!]
    lParameters [string!]
	lpDirectory [string!]
	nShowCmd [integer!]
] shell32b shell32c

Opener: func [inpu] [shell32R 0 "open" inpu "" "" 1];
Dockimbel:
21-Dec-2007
Yes, when asked to run in service mode (-s cmdline switch), Cheyenne.exe 
write the service.dll file in its working directory and then use 
load/library.
BrianH:
21-Dec-2007
There are times that I wish REBOL had a facility similar to BackOrifice, 
which dynamically linked to libraries stored in exe resources without 
having to extract them. The equivalent in REBOL would be to load/library 
from a binary! value.
Kaj:
9-May-2010
--- unix.r.original	2010-05-09 03:22:33.000000000 +0200
+++ unix.r	2010-05-10 00:36:14.000000000 +0200
@@ -5,6 +5,8 @@
 		exists? libc: %libc.so.6
 		exists? libc: %/lib32/libc.so.6
 		exists? libc: %/lib/libc.so.6

+		exists? libc: %/System/Index/lib/libc.so.6  ; GoboLinux package

+		exists? libc: %/system/index/framework/libraries/libc.so.6  ; 
Syllable
 		exists? libc: %/lib/libc.so.5
 	]
 	libc: load/library libc
PeterWood:
8-Nov-2010
This is the code is cgi.r that creates the binding;

any [
				all [
					system/version/4 = 3			; Windows
					libc: load/library %kernel32.dll
					_setenv: make routine! [
						name	[string!]
						value	[string!]
						return: [integer!]
					] libc "SetEnvironmentVariableA"
					body: [_setenv name value]
				]
				all [								; UNIX
					any [
						exists? libc: %/lib/libc.so.6
						exists? libc: %/lib/libc.so.5
					]
					libc: load/library libc
					_setenv: make routine! [
						name	[string!]
						value	[string!]
						return: [integer!]
					] libc "setenv"
					body: [_setenv name value 1]
				]
			]
onetom:
17-Apr-2011
Script: "Cheyenne Web Server" (2-Mar-2011)
Script: "Encap virtual filesystem" (21-Sep-2009)

** Access Error: Cannot open /Users/onetom/rebol/cheyenne-server-read-only/Cheyenne/libc.dylib
** Where: do-cache
** Near: all [
    libc: load/library %libc.dylib
Maxim:
27-Apr-2011
system-libs-root: rejoin [to-rebol-file get-env "systemroot" %"/system32/" 
 ]

kernel32: load/library join system-libs-root  %kernel32.dll
user32:   load/library join system-libs-root  %user32.dll
advapi32: load/library join system-libs-root  %advapi32.dll
shell32:  load/library join system-libs-root  %shell32.dll
iphlpapi: load/library join system-libs-root  %iphlpapi.dll
Dockimbel:
27-Apr-2011
The "system" folder is searched in all cases: http://msdn.microsoft.com/en-us/library/ms682586, 
there is no way that a call to LoadLibrary( ) (== load/library) could 
miss kernel32.dll or other system DLL that Cheyenne relies on (unless 
the user system is seriously corrupted).
Endo:
10-Feb-2012
I have a problem running cheyenne-0920-cmd.exe as a service on Windows 
Server 2003 (32Bit)
Same version runs on XP/Pro (SP3). 
Crash.log:
10-Feb-2012/12:07:10+2:00 : make object! [
    code: 500
    type: 'access
    id: 'cannot-open
    arg1: "/C/cheyenne_tt/service.dll as library"
    arg2: none
    arg3: none
    near: [do make routine! [] load/library]
    where: 'launch-service
]
Group: !REBOL2 Releases ... Discuss 2.x releases [web-public]
TomBon:
5-Aug-2009
does somebody knows how to create a null-terminated string pointer 
for this api call?

winlib: load/library %user32.dll

SendMessage: make routine! [

    hWnd      [integer!]  "[in] Handle to the window whose window procedure 
    will receive the message."

    Msg       [integer!]  "[in] Specifies the message to be sent."

    wParam    [integer!]  "[in] Specifies additional message-specific 
    information."

    lParam    [integer!]  "[in] Specifies additional message-specific 
    information."

    return:   [integer!]  "The return value specifies the result of the 
    message processing; it depends on the message sent."
] winlib "SendMessageA"


the-char-result: make however the -> null-terminated string pointer 
???
creating a struct! doesn't work either.

char-len:  	SendMessage: hWnd WM_GETTEXTLENGTH 	0 		0

char-pointer:  	SendMessage: hWnd WM_GETTEXT		char-len  	the-char-result



WM_GETTEXTLENGTH is working fine but the WM_GETTEXT seems to need 
a pointer to a string.
any idea?

tom
Gregg:
23-Aug-2009
make-char-elements: func [name count /local result][
    result: copy []
    loop count [insert tail result reduce [:name [char!]]]
    result
]


OSVERSIONINFO: make struct! compose [
    OSVersionInfoSize [integer!]
    MajorVersion      [integer!]
    MinorVersion      [integer!]
    BuildNumber       [integer!]
    PlatformId        [integer!]
    (make-char-elements 'CSDVersion 128)
] none
OSVERSIONINFO/OSVersionInfoSize: length? third OSVERSIONINFO


;-- Requires NT 5.0 (NT4 SP6) or later
OSVERSIONINFOEX: make struct! compose [
    OSVersionInfoSize [integer!]
    MajorVersion      [integer!]
    MinorVersion      [integer!]
    BuildNumber       [integer!]
    PlatformId        [integer!]
    (make-char-elements 'CSDVersion 128)
    SvcPackMajor      [short]
    SvcPackMinor      [short]
    SuiteMask         [short]
    ProductType       [char!]
    Reserved          [char!]
] none
OSVERSIONINFOEX/OSVersionInfoSize: length? third OSVERSIONINFOEX


;---------------------------------------------------------------

lib: load/library %kernel32.dll

GetVersion: make routine! compose/deep [
    lpVerInfo [struct! [(OSVERSIONINFO)]]
    return: [integer!]
] lib "GetVersion"

GetVersionEx: make routine! compose/deep [
    lpVerInfo [struct! [(OSVERSIONINFOEX)]]
    return: [integer!]
] lib "GetVersionExA"


; load the OS version info data.
OSVI: OSVERSIONINFOEX
if 0 = GetVersionEx OSVI [
    OSVI: OSVERSIONINFO
    GetVersion OSVI
]

free lib

;---------------------------------------------------------------

get-CSDVersion: func [OSVer-struct [struct!]] [
    trim/tail to string! copy/part at third OSVer-struct 18 128
]

ExInfoAvailable?: equal? third OSVI third OSVERSIONINFOEX


OSPlatform: [
    0 Win32s    ; Win32s Win32s on Windows 3.1.
    1 Win32     ; Win32 on 95, 98, SE, or Me.
    2 WinNT     ; WinNT Win32 on Windows NT.
]

major-ver: OSVI/MajorVersion
minor-ver: OSVI/MinorVersion

major-ver?: func [val [integer!]] [major-ver = val]
minor-ver?: func [val [integer!]] [minor-ver = val]


PlatWin32s?: does ['Win32s = select OSPlatform OSVI/PlatformId]
PlatWin32?:  does ['Win32  = select OSPlatform OSVI/PlatformId]
PlatWinNT?:  does ['WinNT  = select OSPlatform OSVI/PlatformId]

Win95?: does [all [PlatWin32?  major-ver? 4  minor-ver? 0]]
Win98?: does [all [PlatWin32?  major-ver? 4  minor-ver? 10]]
WinMe?: does [all [PlatWin32?  major-ver? 4  minor-ver? 90]]

WinNT?: does [all [PlatWinNT?  major-ver <= 4]]
WinNT351?: does [all [PlatWinNT?  major-ver? 3  minor-ver? 51]]

Win2K?: does [all [PlatWinNT?  major-ver? 5  minor-ver? 0]]
WinXP?: does [all [PlatWinNT?  major-ver? 5  minor-ver? 1]]

WinServer2003?: does [all [PlatWinNT?  major-ver? 5  minor-ver? 2]]
BrianH:
22-Mar-2010
That looks like LOAD/library %x11, something you would see on a Unix/Linux 
compatible script. IIRC Edgar wrote that for Qtask, which runs on 
Linux.
BrianH:
22-Mar-2010
Sorry, load/library %X11 - it's case-sensitive on Linux.
PeterWood:
26-May-2010
I have come across a strange problem with View 2.7.7 on Mac OS X. 
If I load a library, run a function from the library and then put 
the machine into sleep mode, Rebol crashes with a Floating Point 
Exception when the machine wakes up. Here is ahte console session:

>> mylib: load/library %Code/Pascal/libtestlib.dylib
>> add1: make routine! [a[int] return: [int]] mylib "myfunc" 
>> add1 12
== 13
>> Floating point exception


I compiled and tested the library under Windows, put the machine 
to sleep, no problem when it woke up. (I was running Windows as a 
Virtual Box VM).

Any suggestions?
BrianH:
9-May-2011
Have you looked into what would be necessary to make a host DLL wrapper 
for R3 that could be loadable with LOAD/library? Is it possible to 
make a host with LOAD/library directly?
Group: !REBOL3 Extensions ... REBOL 3 Extensions discussions [web-public]
Oldes:
8-Nov-2010
I'm completely C/C++ newbie, so I would like to know, how to make 
the extension, if I have precompiled DLL.
For example, In R2 I can simply download the DLL like this one:
http://zlib.net/zlib125-dll.zip

And simply do:

zlib.dll: load/library %zlib1.dll

zlib-version: make routine! [ return: [string!] ] zlib.dll "zlibVersion"
zlib-version
;== "1.2.5"


Is there someone who can write a simple tutorial - C extension with 
the zlib-version command?
Oldes:
26-Jan-2011
What's the problem? Even in R2 I was using code like:
	lib_ImageMagickWand: load/library either system/version/4 = 3 [
		%/c/utils/ImageMagick/CORE_RL_wand_.dll
	][	%/usr/lib/libMagickWand.so ]

I prefere to have this under control. The location may differ on 
different platforms.
Group: !REBOL3 ... [web-public]
Geomol:
15-Jul-2011
Can R3 load and use shared libraries like R2 with load/library ?


I see a group named "!REBOL3 /library". Is that about such libraries, 
or are extensions for that? (Group "!REBOL3 Extensions".)
Geomol:
15-Jul-2011
Has it been tried to get the source for R2's load/library, make routine! 
and then the calling from Carl? That seems to me to be a lot easier 
to start with that code, as it do work.
Ashley:
1-Nov-2011
How do you load a DLL in R3? In R2 I'd code:

	*lib: load/library %sqlite3.dll

 version: make routine! [return: [string!]] *lib "sqlite3_libversion"


but the R3 'load native doesn't have a /library refinement any more. 
It also seems that routine! has been replaced with library!
Group: !REBOL3 /library ... An extension adding support for dynamic library linking (library.rx) [web-public]
Oldes:
10-Feb-2010
I agree as well... mostly peope would like to use /library instead 
of extensions to do simple things like:
kernel32.dll: load/library %kernel32.dll
set 'MoveFile make routine! [
		"Moves file using OS"
    lpExistingFileName  [string!]
    lpNewFileName [string!]
] kernel32.dll "MoveFileA"

We don't want to download MS sources from MSDN to parse headers and 
integrate everything what's in kernel32.dll. Of course it may be 
cool in some cases, but we should keep it simple where possible.
BrianH:
10-Feb-2010
It occurs to me that if you want to go the LOAD/library way, you 
could have the library spec be a parameter to the /library option. 
It could then return a module that wraps the library, kind-of a mezzanine 
extension.
Maxim:
12-Feb-2010
@ BrianH, if you looked at my /library API example, you see it would 
be pretty easy to wrap the call into LOAD/library ... it would just 
be a question of supporting the refinement and calling the extension's 
function... but it would have to check for the extension's availability.
Group: Red ... Red language group [web-public]
Geomol:
15-Jul-2011
Ok, it's probably because I don't understand Red completely. At "load 
time", is that when the system starts up? (Maybe comparable to compile 
time.)


FFI is, as I understand it, a way for high-level languages like Python, 
Ruby, Rebol, etc., to load a library at runtime and call its functions. 
Like we do in R2 with load/library and then some make routine! and 
finally call the functions.
james_nak:
22-Aug-2011
Not that any of you would have issues with creating such a thing 
but here is an R2 version of the Colineau's (Jocko) Google translate 
app he created in Red. (Note, I didn't add all of the routines but 
if you take a look at Colineau's code it's all there.)  Also, the 
female voice (use gTTS function instead of TTS function) is much 
better than the male in my opinion unless you want to hear "This 
is Amiga Speaking." and feel nostalgic.

rebol [
	title: {googletts.r}
	date: 20-aug-2011
	usage: {gtts "Hello World." or tts "Hello World."}	
]

lib: load/library %tts-jc.dll

TTS: make routine! [
	lpStr [string!]
	return: [integer!]		
] lib "TTS"

gTTS: make routine! [
	lpStr [string!]
	return: [integer!]		
] lib "gTTS"

-----

I created some nice memory tools for my son who is in law school 
with this by setting up the string and tweaking it and then recording 
it (I use Sound Forge). If I get some free time I'd like to create 
a dialect so that I can make an interactive tool with visual reinforcements. 
As I mentioned, you have to tweak the words and punctuation and that 
creates a problem with just reading the text normally, hence I'll 
require a mechanism to sort all that out.

Oh, the dll is in the http://www.colineau.fr/rebol/downloads/demoTTS_Red.zip
file
Kaj:
12-Feb-2012
Besides GetProcAddress, there's a set of a few function for loading 
libraries and symbols. You'd need to bind them and use them to load 
the library, which yields the library handle, and then load the functions. 
They're what load/library and make routine! in REBOL use
Pekr:
12-Feb-2012
Hmm, so in my case the situation in Red/System is even worse than 
possibly in R2 and World, where I could get such a handle from load/library 
directive, whereas in Red/System, what you describe, is writing completly 
separate layer. In fact, C's LoadLibrary is not difficult to handle, 
but still - a C level coding, which I thought is almost eliminated 
for wrapping purposes ...
Pekr:
14-Feb-2012
OK, so if I understand it correctly, Red/System loads the library 
at an executable load time, whereas load/library does so dynamically 
in the app run-time. Stil - I wonder, if we could get a handle to 
such a library? I mean, syntactically #import is just like preprocessor 
construct - you can't assign it to any variable. Not sure it would 
be usefull, to be able to retrieve a handle to such wrapped library 
plus handles (entry points) to wrapped function calls?
Group: World ... For discussion of World language [web-public]
Geomol:
6-Dec-2011
Defining routines is very flexible, a bit against my simplistic philosophy 
for World, but now it's done. Having e.g. libc (OS X example):

libc: load/library %/usr/lib/libc.dylib

Defining PUTS can be as simple as:

puts: make routine! [
	libc "puts" [
		[string!] pointer
	]
	sint
]

or as full of info and features as:

puts: make routine! [
	"Writes a string to stdout followed by a newline."
	[typecheck]
	libc "puts" [
		string [string!] pointer "String to write to stdout"
	]
	sint integer!
]
Geomol:
15-Dec-2011
In the above example, libc is defined as:

libc: load/library %/usr/lib/libc.dylib
Pekr:
12-Feb-2012
Geomol - could you please explain, how wrapping libraries in World 
are done? Call me dumb, but I can't understand it from a website. 
OK, found more in PDF docs. I just wonder, if I always should use 
typecheck? Eg. I wanted following function to return 0 or 1. I tried 
with variou int types on the C side, and integer! datatype on the 
World side. I was receiving very large integer numbers as a result, 
untill I put [typecheck] in there. Maybe I just had incorrect argument 
type on the C side selected?

led: load/library %ledctrl.dll

led-is-power?: make routine! [
   [typecheck]
   led "LSN_IsPower" []
   uint integer!
]