Handy Win32 function..

new topic     » topic index » view thread      » older message » newer message

------=_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>&nbsp;</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>&nbsp;</DIV>
<DIV><FONT size=3D2>just for examples:</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>include ezdll.ew</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>then to link a C procedure:</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>atom xShowWindow</FONT></DIV>
<DIV><FONT size=3D2>xShowWindow&nbsp;&nbsp;&nbsp; =3D&nbsp;=20
DllProc(&quot;user32.dll&quot;, &quot;ShowWindow&quot;, {C_POINTER,=20
C_INT})</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>or to link a C function:</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</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&nbsp; =3D=20
DllFunc(&quot;gdi32.dll&quot;, &quot;GetStockObject&quot;, {C_INT},=20
C_POINTER)</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</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>&nbsp;</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>&nbsp;</DIV>
<DIV><FONT size=3D2>include dll.e<BR>include msgbox.e<BR>include=20
wildcard.e</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>sequence dll_name_list<BR>sequence=20
dll_handle_list</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>integer ok</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>dll_name_list =3D {}<BR>dll_handle_list =3D =
{}</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>function getDLLname(sequence name)<BR>&nbsp; return =
find(name,=20
dll_name_list)<BR>end function</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>function getDLLhandle(integer index)<BR>&nbsp; =
return=20
dll_handle_list[index]<BR>end function</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>global function DllProc(sequence dll,sequence name, =
sequence=20
args)<BR>&nbsp; integer x<BR>&nbsp; atom hndle, proc<BR>&nbsp; dll =3D=20
lower(dll)<BR>&nbsp; x =3D getDLLname(dll)<BR>&nbsp; if x=20
hndle=3DgetDLLhandle(x)<BR>&nbsp; else<BR>&nbsp;&nbsp;&nbsp; hndle =3D=20
open_dll(dll)<BR>&nbsp;&nbsp;&nbsp; if hndle =3D NULL=20
then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -- give error and=20
abort<BR>&nbsp; ok =3D message_box( &quot;Couldn't open .DLL: &quot; =
&amp;=20
dll,<BR>&nbsp;&nbsp; &quot;Fatal Error&quot;, MB_ICONHAND+MB_TASKMODAL=20
)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; --=20
abort(1)<BR>&nbsp;&nbsp;&nbsp; =
else<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
dll_name_list =3D append(dll_name_list,=20
dll)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dll_handle_list =3D=20
append(dll_handle_list, hndle)<BR>&nbsp;&nbsp;&nbsp; end if<BR>&nbsp; =
end=20
if<BR>&nbsp; proc =3D define_c_proc(hndle, name, args)<BR>&nbsp; if proc =
=3D -1=20
then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ok =3D message_box(=20
&quot;Couldn't find/open Windows procedure: &quot; &amp; name &amp;=20
&quot;\r\n&quot;<BR>&nbsp;&nbsp;&nbsp; &amp;&quot;in .DLL: &quot; &amp;=20
dll,<BR>&nbsp;&nbsp;&nbsp;&nbsp; &quot;Fatal Error&quot;,=20
MB_ICONHAND+MB_TASKMODAL )<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
--=20
abort<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; abort(1)<BR>&nbsp; =
end=20
if<BR>&nbsp; return proc<BR>end function</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>global function DllFunc(sequence dll,sequence name, =
sequence=20
args, atom result)<BR>&nbsp; integer x<BR>&nbsp; atom hndle, =
func<BR>&nbsp; dll=20
=3D lower(dll)<BR>&nbsp; x =3D getDLLname(dll)<BR>&nbsp; if x=20
hndle=3DgetDLLhandle(x)<BR>&nbsp; else<BR>&nbsp;&nbsp;&nbsp; hndle =3D=20
open_dll(dll)<BR>&nbsp;&nbsp;&nbsp; if hndle =3D NULL=20
then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -- give error and=20
abort<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ok =3D message_box(=20
&quot;Couldn't open .DLL: &quot; &amp; dll ,<BR>&nbsp;&nbsp;&nbsp;&nbsp; =

&quot;Fatal Error&quot;, MB_ICONHAND+MB_TASKMODAL=20
)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; --=20
abort(1)<BR>&nbsp;&nbsp;&nbsp; =
else<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
dll_name_list =3D append(dll_name_list,=20
dll)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dll_handle_list =3D=20
append(dll_handle_list, hndle)<BR>&nbsp;&nbsp;&nbsp; end if<BR>&nbsp; =
end=20
if<BR>&nbsp; func =3D define_c_func(hndle, name, args, result)<BR>&nbsp; =
if func =3D=20
-1 then<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ok =3D =
message_box(=20
&quot;Couldn't find/open Windows function: &quot; &amp; name &amp; =
&quot;=20
\r\n&quot;<BR>&nbsp;&nbsp;&nbsp; &amp;&quot;in .DLL: &quot; &amp;=20
dll,<BR>&nbsp;&nbsp;&nbsp;&nbsp; &quot;Fatal Error&quot;,=20
MB_ICONHAND+MB_TASKMODAL )<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
--=20
abort<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; abort(1)<BR>&nbsp; =
end=20
if<BR>&nbsp; return func<BR>end function</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT color=3D#000000 size=3D2>Regards,</FONT></DIV>
<DIV><FONT color=3D#000000 size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT color=3D#000000 size=3D2>Greg =

------=_NextPart_000_0017_01BE73EC.F3B11F20--

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu