Jump to content

DLL Call Help, Please.


Recommended Posts

Good day, all.

Here's an interesting snippet from another post:

If @OSType = "WIN32_WINDOWS" Then
    Dim $Resinfo[2]
    $Resinfo = DLLCall("RSRC32.DLL","long","_MyGetFreeSystemResources32@4","long",0)
    $Free_System_Resources = $Resinfo[0]
    $Resinfo = DLLCall("RSRC32.DLL","long","_MyGetFreeSystemResources32@4","long",1)
    $Free_GDI_Resources = $Resinfo[0]
    $Resinfo = DLLCall("RSRC32.DLL","long","_MyGetFreeSystemResources32@4","long",2)
    $Free_User_Resources = $Resinfo[0]
    MsgBox(0, "System Resource Information" , "OS Type is: " & @TAB & @TAB & @OSType & "," & @CRLF & _
    "Free System Resources: " & @TAB & $Free_System_Resources & "%," & @CRLF & _
    "Free GDI Resources: " & @TAB & $Free_GDI_Resources & "%," & @CRLF & _
    "Free User Resources: " & @TAB & $Free_User_Resources & "%")
EndIf

(see http://www.autoitscript.com/forum/index.ph...l=GDI+Resources for the full citation)

Works like a charm!

Now, what I'd like to do is use this same simple code format to pull out the following from kernel32's GlobalMemoryStatus():

*MemoryLoad

*TotalPhys

*AvailPhys

I've hammered at the syntax this way and that, to no avail :D

A simple tweak, anyone?

Thanks!

[center][font="Courier"][quote]Which end do you put the cheesecake in?[/quote][/font][/center]

Link to comment
Share on other sites

First, you require to create this type of structure:

typedef struct _MEMORYSTATUS {
  DWORD dwLength;
  DWORD dwMemoryLoad;
  SIZE_T dwTotalPhys;
  SIZE_T dwAvailPhys;
  SIZE_T dwTotalPageFile;
  SIZE_T dwAvailPageFile;
  SIZE_T dwTotalVirtual;
  SIZE_T dwAvailVirtual;
} MEMORYSTATUS, 
 *LPMEMORYSTATUS;

Then, you have to call this function with a pointer to the structure:

DLL Requires Kernel32.dll.

void GlobalMemoryStatus(
  LPMEMORYSTATUS lpBuffer
);

And read the data from that structure!

#)

Link to comment
Share on other sites

@nfwu:

Thank you for the input.

Still a little lost here . . .

How would this info fit into the form posted above:

Dim $Resinfo[2]
    $Resinfo = DLLCall("RSRC32.DLL","long","_MyGetFreeSystemResources32@4","long",0)
    $Free_System_Resources = $Resinfo[0]
     . . .

Seems like it should be a straightforward graft, no???

:D

Thanks again --

[center][font="Courier"][quote]Which end do you put the cheesecake in?[/quote][/font][/center]

Link to comment
Share on other sites

Wierd... I'm confusing people more often than usual nowadays... well anyway, I'll give you some sample code, then you can fiddle with it!

Wait up!

#)

Link to comment
Share on other sites

Anybody knows how many bytes a "SIZE_T" occupies?

$SIZE_T = "byte"
$struct = DLLStructCreate("dword;dword;"&$SIZE_T&";"&$SIZE_T&";"&$SIZE_T&";"&$SIZE_T&";"&$SIZE_T&";"&$SIZE_T)
DLLCall("Kernel32.dll", "none", "GlobalMemoryStatus", "ptr", StructGetPtr($struct))
$MemoryLoad = StructGetData($struct, 2)
$TotalPhys = StructGetData($struct, 3)
$AvaliablePhys = StructGetData($struct, 4)

NOTE: Not tested.

If you do find out what SIZE_T equates to, replace the "byte" here: $SIZE_T = "byte" with the appropriate type.

#)

Link to comment
Share on other sites

size_t is usually 32 bits / 4 bytes / int.

(http://www.google.nl/search?q=size_t -> http://tigcc.ticalc.org/doc/stddef.html)

$SIZE_T = "int"
$struct = DLLStructCreate("dword;dword;"&$SIZE_T&";"&$SIZE_T&";"&$SIZE_T&";"&$SIZE_T&";"&$SIZE_T&";"&$SIZE_T)
DLLCall("Kernel32.dll", "none", "GlobalMemoryStatus", "ptr", DllStructGetPtr($struct))
$MemoryLoad = DllStructGetData($struct, 2)
$TotalPhys = DllStructGetData($struct, 3)
$AvaliablePhys = DllStructGetData($struct, 4)

ConsoleWrite($MemoryLoad & @LF)
ConsoleWrite($TotalPhys & @LF)
ConsoleWrite($AvaliablePhys & @LF)

51
1073197056
516308992
Edited by w0uter

My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll

Link to comment
Share on other sites

Excellent :D

I actually figured out that the whole SIZE_T thing equated to an int while hammering Google about this the other day. So close...

However, I apparently am "well behind the times"; as I have v. 3, 1, 0, 4. No support for DLLStructCreate in this version. The release info page at AutoIt doesn't list anything like DLLStructCreate as a recent update -- but it obviously is...

I'll download the latest and give it all a spin :D

Thanks folks!

[center][font="Courier"][quote]Which end do you put the cheesecake in?[/quote][/font][/center]

Link to comment
Share on other sites

Excellent :D

I actually figured out that the whole SIZE_T thing equated to an int while hammering Google about this the other day. So close...

However, I apparently am "well behind the times"; as I have v. 3, 1, 0, 4. No support for DLLStructCreate in this version. The release info page at AutoIt doesn't list anything like DLLStructCreate as a recent update -- but it obviously is...

I'll download the latest and give it all a spin :D

Thanks folks!

DllStruct functions are availble currently only in the Beta version

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

Ok...

Had just returned to the thread to report that v 3.1.1.0 showed no support either. Hence the confusion...

Is there any way of porting

$SIZE_T = "int"
$struct = DLLStructCreate("dword;dword;"&$SIZE_T&";"&$SIZE_T&";"&$SIZE_T&";"&$SIZE_T&";"&$SIZE_T&";"&$SIZE_T)
DLLCall("Kernel32.dll", "none", "GlobalMemoryStatus", "ptr", DllStructGetPtr($struct))
$MemoryLoad = DllStructGetData($struct, 2)
$TotalPhys = DllStructGetData($struct, 3)
$AvaliablePhys = DllStructGetData($struct, 4)

ConsoleWrite($MemoryLoad & @LF)
ConsoleWrite($TotalPhys & @LF)
ConsoleWrite($AvaliablePhys & @LF)

to the latest final release???

Just wondering if there's a hack which'd do the job . . .

Thanx.

[center][font="Courier"][quote]Which end do you put the cheesecake in?[/quote][/font][/center]

Link to comment
Share on other sites

w0uter:

maby a stupid question but why not just use the beta ?

Because it's in Beta :D Not interested in debugging at this time . . .

Also thought it looked like a fun challenge for some of the more savvy members to try and "make it work" on the latest stable version :D

Thanks again for the help which you could give!

Have a great day :P

[center][font="Courier"][quote]Which end do you put the cheesecake in?[/quote][/font][/center]

Link to comment
Share on other sites

w0uter:

Because it's in Beta :D Not interested in debugging at this time . . .

So you just assume we write shit for code and leave it to peon's like you to debug for us? Maybe I should start actually doing that, it would save so much time if I didn't test my code.

Oh, perhaps I should mention to you, the so-called "stable" version of AutoIt is nowhere near as stable as the current beta's. So your logic of not using a beta because you don't want to debug it is flawed on pretty much every front.

Link to comment
Share on other sites

@Valik:

That was WAY OVER THE TOP.

HOW DARE YOU ADDRESS A FELLOW MEMBER OF THIS COMMUNITY WITH SUCH AN ABRASIVE, SWAGGERING REBUKE!

I don't care what or who you are, or what little thing it is that you do -- stay away from public interchanges until you can conduct yourself in a decent, normal, civilized manner.

Now, if there's anyone else who has CONSTRUCTIVE input on the code in question, DEVOID OF PROFANITY AND PERSONAL ATTACK, I welcome your response.

Thank you.

[center][font="Courier"][quote]Which end do you put the cheesecake in?[/quote][/font][/center]

Link to comment
Share on other sites

@Valik:

That was WAY OVER THE TOP.

Err, no, that was a rather tame comment from me. And quite a relevant one, too, given you just slammed my code as well as the code of several other qualified people by stating you didn't want to debug it.

HOW DARE YOU ADDRESS A FELLOW MEMBER OF THIS COMMUNITY WITH SUCH AN ABRASIVE, SWAGGERING REBUKE!

How dare I? I dare do a lot worse. I let you off "easy". I would hardly call it "abrasive" or "swaggering".

I don't care what or who you are, or what little thing it is that you do -- stay away from public interchanges until you can conduct yourself in a decent, normal, civilized manner.

Why? Where's the fun in being decent, normal and civilized?

Now, if there's anyone else who has CONSTRUCTIVE input on the code in question, DEVOID OF PROFANITY AND PERSONAL ATTACK, I welcome your response.

Thank you.

Show me where I made a personal attack. Go on, find it. Find it in this post, too. A common staple of me "attacking" somebody is calling them an idiot or stupid or some other term. I did none of these things. I can do them, if you wish (or I wish as that's really the only determining factor). However, if you are referring to the "peon" comment, it should be blatantly obvious from the tone that it was in fact sarcasm, not a real "attack". The profanity was also meant to convey the tone but you obviously missed that literary device as well since you got all uppity over the word "shit" (ooh, I said it again).

The only person who did any personal attacking was you with your comment that our code needed debugged when it is in fact more stable than a version you insist on staying with. You also attack me directly in the post I'm quoting where you state "what little thing it is that you do". The credits section has an extended list of contributions from each developer so you can see all the "little things" I've done.

I'll give you this much, that's quite possibly the funniest post I've read all year, though. I imagine several other forum regulars who know my behavior got a kick out of your reaction, too.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...