1. Handy Win32 function..
- Posted by Greg Harris <blackdog at CDC.NET>
Mar 21, 1999
-
Last edited Mar 22, 1999
------=_NextPart_000_0017_01BE73EC.F3B11F20
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Hi,
As to all the talk about dlls and the difficulty in Euphoria I wrote =
this include file a couple of days ago. I automatically tracks what =
.dlls have been opened (opens them if they have not been) and uses the =
handles over and over.. Hope somebody finds use for this.
This is really usefull if you need to avoid naming conflicts in multiple =
includes..=20
just for examples:
include ezdll.ew
then to link a C procedure:
atom xShowWindow
xShowWindow =3D DllProc("user32.dll", "ShowWindow", {C_POINTER, =
C_INT})
or to link a C function:
atom xGetStockObject
xGetStockObject =3D DllFunc("gdi32.dll", "GetStockObject", {C_INT}, =
C_POINTER)
Or course use this at OWN RISK.There may be bugs. (I really hate =
legalities in programming)
--EZDll.ew
--Simplify declaring of .DLLs in Euphoria
--Greg Harris 1999
include dll.e
include msgbox.e
include wildcard.e
sequence dll_name_list
sequence dll_handle_list
integer ok
dll_name_list =3D {}
dll_handle_list =3D {}
function getDLLname(sequence name)
return find(name, dll_name_list)
end function
function getDLLhandle(integer index)
return dll_handle_list[index]
end function
global function DllProc(sequence dll,sequence name, sequence args)
integer x
atom hndle, proc
dll =3D lower(dll)
x =3D getDLLname(dll)
if x then
hndle=3DgetDLLhandle(x)
else
hndle =3D open_dll(dll)
if hndle =3D NULL then
-- give error and abort
ok =3D message_box( "Couldn't open .DLL: " & dll,
"Fatal Error", MB_ICONHAND+MB_TASKMODAL )
-- abort
abort(1)
else
dll_name_list =3D append(dll_name_list, dll)
dll_handle_list =3D append(dll_handle_list, hndle)
end if
end if
proc =3D define_c_proc(hndle, name, args)
if proc =3D -1 then
ok =3D message_box( "Couldn't find/open Windows procedure: " & =
name & "\r\n"
&"in .DLL: " & dll,
"Fatal Error", MB_ICONHAND+MB_TASKMODAL )
-- abort
abort(1)
end if
return proc
end function
global function DllFunc(sequence dll,sequence name, sequence args, atom =
result)
integer x
atom hndle, func
dll =3D lower(dll)
x =3D getDLLname(dll)
if x then
hndle=3DgetDLLhandle(x)
else
hndle =3D open_dll(dll)
if hndle =3D NULL then
-- give error and abort
ok =3D message_box( "Couldn't open .DLL: " & dll ,
"Fatal Error", MB_ICONHAND+MB_TASKMODAL )
-- abort
abort(1)
else
dll_name_list =3D append(dll_name_list, dll)
dll_handle_list =3D append(dll_handle_list, hndle)
end if
end if
func =3D define_c_func(hndle, name, args, result)
if func =3D -1 then
ok =3D message_box( "Couldn't find/open Windows function: " & =
name & " \r\n"
&"in .DLL: " & dll,
"Fatal Error", MB_ICONHAND+MB_TASKMODAL )
-- abort
abort(1)
end if
return func
end function
Regards,
Greg Harris
------=_NextPart_000_0017_01BE73EC.F3B11F20
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD W3 HTML//EN">
<HTML>
<HEAD>
<META content=3Dtext/html;charset=3Diso-8859-1 =
http-equiv=3DContent-Type>
<META content=3D'"MSHTML 4.72.3110.7"' name=3DGENERATOR>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT size=3D2>Hi,</FONT></DIV>
<DIV><FONT size=3D2></FONT> </DIV>
<DIV><FONT size=3D2>As to all the talk about dlls and the difficulty in =
Euphoria I=20
wrote this include file a couple of days ago. I automatically tracks =
what .dlls=20
have been opened (opens them if they have not been) and uses the handles =
over=20
and over.. Hope somebody finds use for this.</FONT></DIV>
<DIV><FONT size=3D2></FONT><FONT color=3D#000000 size=3D2>This is really =
usefull if=20
you need to avoid naming conflicts in multiple includes.. </FONT></DIV>
<DIV> </DIV>
<DIV><FONT size=3D2>just for examples:</FONT></DIV>
<DIV><FONT size=3D2></FONT> </DIV>
<DIV><FONT size=3D2>include ezdll.ew</FONT></DIV>
<DIV><FONT size=3D2></FONT> </DIV>
<DIV><FONT size=3D2>then to link a C procedure:</FONT></DIV>
<DIV><FONT size=3D2></FONT> </DIV>
<DIV><FONT size=3D2>atom xShowWindow</FONT></DIV>
<DIV><FONT size=3D2>xShowWindow =3D =20
DllProc("user32.dll", "ShowWindow", {C_POINTER,=20
C_INT})</FONT></DIV>
<DIV><FONT size=3D2></FONT> </DIV>
<DIV><FONT size=3D2>or to link a C function:</FONT></DIV>
<DIV><FONT size=3D2></FONT> </DIV>
<DIV><FONT size=3D2></FONT><FONT color=3D#000000 size=3D2>atom <FONT =
size=3D2><FONT=20
color=3D#000000 size=3D2>xGetStockObject</FONT></FONT></FONT></DIV>
<DIV><FONT color=3D#000000 size=3D2>xGetStockObject =3D=20
DllFunc("gdi32.dll", "GetStockObject", {C_INT},=20
C_POINTER)</FONT></DIV>
<DIV><FONT size=3D2></FONT> </DIV>
<DIV><FONT size=3D2>Or course use this at OWN RISK.There may be bugs. (I =
really=20
hate legalities in programming)</FONT></DIV>
<DIV><FONT size=3D2></FONT> </DIV>
<DIV><FONT size=3D2>--EZDll.ew<BR>--Simplify declaring of .DLLs in=20
Euphoria<BR>--Greg Harris 1999</FONT></DIV>
<DIV><FONT size=3D2></FONT> </DIV>
<DIV><FONT size=3D2>include dll.e<BR>include msgbox.e<BR>include=20
wildcard.e</FONT></DIV>
<DIV><FONT size=3D2></FONT> </DIV>
<DIV><FONT size=3D2>sequence dll_name_list<BR>sequence=20
dll_handle_list</FONT></DIV>
<DIV><FONT size=3D2></FONT> </DIV>
<DIV><FONT size=3D2>integer ok</FONT></DIV>
<DIV><FONT size=3D2></FONT> </DIV>
<DIV><FONT size=3D2>dll_name_list =3D {}<BR>dll_handle_list =3D =
{}</FONT></DIV>
<DIV><FONT size=3D2></FONT> </DIV>
<DIV><FONT size=3D2>function getDLLname(sequence name)<BR> return =
find(name,=20
dll_name_list)<BR>end function</FONT></DIV>
<DIV><FONT size=3D2></FONT> </DIV>
<DIV><FONT size=3D2>function getDLLhandle(integer index)<BR> =
return=20
dll_handle_list[index]<BR>end function</FONT></DIV>
<DIV><FONT size=3D2></FONT> </DIV>
<DIV><FONT size=3D2>global function DllProc(sequence dll,sequence name, =
sequence=20
args)<BR> integer x<BR> atom hndle, proc<BR> dll =3D=20
lower(dll)<BR> x =3D getDLLname(dll)<BR> if x=20
hndle=3DgetDLLhandle(x)<BR> else<BR> hndle =3D=20
open_dll(dll)<BR> if hndle =3D NULL=20
then<BR> -- give error and=20
abort<BR> ok =3D message_box( "Couldn't open .DLL: " =
&=20
dll,<BR> "Fatal Error", MB_ICONHAND+MB_TASKMODAL=20
)<BR> --=20
abort(1)<BR> =
else<BR> =20
dll_name_list =3D append(dll_name_list,=20
dll)<BR> dll_handle_list =3D=20
append(dll_handle_list, hndle)<BR> end if<BR> =
end=20
if<BR> proc =3D define_c_proc(hndle, name, args)<BR> if proc =
=3D -1=20
then<BR> ok =3D message_box(=20
"Couldn't find/open Windows procedure: " & name &=20
"\r\n"<BR> &"in .DLL: " &=20
dll,<BR> "Fatal Error",=20
MB_ICONHAND+MB_TASKMODAL )<BR> =
--=20
abort<BR> abort(1)<BR> =
end=20
if<BR> return proc<BR>end function</FONT></DIV>
<DIV><FONT size=3D2></FONT> </DIV>
<DIV><FONT size=3D2>global function DllFunc(sequence dll,sequence name, =
sequence=20
args, atom result)<BR> integer x<BR> atom hndle, =
func<BR> dll=20
=3D lower(dll)<BR> x =3D getDLLname(dll)<BR> if x=20
hndle=3DgetDLLhandle(x)<BR> else<BR> hndle =3D=20
open_dll(dll)<BR> if hndle =3D NULL=20
then<BR> -- give error and=20
abort<BR> ok =3D message_box(=20
"Couldn't open .DLL: " & dll ,<BR> =
"Fatal Error", MB_ICONHAND+MB_TASKMODAL=20
)<BR> --=20
abort(1)<BR> =
else<BR> =20
dll_name_list =3D append(dll_name_list,=20
dll)<BR> dll_handle_list =3D=20
append(dll_handle_list, hndle)<BR> end if<BR> =
end=20
if<BR> func =3D define_c_func(hndle, name, args, result)<BR> =
if func =3D=20
-1 then<BR> ok =3D =
message_box(=20
"Couldn't find/open Windows function: " & name & =
"=20
\r\n"<BR> &"in .DLL: " &=20
dll,<BR> "Fatal Error",=20
MB_ICONHAND+MB_TASKMODAL )<BR> =
--=20
abort<BR> abort(1)<BR> =
end=20
if<BR> return func<BR>end function</FONT></DIV>
<DIV><FONT size=3D2></FONT> </DIV>
<DIV><FONT color=3D#000000 size=3D2>Regards,</FONT></DIV>
<DIV><FONT color=3D#000000 size=3D2></FONT> </DIV>
<DIV><FONT color=3D#000000 size=3D2>Greg =
------=_NextPart_000_0017_01BE73EC.F3B11F20--