應(yīng)用里添加?System.Management
10余年的本溪網(wǎng)站建設(shè)經(jīng)驗,針對設(shè)計、前端、開發(fā)、售后、文案、推廣等六對一服務(wù),響應(yīng)快,48小時及時工作處理。成都全網(wǎng)營銷的優(yōu)勢是能夠根據(jù)用戶設(shè)備顯示端的尺寸不同,自動調(diào)整本溪建站的顯示方式,使網(wǎng)站能夠適用不同顯示終端,在瀏覽器中調(diào)整網(wǎng)站的寬度,無論在任何一種瀏覽器上瀏覽網(wǎng)站,都能展現(xiàn)優(yōu)雅布局與設(shè)計,從而大程度地提升瀏覽體驗。創(chuàng)新互聯(lián)從事“本溪網(wǎng)站設(shè)計”,“本溪網(wǎng)站推廣”以來,每個客戶項目都認(rèn)真落實執(zhí)行。
文件前加上
Imports?System.Management
'''?summary
'''?獲取系統(tǒng)內(nèi)存大小
'''?/summary
'''?returns內(nèi)存大?。▎挝籅yte)/returns
Private?shared?Function?GetPhisicalMemory()As?Long
dim?searcher?=?new?ManagementObjectSearcher()???'用于查詢一些如系統(tǒng)信息的管理對象
searcher.Query?=?new?SelectQuery("Win32_PhysicalMemory?",?"",?new?string()?{?"Capacity"?})'設(shè)置查詢條件?
dim?collection?=?searcher.Get()???'獲取內(nèi)存容量?
dim?em?=?collection.GetEnumerator()
dim?capacity?as?long=?0
While?(em.MoveNext())
dim?baseObj?=?em.Current
If?(baseObj.Properties("Capacity").Value?IsNot?Nothing)?Then????????????????????
Try
capacity?+=?long.Parse(baseObj.Properties("Capacity").Value.ToString())
Catch
return?0
End?Try
End?If?
End?While
return?capacity
End?Function
你是想讀取游戲進(jìn)程吧 這個問題剛開始也 讓我郁悶了很久 其實很多 游戲?qū)ψx取內(nèi)存做了特殊處理 常規(guī)的 調(diào)用api打開進(jìn)程 讀取內(nèi)存 無效可以嘗試 用token 直接調(diào)用就ok了 返回true說明調(diào)用成功下面是詳細(xì)代碼 Public Class ToKen
#Region "常數(shù)及結(jié)構(gòu)聲明"
Private Const SE_PRIVILEGE_ENABLED As Int32 = 2
Private Const EWX_SHUTDOWN As Int32 = 1
Private Const EWX_REBOOT As Int32 = 2
Private Const EWX_LOGOFF As Int32 = 0
Private Structure LUID_AND_ATTRIBUTES
Public pLuid As LUID
Public Attributes As Integer
End Structure
Private Structure LUID
Dim LowPart As Int32
Dim HighPart As Int32
End Structure
Private Structure TOKEN_PRIVILEGES
Public PrivilegeCount As Integer
Public Privileges As LUID
Public Attributes As Int32
End Structure
#End Region#Region "API聲明"
Private Declare Function LookupPrivilegeValue Lib "advapi32.dll" Alias "LookupPrivilegeValueA" (ByVal lpSystemName As String, ByVal lpName As String, ByRef lpLuid As LUID) As Int32
Private Declare Function AdjustTokenPrivileges Lib "advapi32.dll" (ByVal TokenHandle As IntPtr, ByVal DisableAllPrivileges As Int32, ByRef NewState As TOKEN_PRIVILEGES, ByVal BufferLength As Int32, ByRef PreviousState As TOKEN_PRIVILEGES, ByRef ReturnLength As Int32) As Int32
Private Declare Function OpenProcessToken Lib "advapi32.dll" (ByVal ProcessHandle As IntPtr, ByVal DesiredAccess As Integer, ByRef TokenHandle As IntPtr) As Boolean
#End Region
#Region "獲取全部權(quán)限"
Public Function ToKenPrivileges() As Boolean
Dim hdlTokenHandle As Integer
Dim tmpLuid As LUID
Dim tkp As TOKEN_PRIVILEGES
Dim tkpNewButIgnored As TOKEN_PRIVILEGES
Dim lBufferNeeded As Integer
Dim currentProcess As Process = Process.GetCurrentProcess()
If OpenProcessToken(currentProcess.Handle, HF00FF, hdlTokenHandle) Then
LookupPrivilegeValue("", "SeDebugPrivilege", tmpLuid)
tkp.PrivilegeCount = 1
tkp.Privileges = tmpLuid
tkp.Attributes = SE_PRIVILEGE_ENABLED
Return AdjustTokenPrivileges(hdlTokenHandle, False, tkp, Len(tkpNewButIgnored), tkpNewButIgnored, lBufferNeeded)
End If
End Function
#End Region
End Class
這說明你調(diào)用 API 傳參存在問題。
首先有沒有設(shè)置結(jié)構(gòu)體內(nèi)存對齊?
[StructLayout(LayoutKind.Sequential)] 加了嗎?
COLORREF 不要用 Color 代替,用 int 代替
TCHAR cfFaceName[32] 定義為 Byte 數(shù)組也可以,帶在傳參前,必須初始化為 32 個長度