Visual Basic을 통해 내 PC에 설치된 실제 메모리 (총 RAM)를 얻으려고합니다. 문제는 "0 바이트"를 반환하는 것입니다. 요 사용률, 여유 RAM, 총 페이징, 무료 페이지 및 Windows 용 RAM의 리소스 모니터와 같은 사용량을 보여주는 그래프의 양을 얻으십시오. 문제는 내가 처음에 사용 가능한 RAM의 정확한 양을 얻을 수 없다는 것입니다. 다른 사람들과 함께 나아 간다.Visual Basic 실제 메모리
내가 뭘 잘못하고있어? 감사합니다. http://s18.postimage.org/7zn5adst3/Memory.jpg 괜찮나 내가 당신을 매우 게 감사 할 수 있습니다 : 나는 이런 식으로 뭔가를 할 수 있다면 궁금하네요이 problem.Now를 해결 한
Option Strict On
Option Explicit On
Imports System.Math
Imports System.Management
Imports System.Runtime.InteropServices
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " API "
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi)> _
Private Structure MEMORYSTATUSEX
Dim dwLength As Integer
Dim dwMemoryLoad As Integer
Dim ullTotalPhys As ULong
End Structure
Private memoryInfo As MEMORYSTATUSEX
Private Declare Auto Sub GlobalMemoryStatusEx Lib "kernel32" (ByRef lpBuffer As MEMORYSTATUSEX)
#End Region
#Region " Variables "
Private mullTotalRAM As ULong
#End Region
#Region " Form Events "
Private Sub Form1_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
' set title
Me.Text = My.Application.Info.Title & " " & My.Application.Info.Version.Major.ToString & "." & _
My.Application.Info.Version.Minor.ToString
Application.DoEvents()
GetMemoryInfo()
Timer1.Enabled = True
End Sub
#End Region
#Region " Information Gathering and Display "
Private Sub GetMemoryInfo()
System.Windows.Forms.Application.DoEvents()
' set size of structure (required by this api call)
memoryInfo.dwLength = Marshal.SizeOf(memoryInfo)
GlobalMemoryStatusEx(memoryInfo)
mullTotalRAM = memoryInfo.ullTotalPhys
txtRAM.Text = FormatBytes(mullTotalRAM)
End Sub
#End Region
#Region " Update Timer "
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs)
GetMemoryInfo()
Application.DoEvents()
End Sub
#End Region
#Region " Formatting Routines "
Private Function FormatBytes(ByVal ullBytes As ULong) As String
Dim dblTemp As Double
Try
Select Case ullBytes
Case Is >= 1073741824 'GB
dblTemp = CDbl(ullBytes/1073741824)
Return FormatNumber(dblTemp, 2) & " GB"
Case 1048576 To 1073741823
dblTemp = CDbl(ullBytes/1048576) 'MB
Return FormatNumber(dblTemp, 0) & " MB"
Case 1024 To 1048575
dblTemp = CDbl(ullBytes/1024) 'KB
Return FormatNumber(dblTemp, 0) & " KB"
Case 0 To 1023
dblTemp = ullBytes ' bytes
Return FormatNumber(dblTemp, 0) & " bytes"
Case Else
Return ""
End Select
Catch
Return ""
End Try
End Function
#End Region
Private Sub ramaTotalRAM_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ramaTotalRAM.Enter
End Sub
Private Sub txtRAM_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtRAM.TextChanged
End Sub
End Class
:
이
내 코드입니다 많은.
가 실행중인 어떤 운영 시스템 (
.dll
는 코드에서 누락되었음을 통지)이에 DECL 당신의 API를 변경 ? –이것은 VB가 아닌 VB.Net입니다. – Bob77
@ Bob Riemersma : Visual Studio 2008을 사용하고 있으며 .vb 응용 프로그램입니다 ("Form1.vb"는 그 이름 임). –