We need you!

We're working hard on the next version of Developer Fusion. Let us know what you think we should be up to!

Members

Technology Zones

Articles

Hosted By

MaximumASP

Info

Rated
Read 35,789 times

Contents

Related Categories

API Programming Series #5 - The Code

sreejath

The Code

As usual, fire up VB and create a Standard EXE project. Copy this code into the General Declarations section of the form that is added to the project by default:

Private Type MEMORYSTATUS
  dwLength As Long
  dwMemoryLoad As Long
  dwTotalPhys As Long
  dwAvailPhys As Long
  dwTotalPageFile As Long
  dwAvailPageFile As Long
  dwTotalVirtual As Long
  dwAvailVirtual As Long
End Type

Private Declare Sub GlobalMemoryStatus Lib "kernel32" Alias "GlobalMemoryStatus" (lpBuffer As MEMORYSTATUS)

Here we first declare a user defined type structure, MEMORYSTATUS. It contains eight members all of the type Long. A variable of this Type is passed ByRef as argument to the GlobalMemoryStatus API function. (See Article 1 and Article 2 of this series for more info on ByVal, ByRef and other such creatures associated with API programming.

The GlobalMemoryStatus function retrieves information about current available memory. The function returns information about both physical and virtual memory. The function populates it with the memory information parameters, which we can then determine by examining the appropriate variable.

Now, add the following code to any suitable event in your app where you want to display the memory status:

Dim memInfo As MEMORYSTATUS
GlobalMemoryStatus memInfo 'In this step we invoked the GlobalMemoryStatus function and pass it meminfo as parameter
MsgBox "Total memory (in bytes): " & memInfo.dwTotalPhys
MsgBox "Available memory (in bytes): " & memInfo.dwAvailPhys

Comments

  • questions..

    Posted by mistkron on 04 Nov 2004

    this is really nice article, but im wondering is there a way to display the memory status in a textbox ? well im rather new to vb.

  • MSFlexGrid to Excel

    Posted by wayp on 20 Jan 2004

    I always do this for my "print to file" checkbox in the print dialog

    **Needed Reference** : Microsoft Excel x.y Object Library

    [code]
    Public Sub ExportFlexGrid(ByRef objGrid As MSFlexGrid)
    ...

  • vb and excel

    Posted by marz on 24 Aug 2003

    HI!

    Is there a way to transfer the database to excel rather usingt the datareport?
    If you have any suggestions or ideas pls feel free to mail me.

    thanks.
    marz!
    marz03@yahoo.com

  • Thanks

    Posted by sreejath on 05 Jun 2003

    Thank you for expressing your appreciation.

  • Thanks..

    Posted by troygates on 02 Jun 2003

    Thank you for spending your time to write these great articles. They are very helpful and clearly written.