1. Noob, learning how to use dll's.
- Posted by Archarios <archarios at veriz?n?net> Jun 12, 2008
- 809 views
hi i'm trying to get my program to adjust its self according to how much memory is available and cpu usage. so far i plan to use kernel32.dll's GlobalMemoryStatus/ex for memory calling, but i've never used any dlls. Could anyone give me a simple run down pref with an example using euphoria? and a dll for cpu callings? i've visited msdn but i don't speak winapi. i've learned so far that i have to open_dll the kernel and define_c_? plz help, thanks in advance!
2. Re: Noob, learning how to use dll's.
- Posted by Michael J. Sabal <m_sabal at yah?o.?om> Jun 12, 2008
- 795 views
- Last edited Jun 13, 2008
See http://msdn.microsoft.com/en-us/library/aa366589(VS.85).aspx for GlobalMemoryStatusEx. DLL = open_dll("kernel.dll") GMSx = define_c_func(DLL,"GlobalMemoryStatusEx",{C_POINTER},C_INT) mem = allocate(64) result = c_func(GMSx,{mem}) free(mem) I can't remember the exact size of DWORD and DWORDLONG, I think it's 4 and 8. You'll have to peek(mem+offset,num_bytes) to get the information you want, and multiply it out to convert it from a sequence of bytes to a number. Hope this helps, Mike
3. Re: Noob, learning how to use dll's.
- Posted by Mike777 <anon4321 at gmai?.?om> Jun 13, 2008
- 785 views
Since we are on the subject of NOOB's and dll's, I herewith post a link to a thread I started a few months ago about using a Euphoria DLL from within Excel: http://www.openeuphoria.org/cgi-bin/esearch.exu?thread=1&fromMonth=C&fromYear=C&toMonth=2&toYear=D&keywords=%22Excel%22 Is there anybody reading this at this time that can extend the discussion a bit? Just to clarify, I'm not trying to: 1) write to an Excel sheet from a Euphoria program 2) create something that mimics an ActiveX object that therefore needs a wrapper. I'm interested in creating a DLL that exposes a function which can be utilized within an Excel spreadsheet. For example, say my DLL has a function which is called specialaverage and it takes a series of potentially 10 numbers and calculates a "special average" (say, something like the highest 3 consecutive out of 5, using a floor approach whereby the next in the series can never be less than 20% beneath what its predecessor is). I want to put: =specialaverage(a1..a10) in the cell and have the result populated. I have looked at the notes on MSDN on creating a DLL for use with excel (referred to as an xll, I believe) but I'm not able to understand whether doing so in Euphoria is even possible. Thanks Mike
4. Re: Noob, learning how to use dll's.
- Posted by Matt Lewis <matthewwalkerlewis at ?ma?l.com> Jun 13, 2008
- 779 views
Mike777 wrote: > > I'm interested in creating a DLL that exposes a function which can be utilized > within an Excel spreadsheet. > > For example, say my DLL has a function which is called specialaverage and it > takes a series of potentially 10 numbers and calculates a "special average" > (say, something like the highest 3 consecutive out of 5, using a floor > approach whereby the next in the series can never be less than 20% beneath > what its predecessor is). I want to put: > > =specialaverage(a1..a10) > > in the cell and have the result populated. > > I have looked at the notes on MSDN on creating a DLL for use with excel > (referred to as an xll, I believe) but I'm not able to understand whether > doing so in Euphoria is even possible. Do you have a live link for these notes? Matt
5. Re: Noob, learning how to use dll's.
- Posted by Archarios <archarios at v?rizon?net> Jun 13, 2008
- 779 views
See http://msdn.microsoft.com/en-us/library/aa366589(VS.85).aspx for GlobalMemoryStatusEx. DLL = open_dll("kernel.dll") GMSx = define_c_func(DLL,"GlobalMemoryStatusEx",{C_POINTER},C_INT) mem = allocate(64) result = c_func(GMSx,{mem}) free(mem) I can't remember the exact size of DWORD and DWORDLONG, I think it's 4 and 8. You'll have to peek(mem+offset,num_bytes) to get the information you want, and multiply it out to convert it from a sequence of bytes to a number. Hope this helps, Mike Thanks for the help, exactally what I needed! DWORD is 8 bytes so a DWORDLONG is also 8 but unsigned...right and why do you ask? P.S. I copied and pasted your message cause the quote didn't come out well.
6. Re: Noob, learning how to use dll's.
- Posted by Archarios <archarios at v?rizon.net> Jun 13, 2008
- 797 views
Sorry, never mind, I finally found out why you asked about DWORD and DWORDLONG.
7. Re: Noob, learning how to use dll's.
- Posted by Archarios <archarios at verizon?net> Jun 13, 2008
- 795 views
without warning include file.e include dll.e include safe.e atom file1,DLL,GMSx,mem,result object temp file1 = open("D:\obscured\test.txt","w") DLL = open_dll("kernel.dll") GMSx = define_c_func(DLL,"GlobalMemoryStatusEx",{C_POINTER},C_INT) mem = allocate(64) result = c_func(GMSx,{mem}) ----faults here printf(file1,"%d",peek(mem+1)) free(mem) close(file1) abort(0)
I get: C:\EUPHORIA\include\safe.e:516 in function original_c_func() c_proc/c_func: bad routine number (-1) i = -1 s = {832176} ... called from C:\EUPHORIA\include\safe.e:522 in function c_func() i = -1 s = {832176} r = <no value> ... called from D:\obscured\test.exw:13 Do I have to use machine.e for this, I was using safe.e since I'm new to dll's.
8. Re: Noob, learning how to use dll's.
- Posted by Archarios <archarios at verizo?.n?t> Jun 13, 2008
- 822 views
sorry, had it calling kernel.dll, forgot 32
9. Re: Noob, learning how to use dll's.
- Posted by CChris <christian.cuvier at a?riculture.go?v.fr> Jun 13, 2008
- 771 views
Archarios wrote: > > }}} <eucode> > without warning > include file.e > include dll.e > include safe.e > > atom file1,DLL,GMSx,mem,result > object temp > file1 = open("D:\obscured\test.txt","w") > > DLL = open_dll("kernel.dll") > GMSx = define_c_func(DLL,"GlobalMemoryStatusEx",{C_POINTER},C_INT) > mem = allocate(64) > result = c_func(GMSx,{mem}) ----faults here > printf(file1,"%d",peek(mem+1)) > free(mem) > close(file1) > abort(0) > </eucode> {{{ > I get: > C:\EUPHORIA\include\safe.e:516 in function original_c_func() > c_proc/c_func: bad routine number (-1) > i = -1 > s = {832176} > > ... called from C:\EUPHORIA\include\safe.e:522 in function c_func() > i = -1 > s = {832176} > r = <no value> > > ... called from D:\obscured\test.exw:13 > > Do I have to use machine.e for this, I was using safe.e since I'm new to > dll's. Are you sure you need the Ex ? CChris
10. Re: Noob, learning how to use dll's.
- Posted by Archarios <archarios at verizon?ne?> Jun 13, 2008
- 801 views
Not really. I simply copied Mikes code to learn from. I read that GlobalMemoryStatus is known to give false results but thats what I seem to be getting with ex. Heres my hex dump: 12000000,68010000,730100001B000000,650100006C010000,6B01000073010000,6A0100009B000000,6A0100004D010000,7301000007000000,7301000073010000 I thought i was just having trouble due to having a dual core, but I'll try w/o ex.
11. Re: Noob, learning how to use dll's.
- Posted by Archarios <archarios at v?riz?n.net> Jun 13, 2008
- 783 views
Got similar results: 20000000,24000000,00000080FFDFA58,FFFFFFFFF00406EF8,0000FE7F00C0F67D,6A0100009B000000,6A0100004D010000,7301000007000000,7301000073010000 ?,36% cpu load, 554048660879 total physical memory, 18446744069418807032 available I don't know, am I reading the results wrong? using printf("%d",peek()) using variations of peek and peek4u/s my processor hardly goes above 15%, I have 4gb ram installed but only 2882028 is shown, 1980160 available
12. Re: Noob, learning how to use dll's.
- Posted by Bernie Ryan <xotron at b?uefr?g.com> Jun 13, 2008
- 805 views
CChris wrote: > > Archarios wrote: > > > > }}} <eucode> > > without warning > > include file.e > > include dll.e > > include safe.e > > > > atom file1,DLL,GMSx,mem,result > > object temp > > file1 = open("D:\obscured\test.txt","w") > > > > DLL = open_dll("kernel.dll") > > GMSx = define_c_func(DLL,"GlobalMemoryStatusEx",{C_POINTER},C_INT) > > mem = allocate(64) > > result = c_func(GMSx,{mem}) ----faults here > > printf(file1,"%d",peek(mem+1)) > > free(mem) > > close(file1) > > abort(0) > > </eucode> {{{ > > I get: > > C:\EUPHORIA\include\safe.e:516 in function original_c_func() > > c_proc/c_func: bad routine number (-1) > > i = -1 > > s = {832176} > > > > ... called from C:\EUPHORIA\include\safe.e:522 in function c_func() > > i = -1 > > s = {832176} > > r = <no value> > > > > ... called from D:\obscured\test.exw:13 > > > > Do I have to use machine.e for this, I was using safe.e since I'm new to > > dll's. > > Are you sure you need the Ex ? CChris: Ex is correct. The structure being passed contains some DWORDLONG,s ( 64-bit int types ).
mem = allocate(64) << is WRONG
mem = allocate(512) << CORRECT VALUE
}}}
Bernie
My files in archive: WMOTOR, XMOTOR, W32ENGIN, MIXEDLIB, EU_ENGIN, WIN32ERU, WIN32API
Can be downloaded here: http://www.rapideuphoria.com/cgi-bin/asearch.exu?dos=on&win=on&lnx=on&gen=on&keywords=bernie+ryan }}}
13. Re: Noob, learning how to use dll's.
- Posted by Mike777 <anon4321 at gmai?.c?m> Jun 13, 2008
- 794 views
Matt Lewis wrote: > > Mike777 wrote: > > > > I'm interested in creating a DLL that exposes a function which can be > > utilized > > within an Excel spreadsheet. > > > > For example, say my DLL has a function which is called specialaverage and it > > takes a series of potentially 10 numbers and calculates a "special average" > > (say, something like the highest 3 consecutive out of 5, using a floor > > approach whereby the next in the series can never be less than 20% beneath > > what its predecessor is). I want to put: > > > > =specialaverage(a1..a10) > > > > in the cell and have the result populated. > > > > I have looked at the notes on MSDN on creating a DLL for use with excel > > (referred to as an xll, I believe) but I'm not able to understand whether > > doing so in Euphoria is even possible. > > Do you have a live link for these notes? http://msdn.microsoft.com/en-us/library/bb687883.aspx Mike
14. Re: Noob, learning how to use dll's.
- Posted by Archarios <archarios at ?eri?on.net> Jun 13, 2008
- 767 views
Still stuck, nothing is reporting anything close to what I really have. Gotta go for now, I'll leave you with my code at the moment.
without warning include file.e include dll.e include safe.e atom file1,DLL,GMSx,mem,result object temp file1 = open("D:\\obscured\\test.txt","w") DLL = open_dll("kernel32.dll") GMSx = define_c_func(DLL,"GlobalMemoryStatusEx",{C_POINTER},C_INT) mem = allocate(512) result = c_func(GMSx,{mem}) for count = mem+8 by 8 do printf(file1,"%d\n",float64_to_atom(peek({count,8}))) end for puts(file1,peek({mem,512})) free(mem) close(file1) abort(0)
15. Re: Noob, learning how to use dll's.
- Posted by Bernie Ryan <xotron at blu?frog.?om> Jun 13, 2008
- 771 views
without warning include file.e include dll.e include safe.e atom file1,DLL,GMSx,mem,result object temp file1 = open("D:\\obscured\\test.txt","w") DLL = open_dll("kernel32.dll") GMSx = define_c_func(DLL,"GlobalMemoryStatusEx",{C_POINTER},C_INT) mem = allocate(512) -- dwLength: The size of the structure, in bytes. -- You must set this member before calling GlobalMemoryStatusEx. poke4(mem,512) result = c_func(GMSx,{mem}) for count = mem+8 by 8 do printf(file1,"%d\n",float64_to_atom(peek({count,8}))) end for puts(file1,peek({mem,512})) free(mem) close(file1) abort(0)
Bernie My files in archive: WMOTOR, XMOTOR, W32ENGIN, MIXEDLIB, EU_ENGIN, WIN32ERU, WIN32API Can be downloaded here: http://www.rapideuphoria.com/cgi-bin/asearch.exu?dos=on&win=on&lnx=on&gen=on&keywords=bernie+ryan
16. Re: Noob, learning how to use dll's.
- Posted by OtterDad <otter at f??l-moon.com> Jun 13, 2008
- 770 views
<snip> unless you're wrapping this purely as an exercise, it's been done already see http://www.rapideuphoria.com/memmon.zip Yours, OtterDad Don't sweat it -- it's not real life. It's only ones and zeroes. Gene Spafford
17. Re: Noob, learning how to use dll's.
- Posted by Larry Miller <larrymiller at s?sktel.?et> Jun 13, 2008
- 787 views
- Last edited Jun 14, 2008
Archarios wrote: > > Still stuck, nothing is reporting anything close to what I really have. Gotta > go for now, I'll leave you with my code at the moment. > }}} <eucode> > without warning > include file.e > include dll.e > include safe.e > > atom file1,DLL,GMSx,mem,result > object temp > file1 = open("D:\\obscured\\test.txt","w") > > DLL = open_dll("kernel32.dll") > GMSx = define_c_func(DLL,"GlobalMemoryStatusEx",{C_POINTER},C_INT) > mem = allocate(512) > result = c_func(GMSx,{mem}) > for count = mem+8 by 8 do > printf(file1,"%d\n",float64_to_atom(peek({count,8}))) > end for > puts(file1,peek({mem,512})) > free(mem) > close(file1) > abort(0) > </eucode> {{{ There are a number of problems here. safe.e can not be included this way as it will cause name space errors. As documented you must rename safe.e to machine.e and include machine.e. You would also have to rename the original machine.e before doing this. safe.e is intended for debugging only, not general use. The size of the structure need not be larger than 64 bytes. You must also poke this value into the first entry. The structure entries are 64 bit integers, not floating point numbers. float64_to_atom() can not be used here. This revised program should work:
without warning include file.e include dll.e include machine.e atom file1,DLL,GMSx,mem,result object temp file1 = open("D:\\obscured\\test.txt","w") DLL = open_dll("kernel32.dll") GMSx = define_c_func(DLL,"GlobalMemoryStatusEx",{C_POINTER},C_INT) mem = allocate(64) poke4(mem,64) result = c_func(GMSx,{mem}) for count = mem+8 to mem+48 by 8 do printf(file1,"%d\n",peek4u(count)+peek4u(count+4)*#100000000) end for free(mem) close(file1) abort(0)
Larry Miller
18. Re: Noob, learning how to use dll's.
- Posted by Larry Miller <larrymiller at saskte?.n?t> Jun 13, 2008
- 787 views
- Last edited Jun 14, 2008
Program should be: without warning include file.e include dll.e include machine.e atom file1,DLL,GMSx,mem,result object temp file1 = open("D:\\obscured\\test.txt","w") DLL = open_dll("kernel32.dll") GMSx = define_c_func(DLL,"GlobalMemoryStatusEx",{C_POINTER},C_INT) mem = allocate(64) poke4(mem,64) result = c_func(GMSx,{mem}) for count = mem+8 to mem+56 by 8 do printf(file1,"%d\n",peek4u(count)+peek4u(count+4)*#100000000) end for free(mem) close(file1) abort(0) The program in the prior post would miss the final structure entry. Larry Miller
19. Re: Noob, learning how to use dll's.
- Posted by Archarios <archarios at verizo??net> Jun 14, 2008
- 771 views
I finally found the problem. Before the last code I showed I had been offsetting my offsets by 1(made sense at the time). Funny that a little thing can be such a big pain. Everything is working fine now, thanks for all your help, hope I wasn't too big a pain, I usually don't ask for so much help.