On Nov 18, 5:11=A0pm, Andy <chocolatemint77...@nospicedham.yahoo.com>
wrote:
> On Nov 18, 4:07=A0pm, Richard Russell <n...@nospicedham.rtrussell.co.uk>
> wrote:
>
>
>
> > On Nov 18, 8:33=A0pm, "Nathan Baker"
>
> > <nathancba...@nospicedham.gmail.com> wrote:
> > > But how do we link the .NET Virtual Machine into our code?? =A0Which =
DLL do we
> > > link against? =A0Is there a "dotnetvm.dll"?
>
> > I see nothing to imply that the IWTSProtocolConnection Interface is
> > specifically a .NET interface; it appears to be an ordinary COM
> > interface as far as I understand the docs.
>
> > > Also, calling a 'method' infers that we need to reference (or instant=
iate)
> > > an object. =A0Don't we need a 'this' pointer?
>
> > Yes, but that's often no more difficult than calling (for example)
> > CoCreateInstance in OLE32.DLL.
>
> > > Wouldn't the .NET VM block access from our code on the grounds that o=
ur code
> > > breaks major tenets of "Managed Code" philosophy? =A0Security, etc...
>
> > Calling Object Methods and interfacing with Managed Code are different
> > things. =A0It may well be difficult to access Managed Code from
> > assembler (I've never tried) but calling COM Object Methods isn't.
>
> > Richard.http://www.rtrussell.co.uk/
>
> Someone was nice enough to write me some code.
>
> It shows idle time, system uptime, and last input.
>
> It shows system uptime and then zeros out whenever there is any "input
> activity".(mouse or kb)
>
> When there is input, last output starts incrementing.
>
> Now, to figure out the next step, I have to subject the correct values
> to determine when 5 minutes have gone by.
>
> When that is done, I have been told that ->
>
> <The window enumeration is really the only tricky part originally.>
>
> I know how to stop a process.
>
> I am studying the code when I have time.
>
> Have a great day,
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Andy
>
> http://intouch.org/magazine/daily-devotionalhttp://www.happynews.com
Here is some code. PLEASE leave credits in the source.
Thanks,
Andy
; GetLastInputInfo.asm Code by MarMo as posted
; on http://www.winasm.net/forum/index.php
.486
.model flat, stdcall
option casemap :none
include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
include \masm32\include\gdi32.inc
include \masm32\macros\pomacros.asm
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\gdi32.lib
WinMain PROTO :DWORD,:DWORD,:DWORD,:DWORD
WndProc PROTO :DWORD,:DWORD,:DWORD,:DWORD
TopXY PROTO :DWORD,:DWORD
Static
PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD
SetStaticTxt PROTO :DWORD,:DWORD
mTimerProc PROTO :DWORD,:DWORD,:DWORD,:DWORD
LASTINPUTINFO Struct
cbSize dd ?
dwTime dd ?
LASTINPUTINFO EndS
.data
szDisplayName db "GetLastInputInfo help",0
.data?
CommandLine dd ?
hWnd dd ?
hInstance dd ?
.code
start:
invoke GetModuleHandle, NULL
mov hInstance, eax
invoke GetCommandLine
mov CommandLine, eax
invoke WinMain,hInstance,NULL,CommandLine,SW_SHOWDEFAULT
invoke ExitProcess,eax
WinMain proc hInst :DWORD,
hPrevInst :DWORD,
CmdLine :DWORD,
CmdShow :DWORD
; LOCALs on stack
LOCAL wc :WNDCLASSEX
LOCAL msg :MSG
LOCAL Wwd :DWORD
LOCAL Wht :DWORD
LOCAL Wtx :DWORD
LOCAL Wty :DWORD
; Fill WNDCLASSEX structure with required variables
mov wc.cbSize, sizeof WNDCLASSEX
mov wc.style, CS_BYTEALIGNWINDOW
mov wc.lpfnWndProc, offset WndProc
mov wc.cbClsExtra, NULL
mov wc.cbWndExtra, NULL
m2m wc.hInstance, hInst
mov wc.hbrBackground, COLOR_BTNFACE+1
mov wc.lpszMenuName, NULL
mov wc.lpszClassName, offset szClassName
mov wc.hIcon, NULL
invoke LoadCursor,NULL,IDC_ARROW
mov wc.hCursor, eax
mov wc.hIconSm, 0
invoke RegisterClassEx, ADDR wc
; Center window at following size
mov Wwd, 300
mov Wht, 110
invoke GetSystemMetrics,SM_CXSCREEN
invoke TopXY,Wwd,eax
mov Wtx, eax
invoke GetSystemMetrics,SM_CYSCREEN
invoke TopXY,Wht,eax
mov Wty, eax
szText szClassName,"GetLastInputInfo_Class"
invoke CreateWindowEx,WS_EX_OVERLAPPEDWINDOW,
ADDR szClassName,
ADDR szDisplayName,
WS_OVERLAPPEDWINDOW or WS_CLIPCHILDREN,
Wtx,Wty,Wwd,Wht,
NULL,NULL,
hInst,NULL
mov hWnd,eax
invoke ShowWindow,hWnd,SW_SHOWNORMAL
invoke UpdateWindow,hWnd
; Loop until PostQuitMessage is sent
StartLoop:
invoke GetMessage,ADDR msg,NULL,0,0
cmp eax, 0
je ExitLoop
invoke TranslateMessage, ADDR msg
invoke DispatchMessage, ADDR msg
jmp StartLoop
ExitLoop:
return msg.wParam
WinMain endp
WndProc proc hWin :DWORD,
uMsg :DWORD,
wParam :DWORD,
lParam :DWORD
LOCAL Rc :RECT
LOCAL rLeft :DWORD
LOCAL rTop :DWORD
LOCAL rRight :DWORD
LOCAL rBottom :DWORD
.if uMsg =3D=3D WM_CREATE
jmp @F
lbl1 db "Idle Time:",0
lbl2 db "System Uptime:",0
lbl3 db "Last Input:",0
lbl4 db "0 seconds ",0
@@:
;Create labels
invoke Static,ADDR lbl1,hWin,20,5,130,18,-1,WS_CHILD or
WS_VISIBLE or SS_LEFT
invoke Static,ADDR lbl2,hWin,20,30,130,18,-1,WS_CHILD or
WS_VISIBLE or SS_LEFT
invoke Static,ADDR lbl3,hWin,20,55,130,18,-1,WS_CHILD or
WS_VISIBLE or SS_LEFT
invoke Static,ADDR lbl4,hWin,130,5,140,18,500,WS_CHILD or
WS_VISIBLE or SS_RIGHT
invoke Static,ADDR lbl4,hWin,130,30,140,18,501,WS_CHILD or
WS_VISIBLE or SS_RIGHT
invoke Static,ADDR lbl4,hWin,130,55,140,18,502,WS_CHILD or
WS_VISIBLE or SS_RIGHT
; start timer proc 1000 =3D 1 secund
invoke SetTimer,hWin,NULL,1000,addr mTimerProc
.elseif uMsg =3D=3D WM_SIZE
.elseif uMsg =3D=3D WM_CLOSE
.elseif uMsg =3D=3D WM_DESTROY
invoke PostQuitMessage,NULL
return 0
.endif
invoke DefWindowProc,hWin,uMsg,wParam,lParam
ret
WndProc endp
TopXY proc wDim:DWORD, sDim:DWORD
shr sDim, 1 ; divide screen dimension by 2
shr wDim, 1 ; divide window dimension by 2
mov eax, wDim ; copy window dimension into eax
sub sDim, eax ; sub half win dimension from half screen
dimension
return sDim
TopXY endp
Static proc lpText:DWORD,hParent:DWORD,
=20
a:DWORD,b:DWORD,wd:DWORD,ht:DWORD,ID:DWORD,dwStyle:DWORD
LOCAL hStat :DWORD
LOCAL hFont :DWORD
szText statClass,"STATIC"
invoke CreateWindowEx,WS_EX_STATICEDGE,
ADDR statClass,lpText,
dwStyle,
a,b,wd,ht,hParent,ID,
hInstance,NULL
mov hStat, eax
invoke GetStockObject,ANSI_FIXED_FONT
mov hFont, eax
invoke SendMessage,hStat,WM_SETFONT,hFont, 0
mov eax, hStat
ret
Static endp
SetStaticTxt proc TickCount :DWORD, ID :DWORD
LOCAL Buffer[24]:BYTE
xor edx, edx
mov eax, TickCount
mov ecx, 1000
div ecx
szText ctlstr,"%-2.6lu seconds "
invoke wsprintf,ADDR Buffer,ADDR ctlstr,eax
invoke SetDlgItemText,hWnd,ID,ADDR Buffer
ret
SetStaticTxt endp
mTimerProc proc hWndT :DWORD,
uMsg :DWORD,
idEvent :DWORD,
dwTime :DWORD
LOCAL plii :LASTINPUTINFO
LOCAL LastInputTicks :DWORD
LOCAL IdleTicks :DWORD
LOCAL systemUptime :DWORD
;The tick at which the last input was recorded
mov LastInputTicks, 0
;The number of ticks that passed since last input
mov IdleTicks, 0
;Set the struct
mov plii.cbSize, sizeof LASTINPUTINFO
mov plii.dwTime, 0
;If we have a value from the function
invoke GetLastInputInfo, addr plii
.If eax!=3D0
;Get the number of ticks at the point when the last activity was
seen
m2m LastInputTicks, plii.dwTime
;Number of idle ticks =3D system uptime ticks - number of ticks at
last input
invoke GetTickCount
mov systemUptime, eax
sub eax, LastInputTicks
mov IdleTicks, eax
.EndIf
;change text
invoke SetStaticTxt,systemUptime,500
invoke SetStaticTxt,IdleTicks,501
invoke SetStaticTxt,LastInputTicks,502
ret
mTimerProc endp
end start
|