BBC BASIC for Windows
« cpuspeed program expansion.... »

Welcome Guest. Please Login or Register.
Apr 5th, 2018, 9:53pm



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

If you require a dump of the post on your message board, please come to the support board and request it.


Thank you Conforums members.

BBC BASIC for Windows Resources
Online BBC BASIC for Windows documentation
BBC BASIC for Windows Beginners' Tutorial
BBC BASIC Home Page
BBC BASIC on Rosetta Code
BBC BASIC discussion group
BBC BASIC for Windows Programmers' Reference

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: cpuspeed program expansion....  (Read 729 times)
Yshua
New Member
Image


member is offline

Avatar




PM


Posts: 6
xx cpuspeed program expansion....
« Thread started on: Jul 16th, 2015, 5:45pm »

Dear BBC BASIC forum people:

Have a program running successfully, an expansion of cpuspeed.com, as follows:

REM Get CPU clock speed using Windows Management Instrumentation (WMI)
REM Adapted from http://www.codeproject.com/KB/system/UsingWMI.aspx
REM Richard Russell, http://www.rtrussell.co.uk/, 18-Sep-2010

REM Load OLE32 library:
SYS "LoadLibrary", "OLE32.DLL" TO ole32%
SYS "GetProcAddress", ole32%, "CoInitializeEx" TO `CoInitializeEx`
SYS "GetProcAddress", ole32%, "CoUninitialize" TO `CoUninitialize`
SYS "GetProcAddress", ole32%, "CoCreateInstance" TO `CoCreateInstance`
SYS "GetProcAddress", ole32%, "CoSetProxyBlanket" TO `CoSetProxyBlanket`
SYS "GetProcAddress", ole32%, "CLSIDFromString" TO `CLSIDFromString`

REM Define constants:
RPC_C_AUTHN_LEVEL_CALL = 3
RPC_C_AUTHN_WINNT = 10
RPC_C_AUTHZ_NONE = 0
RPC_C_IMP_LEVEL_IMPERSONATE = 3
WBEM_FLAG_FORWARD_ONLY = &20

CLSID_WbemLocator% = FNguid("{4590f811-1d3a-11d0-891f-00aa004b2e24}")
IID_IWbemLocator% = FNguid("{dc12a687-737f-11cf-884d-00aa004b2e24}")
CLSCTX_INPROC_SERVER = 1

REM Define COM interfaces:
DIM IWbemLocator{QueryInterface%, AddRef%, Release%, ConnectServer%}

DIM IWbemServices{QueryInterface%, AddRef%, Release%, OpenNameSpace%, \
\ CancelAsyncCall%, QueryObjectSink%, GetObject%, GetObjectAsync%, \
\ PutClass%, PutClassAsync%, DeleteClass%, DeleteClassAsync%, \
\ CreateClassEnum%, CreateClassEnumAsync%, PutInstance%, PutInstanceAsync%, \
\ DeleteInstance%, DeleteInstanceAsync%, CreateInstanceEnum%, \
\ CreateInstanceEnumAsync%, ExecQuery%, ExecQueryAsync%, \
\ ExecNotificationQuery%, ExecNotificationQueryAsync%, ExecMethod%, \
\ ExecMethodAsync%}

DIM IEnumWbemClassObject{QueryInterface%, AddRef%, Release%, \
\ Reset%, Next%, NextAsync%, Clone%, Skip%}

DIM IWbemClassObject{QueryInterface%, AddRef%, Release%, \
\ GetQualifierSet%, Get%, Put%, Delete%, GetNames%, BeginEnumeration%, \
\ Next%, EndEnumeration%, GetPropertyQualifierSet%, Clone%, GetObjectText%, \
\ SpawnDerivedClass%, SpawnInstance%, CompareTo%, GetPropertyOrigin%, \
\ InheritsFrom%, GetMethod%, PutMethod%, DeleteMethod%, \
\ BeginMethodEnumeration%, NextMethod%, EndMethodEnumeration%, \
\ GetMethodQualifierSet%, GetMethodOrigin%}

REM Initialise COM:
SYS `CoInitializeEx`, 0, 0

ON ERROR PROCcleanup : SYS "MessageBox", @hwnd%, REPORT$, 0, 48 : QUIT
ON CLOSE PROCcleanup : QUIT

REM Get CPU speed using WMI:

SYS `CoCreateInstance`, CLSID_WbemLocator%, 0, CLSCTX_INPROC_SERVER, \
\ IID_IWbemLocator%, ^pLoc% TO hr%
IF hr% THEN ERROR 100, "Could not create IWbemLocator interface"
!(^IWbemLocator{}+4) = !pLoc%

SYS IWbemLocator.ConnectServer%, pLoc%, FNwide("root\cimv2"), \
\ 0, 0, 0, 0, 0, 0, ^pSvc% TO hr%
IF hr% THEN ERROR 100, "Could not create IWbemServices interface"
!(^IWbemServices{}+4) = !pSvc%

SYS `CoSetProxyBlanket`, pSvc%, RPC_C_AUTHN_WINNT, RPC_C_AUTHZ_NONE, 0, \
\ RPC_C_AUTHN_LEVEL_CALL, RPC_C_IMP_LEVEL_IMPERSONATE, 0, 0 TO hr%
IF hr% THEN ERROR 100, "Could not set proxy blanket"

query$ = FNwide("SELECT * FROM Win32_Processor")
lang$ = FNwide("WQL")
SYS IWbemServices.ExecQuery%, pSvc%, lang$, query$, \
\ WBEM_FLAG_FORWARD_ONLY, 0, ^pEnum% TO hr%
IF hr% THEN ERROR 100, "Could not query Win32_Processor enumerator"
!(^IEnumWbemClassObject{}+4) = !pEnum%

SYS IEnumWbemClassObject.Next%, pEnum%, -1, 1, ^pCPU%, ^nret% TO hr%
IF hr% THEN ERROR 100, "Could not enumerate Win32_Processor object"
!(^IWbemClassObject{}+4) = !pCPU%

DIM var{vartype{l&,h&},reserved&(5),ldata%,hdata%}
SYS IWbemClassObject.Get%, pCPU%, FNwide("CurrentClockSpeed"), 0, \
\ var{}, 0, 0 TO hr%
IF hr% THEN ERROR 100, "Could not get processor clock speed"

PRINT "CPU #0 clock speed = " ; var.ldata% AND &FFFF ; " MHz"

DIM var{vartype{l&,h&},reserved&(5),ldata%,hdata%}
SYS IWbemClassObject.Get%, pCPU%, FNwide("DataWidth"), 0, \
\ var{}, 0, 0 TO hr%
IF hr% THEN ERROR 100, "Could not get data width"

PRINT "data width = " ; var.ldata% AND &FFFF

DIM var{vartype{l&,h&},reserved&(5),ldata%,hdata%}
SYS IWbemClassObject.Get%, pCPU%, FNwide("Description"), 0, \
\ var{}, 0, 0 TO hr%
IF hr% THEN ERROR 100, "Could not get processor description"

DIM cpu{desc&(256)}
SYS "WideCharToMultiByte", 0, 0, var.ldata%, -1, cpu{}, 256, 0, 0
PRINT "CPU #0 description = """ cpu.desc&() """"

DIM var{vartype{l&,h&},reserved&(5),ldata%,hdata%}
SYS IWbemClassObject.Get%, pCPU%, FNwide("Manufacturer"), 0, \
\ var{}, 0, 0 TO hr%
IF hr% THEN ERROR 100, "Could not get Manufacturer"

DIM cpu{desc&(256)}
SYS "WideCharToMultiByte", 0, 0, var.ldata%, -1, cpu{}, 256, 0, 0
PRINT "CPU #0 description = """ cpu.desc&() """"

DIM var{vartype{l&,h&},reserved&(5),ldata%,hdata%}
SYS IWbemClassObject.Get%, pCPU%, FNwide("Revision"), 0, \
\ var{}, 0, 0 TO hr%
IF hr% THEN ERROR 100, "Could not get revision"

PRINT "Revision number = " ; var.ldata% AND &FFFF ; "."


PROCcleanup

END

DEF PROCcleanup
pCPU% += 0 : IF pCPU% SYS !(!pCPU%+8), pCPU% : pCPU% = 0
pEnum% += 0 : IF pEnum% SYS !(!pEnum%+8), pEnum% : pEnum% = 0
pSvc% += 0 : IF pSvc% SYS !(!pSvc%+8), pSvc% : pSvc% = 0
pLoc% += 0 : IF pLoc% SYS !(!pLoc%+8), pLoc% : pLoc% = 0
SYS `CoUninitialize`
ENDPROC

DEF FNwide(A$)
LOCAL M$
M$ = STRING$(2*LENA$+2,CHR$0)
SYS "MultiByteToWideChar", 0, 0, A$, -1, M$, LENA$+1
= M$

DEF FNguid(A$)
LOCAL C%, M%
DIM C% 15, M% LOCAL 2*LENA$+1
SYS "MultiByteToWideChar", 0, 0, A$, -1, M%, LENA$+1
SYS `CLSIDFromString`, M%, C%
= C%


Now when even just one more WMI attribute is added, such as,


DIM cpu{desc&(256)}
SYS "WideCharToMultiByte", 0, 0, var.ldata%, -1, cpu{}, 256, 0, 0
PRINT "CPU #0 description = """ cpu.desc&() """"

DIM var{vartype{l&,h&},reserved&(5),ldata%,hdata%}
SYS IWbemClassObject.Get%, pCPU%, FNwide("InstallDate"), 0, \
\ var{}, 0, 0 TO hr%
IF hr% THEN ERROR 100, "Could not get install date"

after the CPU Description attribute, this attribute simply repeats the CPU Description. Also is there a limit to how many attributes can be printed out in the program?

Thanks sooo much,
Yshua
huh huh
User IP Logged

rtr2
Guest
xx Re: cpuspeed program expansion....
« Reply #1 on: Jul 16th, 2015, 9:14pm »

on Jul 16th, 2015, 5:45pm, Yshua wrote:
Now when even just one more WMI attribute is added, such as... "InstallDate"... this attribute simply repeats the CPU Description.

It doesn't "repeat" the CPU Description, that string is simply left over from the previous operation. If you had checked the returned VARTYPE you would have seen that it is VT_NULL, which I suspect simply means that the InstallDate property is not available for the processor.

Quote:
Also is there a limit to how many attributes can be printed out in the program?

No.

Richard.
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls