Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'master' of https://github.com/begoon/stuff

  • Loading branch information...
commit a0c7f15278fa8ad7ab62bd39b7126f0a4e777100 2 parents 99fb38a + 3ef509b
@begoon authored
Showing with 2,331 additions and 0 deletions.
  1. +1 −0  devices/xport/backup.cmd
  2. +4 −0 devices/xport/checkout-bin.cmd
  3. +1 −0  devices/xport/clean.cmd
  4. +148 −0 devices/xport/formload.cpp
  5. +12 −0 devices/xport/formload.h
  6. +145 −0 devices/xport/main.cpp
  7. +228 −0 devices/xport/main.dfm
  8. +74 −0 devices/xport/main.h
  9. +126 −0 devices/xport/xportgpio.cpp
  10. +41 −0 devices/xport/xportgpio.h
  11. +127 −0 devices/xport/xporttest.bpr
  12. +33 −0 devices/xport/xporttest.cpp
  13. +13 −0 devices/xport/xporttest.ini
  14. BIN  devices/xport/xporttest.res
  15. +7 −0 languages/assembler/i8080/as-test/Makefile
  16. +16 −0 languages/assembler/i8080/as-test/test.asm
  17. +41 −0 languages/c++/fibonacci/fibo_sequence.cpp
  18. +45 −0 languages/php/ucs2/hex.php
  19. +46 −0 languages/php/ucs2/intconv.php
  20. +77 −0 languages/php/ucs2/ucs2.php
  21. +18 −0 languages/python/serial/modem.py
  22. +23 −0 languages/python/threads/threads.py
  23. 0  languages/python/{begemot → xls}/begemon-convert.py
  24. +10 −0 wince/hello/hello.c
  25. +6 −0 wince/hello/hello1.c
  26. +6 −0 wince/hello/hello2.c
  27. +75 −0 wince/hello/simple_window.c
  28. +1 −0  windows/joystick/backup.cmd
  29. +4 −0 windows/joystick/checkout-bin.cmd
  30. +1 −0  windows/joystick/clean.cmd
  31. +129 −0 windows/joystick/joytest.bpr
  32. +33 −0 windows/joystick/joytest.cpp
  33. BIN  windows/joystick/joytest.res
  34. +55 −0 windows/joystick/main.cpp
  35. +95 −0 windows/joystick/main.dfm
  36. +35 −0 windows/joystick/main.h
  37. +1 −0  windows/lnkparse/backup.cmd
  38. +1 −0  windows/lnkparse/build.cmd
  39. +1 −0  windows/lnkparse/clean.cmd
  40. +3 −0  windows/lnkparse/lnkparse.bpf
  41. +127 −0 windows/lnkparse/lnkparse.bpr
  42. BIN  windows/lnkparse/lnkparse.res
  43. +74 −0 windows/lnkparse/main.cpp
  44. +2 −0  windows/logoff-all/logoff-all.cmd
  45. +57 −0 windows/ntprocesses/ps.c
  46. +65 −0 windows/ntprocesses/ps.cpp
  47. +141 −0 windows/service/actmonitor/actservice.cpp
  48. +1 −0  windows/service/actmonitor/build.cmd
  49. +1 −0  windows/service/actmonitor/clear.cmd
  50. +131 −0 windows/service/actmonitor/example/service.cpp
  51. +3 −0  windows/service/actmonitor/start.cmd
  52. +1 −0  windows/service/actmonitor/stop.cmd
  53. +46 −0 windows/startlist/startlist.php
View
1  devices/xport/backup.cmd
@@ -0,0 +1 @@
+winrar u -v -r -s -m5 -ag-YYYY.MM.DD-HH.MM.SS -x*.rar -x*.zip xporttest
View
4 devices/xport/checkout-bin.cmd
@@ -0,0 +1,4 @@
+upx -9 xporttest.exe
+winrar a -m5 -x*.rar -x*.zip -x*.rar -x*.bmp -m5 xporttest-bin.zip xporttest.exe
+winrar a xporttest-bin.rar xporttest-bin.zip
+del xporttest-bin.zip
View
1  devices/xport/clean.cmd
@@ -0,0 +1 @@
+del *.obj *.~* *.tds *.ddp *.cgl *.err *.dsk *.exe
View
148 devices/xport/formload.cpp
@@ -0,0 +1,148 @@
+#include <typeinfo>
+
+#include <vcl.h>
+#include <Buttons.hpp>
+#include <IniFiles.hpp>
+
+#include <sstream>
+
+#include "formload.h"
+
+void FormLoader::store( TForm* form, AnsiString file )
+{
+ if( !file.Length() )
+ file = ChangeFileExt( Application->ExeName, ".ini" );
+
+ TIniFile* ini = new TIniFile( file );
+
+ try {
+
+ AnsiString section = form->Name;
+
+ ini->WriteString( section, "Left", form->Left );
+ ini->WriteString( section, "Top", form->Top );
+ ini->WriteString( section, "Width", form->Width );
+ ini->WriteString( section, "Height", form->Height );
+
+ for( int i = 0; i < form->ComponentCount; i++ ) {
+ TComponent* c = form->Components[i];
+
+ if( c->Tag == -1 ) continue;
+
+ AnsiString type = typeid( *c ).name();
+ AnsiString name = c->Name;
+ AnsiString value;
+
+ if( type == "TLabeledEdit" ) value = dynamic_cast< TLabeledEdit * >(c)->Text;
+ if( type == "TEdit" ) value = dynamic_cast< TEdit * >(c)->Text;
+ if( type == "TOpenDialog" ) value = dynamic_cast< TOpenDialog * >(c)->FileName;
+ if( type == "TCheckBox" ) value = (int)dynamic_cast< TCheckBox * >(c)->Checked;
+ if( type == "TRadioButton" ) value = (int)dynamic_cast< TRadioButton * >(c)->Checked;
+ if( type == "TSpeedButton" ) value = (int)dynamic_cast< TSpeedButton * >(c)->Down;
+ if( type == "TMenuItem" ) value = (int)dynamic_cast< TMenuItem * >(c)->Checked;
+
+ if( type == "TMemo" ) {
+ TMemo* memo = dynamic_cast< TMemo * >(c);
+ memo->Lines->QuoteChar = '|';
+ value = memo->Lines->DelimitedText;
+ }
+
+ if( !value.Length() ) continue;
+
+ name = name.Delete( name.Length() - type.Length() + 2, type.Length() - 1 );
+
+ ini->WriteString( section, name, value );
+ }
+ } __finally {
+ delete ini;
+ }
+}
+
+void FormLoader::restore( TForm* form, AnsiString file )
+{
+ if( !file.Length() )
+ file = ChangeFileExt( Application->ExeName, ".ini" );
+
+ TIniFile* ini = new TIniFile( file );
+
+ try {
+
+ AnsiString section = form->Name;
+
+ AnsiString window = ini->ReadString( section, "Window", "" );
+
+ form->Left = ini->ReadString( section, "Left", form->Left ).ToInt();
+ form->Top = ini->ReadString( section, "Top", form->Top ).ToInt();
+ form->Width = ini->ReadString( section, "Width", form->Width ).ToInt();
+ form->Height = ini->ReadString( section, "Height", form->Height ).ToInt();
+
+ for( int i = 0; i < form->ComponentCount; i++ ) {
+ TComponent* c = form->Components[i];
+
+ if( c->Tag == -1 ) continue;
+
+ AnsiString type = typeid( *c ).name();
+ AnsiString name = c->Name;
+ AnsiString default_value;
+
+ bool use = false;
+
+ if( type == "TLabeledEdit" ) {
+ default_value = dynamic_cast< TLabeledEdit * >(c)->Text;
+ use = true;
+ }
+ if( type == "TEdit" ) {
+ default_value = dynamic_cast< TEdit * >(c)->Text;
+ use = true;
+ }
+ if( type == "TOpenDialog" ) {
+ default_value = dynamic_cast< TOpenDialog * >(c)->FileName;
+ use = true;
+ }
+ if( type == "TCheckBox" ) {
+ default_value = (int)dynamic_cast< TCheckBox * >(c)->Checked;
+ use = true;
+ }
+ if( type == "TRadioButton" ) {
+ default_value = (int)dynamic_cast< TRadioButton * >(c)->Checked;
+ use = true;
+ }
+ if( type == "TSpeedButton" ) {
+ default_value = (int)dynamic_cast< TSpeedButton * >(c)->Down;
+ use = true;
+ }
+ if( type == "TMenuItem" ) {
+ default_value = (int)dynamic_cast< TMenuItem * >(c)->Checked;
+ use = true;
+ }
+ if( type == "TMemo" ) {
+ TMemo* memo = dynamic_cast< TMemo * >(c);
+ memo->Lines->QuoteChar = '|';
+ default_value = memo->Lines->DelimitedText;
+ use = true;
+ }
+
+ if( !use ) continue;
+
+ name = name.Delete( name.Length() - type.Length() + 2, type.Length() - 1 );
+
+ AnsiString value = ini->ReadString( section, name, default_value );
+
+ if( type == "TLabeledEdit" ) dynamic_cast< TLabeledEdit * >(c)->Text = value;
+ if( type == "TEdit" ) dynamic_cast< TEdit * >(c)->Text = value;
+ if( type == "TOpenDialog" ) dynamic_cast< TOpenDialog * >(c)->FileName = value;
+ if( type == "TCheckBox" ) dynamic_cast< TCheckBox * >(c)->Checked = (bool)value.ToInt();
+ if( type == "TRadioButton" ) (bool)dynamic_cast< TRadioButton * >(c)->Checked = (bool)value.ToInt();
+ if( type == "TSpeedButton" ) (bool)dynamic_cast< TSpeedButton * >(c)->Down = (bool)value.ToInt();
+ if( type == "TMenuItem" ) (bool)dynamic_cast< TMenuItem * >(c)->Checked = (bool)value.ToInt();
+
+ if( type == "TMemo" ) {
+ TMemo* memo = dynamic_cast< TMemo * >(c);
+ memo->Lines->QuoteChar = '|';
+ memo->Lines->DelimitedText = value;
+ }
+ }
+ } __finally {
+ delete ini;
+ }
+}
View
12 devices/xport/formload.h
@@ -0,0 +1,12 @@
+#ifndef _FORMLOAD_H
+#define _FORMLOAD_H
+
+#include <vcl.h>
+
+class FormLoader {
+public:
+ static void FormLoader::store( TForm* form, AnsiString file = "" );
+ static void FormLoader::restore( TForm* form, AnsiString file = "" );
+};
+
+#endif
View
145 devices/xport/main.cpp
@@ -0,0 +1,145 @@
+//---------------------------------------------------------------------------
+
+#include <vcl.h>
+#include <IdTCPClient.hpp>
+#include <ctime>
+#pragma hdrstop
+
+#include "main.h"
+#include "xportgpio.h"
+#include "formload.h"
+//---------------------------------------------------------------------------
+#pragma package(smart_init)
+#pragma link "CPortCtl"
+#pragma link "SHDocVw_OCX"
+#pragma resource "*.dfm"
+TMainForm *MainForm;
+
+// XPortGPIO xportgpio( "localhost", 0x77F0, 50000 );
+XPortGPIO xportgpio( "localhost" );
+
+//---------------------------------------------------------------------------
+__fastcall TMainForm::TMainForm(TComponent* Owner)
+ : TForm(Owner)
+{
+ xportgpio.set_host( XPortIPLabeledEdit->Text );
+}
+//---------------------------------------------------------------------------
+
+void __fastcall TMainForm::Led1GetButtonClick(TObject *Sender)
+{
+ int v = xportgpio.GetCurrentStates();
+ ComLed1->State = v & 1 ? lsOn : lsOff;
+}
+//---------------------------------------------------------------------------
+
+void __fastcall TMainForm::Led2GetButtonClick(TObject *Sender)
+{
+ int v = xportgpio.GetCurrentStates();
+ ComLed2->State = v & 2 ? lsOn : lsOff;
+}
+//---------------------------------------------------------------------------
+
+void __fastcall TMainForm::Led3GetButtonClick(TObject *Sender)
+{
+ int v = xportgpio.GetCurrentStates();
+ ComLed3->State = v & 4 ? lsOn : lsOff;
+}
+//---------------------------------------------------------------------------
+
+void __fastcall TMainForm::Led1OutSpeedButtonClick(TObject *Sender)
+{
+ xportgpio.SetDirections( 1, 1 );
+}
+//---------------------------------------------------------------------------
+
+void __fastcall TMainForm::Led1InSpeedButtonClick(TObject *Sender)
+{
+ xportgpio.SetDirections( 1, 0 );
+}
+//---------------------------------------------------------------------------
+
+void __fastcall TMainForm::Led2OutSpeedButtonClick(TObject *Sender)
+{
+ xportgpio.SetDirections( 2, 1 );
+}
+//---------------------------------------------------------------------------
+
+void __fastcall TMainForm::Led2InSpeedButtonClick(TObject *Sender)
+{
+ xportgpio.SetDirections( 2, 0 );
+}
+//---------------------------------------------------------------------------
+
+void __fastcall TMainForm::Led3OutSpeedButtonClick(TObject *Sender)
+{
+ xportgpio.SetDirections( 4, 1 );
+}
+//---------------------------------------------------------------------------
+
+void __fastcall TMainForm::Led3InSpeedButtonClick(TObject *Sender)
+{
+ xportgpio.SetDirections( 4, 0 );
+}
+//---------------------------------------------------------------------------
+
+void __fastcall TMainForm::Led11ButtonClick(TObject *Sender)
+{
+ xportgpio.SetStates( 1, 1 );
+}
+//---------------------------------------------------------------------------
+
+void __fastcall TMainForm::Led10ButtonClick(TObject *Sender)
+{
+ xportgpio.SetStates( 1, 0 );
+}
+//---------------------------------------------------------------------------
+
+void __fastcall TMainForm::Led21ButtonClick(TObject *Sender)
+{
+ xportgpio.SetStates( 2, 2 );
+}
+//---------------------------------------------------------------------------
+
+void __fastcall TMainForm::Led20ButtonClick(TObject *Sender)
+{
+ xportgpio.SetStates( 2, 0 );
+}
+//---------------------------------------------------------------------------
+
+void __fastcall TMainForm::Led31ButtonClick(TObject *Sender)
+{
+ xportgpio.SetStates( 4, 4 );
+}
+//---------------------------------------------------------------------------
+
+void __fastcall TMainForm::Led30ButtonClick(TObject *Sender)
+{
+ xportgpio.SetStates( 4, 0 );
+}
+//---------------------------------------------------------------------------
+
+void __fastcall TMainForm::XPortIPLabeledEditChange(TObject *Sender)
+{
+ xportgpio.set_host( XPortIPLabeledEdit->Text );
+}
+//---------------------------------------------------------------------------
+
+void __fastcall TMainForm::FormCreate(TObject *Sender)
+{
+ FormLoader::restore(this);
+ CppWebBrowser->Navigate( (BSTR)WideString(CameraURLLabeledEdit->Text) );
+}
+//---------------------------------------------------------------------------
+
+void __fastcall TMainForm::FormDestroy(TObject *Sender)
+{
+ FormLoader::store(this);
+}
+//---------------------------------------------------------------------------
+
+void __fastcall TMainForm::GoButtonClick(TObject *Sender)
+{
+ CppWebBrowser->Navigate( (BSTR)WideString(CameraURLLabeledEdit->Text) );
+}
+//---------------------------------------------------------------------------
View
228 devices/xport/main.dfm
@@ -0,0 +1,228 @@
+object MainForm: TMainForm
+ Left = 192
+ Top = 114
+ Width = 867
+ Height = 799
+ Caption = 'XPort LEDs'
+ Color = clBtnFace
+ Font.Charset = DEFAULT_CHARSET
+ Font.Color = clWindowText
+ Font.Height = -11
+ Font.Name = 'MS Sans Serif'
+ Font.Style = []
+ OldCreateOrder = False
+ OnCreate = FormCreate
+ OnDestroy = FormDestroy
+ PixelsPerInch = 96
+ TextHeight = 13
+ object ComLed1: TComLed
+ Left = 32
+ Top = 40
+ Width = 25
+ Height = 25
+ LedSignal = lsConn
+ Kind = lkGreenLight
+ end
+ object ComLed2: TComLed
+ Left = 32
+ Top = 72
+ Width = 25
+ Height = 25
+ LedSignal = lsConn
+ Kind = lkGreenLight
+ end
+ object ComLed3: TComLed
+ Left = 32
+ Top = 104
+ Width = 25
+ Height = 25
+ LedSignal = lsConn
+ Kind = lkGreenLight
+ end
+ object Led1OutSpeedButton: TSpeedButton
+ Left = 120
+ Top = 40
+ Width = 25
+ Height = 22
+ GroupIndex = 1
+ Down = True
+ Caption = 'Out'
+ OnClick = Led1OutSpeedButtonClick
+ end
+ object Led1InSpeedButton: TSpeedButton
+ Left = 152
+ Top = 40
+ Width = 25
+ Height = 22
+ GroupIndex = 1
+ Caption = 'In'
+ OnClick = Led1InSpeedButtonClick
+ end
+ object Led2OutSpeedButton: TSpeedButton
+ Left = 120
+ Top = 72
+ Width = 25
+ Height = 22
+ GroupIndex = 2
+ Down = True
+ Caption = 'Out'
+ OnClick = Led2OutSpeedButtonClick
+ end
+ object Led2InSpeedButton: TSpeedButton
+ Left = 152
+ Top = 72
+ Width = 23
+ Height = 22
+ GroupIndex = 2
+ Caption = 'In'
+ OnClick = Led2InSpeedButtonClick
+ end
+ object Led3OutSpeedButton: TSpeedButton
+ Left = 120
+ Top = 104
+ Width = 23
+ Height = 22
+ GroupIndex = 3
+ Down = True
+ Caption = 'Out'
+ OnClick = Led3OutSpeedButtonClick
+ end
+ object Led3InSpeedButton: TSpeedButton
+ Left = 152
+ Top = 104
+ Width = 23
+ Height = 22
+ GroupIndex = 3
+ Caption = 'In'
+ OnClick = Led3InSpeedButtonClick
+ end
+ object Led1GetButton: TButton
+ Left = 64
+ Top = 40
+ Width = 41
+ Height = 23
+ Caption = 'Get'
+ TabOrder = 0
+ OnClick = Led1GetButtonClick
+ end
+ object Led2GetButton: TButton
+ Left = 64
+ Top = 72
+ Width = 41
+ Height = 23
+ Caption = 'Get'
+ TabOrder = 1
+ OnClick = Led2GetButtonClick
+ end
+ object Led3GetButton: TButton
+ Left = 64
+ Top = 104
+ Width = 41
+ Height = 23
+ Caption = 'Get'
+ TabOrder = 2
+ OnClick = Led3GetButtonClick
+ end
+ object Led11Button: TButton
+ Left = 192
+ Top = 40
+ Width = 17
+ Height = 23
+ Caption = '1'
+ TabOrder = 3
+ OnClick = Led11ButtonClick
+ end
+ object Led10Button: TButton
+ Left = 216
+ Top = 40
+ Width = 17
+ Height = 23
+ Caption = '0'
+ TabOrder = 4
+ OnClick = Led10ButtonClick
+ end
+ object Led21Button: TButton
+ Left = 192
+ Top = 72
+ Width = 17
+ Height = 23
+ Caption = '1'
+ TabOrder = 5
+ OnClick = Led21ButtonClick
+ end
+ object Led20Button: TButton
+ Left = 216
+ Top = 72
+ Width = 17
+ Height = 23
+ Caption = '0'
+ TabOrder = 6
+ OnClick = Led20ButtonClick
+ end
+ object Led31Button: TButton
+ Left = 192
+ Top = 104
+ Width = 17
+ Height = 23
+ Caption = '1'
+ TabOrder = 7
+ OnClick = Led31ButtonClick
+ end
+ object Led30Button: TButton
+ Left = 216
+ Top = 104
+ Width = 17
+ Height = 23
+ Caption = '0'
+ TabOrder = 8
+ OnClick = Led30ButtonClick
+ end
+ object XPortIPLabeledEdit: TLabeledEdit
+ Left = 80
+ Top = 8
+ Width = 153
+ Height = 21
+ EditLabel.Width = 39
+ EditLabel.Height = 13
+ EditLabel.Caption = 'XPort IP'
+ LabelPosition = lpLeft
+ LabelSpacing = 5
+ TabOrder = 9
+ Text = '127.0.0.1'
+ OnChange = XPortIPLabeledEditChange
+ end
+ object CppWebBrowser: TCppWebBrowser
+ Left = 32
+ Top = 144
+ Width = 800
+ Height = 600
+ TabOrder = 10
+ ControlData = {
+ 4C000000AF520000033E00000000000000000000000000000000000000000000
+ 000000004C000000000000000000000001000000E0D057007335CF11AE690800
+ 2B2E126208000000000000004C0000000114020000000000C000000000000046
+ 8000000000000000000000000000000000000000000000000000000000000000
+ 00000000000000000100000000000000000000000000000000000000}
+ end
+ object CameraURLLabeledEdit: TLabeledEdit
+ Left = 352
+ Top = 8
+ Width = 473
+ Height = 21
+ EditLabel.Width = 61
+ EditLabel.Height = 13
+ EditLabel.Caption = 'Camera URL'
+ LabelPosition = lpLeft
+ LabelSpacing = 5
+ TabOrder = 11
+ end
+ object GoButton: TButton
+ Left = 352
+ Top = 32
+ Width = 75
+ Height = 25
+ Caption = 'View'
+ TabOrder = 12
+ OnClick = GoButtonClick
+ end
+end
View
74 devices/xport/main.h
@@ -0,0 +1,74 @@
+//---------------------------------------------------------------------------
+
+#ifndef mainH
+#define mainH
+//---------------------------------------------------------------------------
+#include <Classes.hpp>
+#include <Controls.hpp>
+#include <StdCtrls.hpp>
+#include <Forms.hpp>
+#include <IdBaseComponent.hpp>
+#include <IdComponent.hpp>
+#include <IdTCPClient.hpp>
+#include <IdTCPConnection.hpp>
+
+#include "xportgpio.h"
+#include "CPortCtl.hpp"
+#include <Buttons.hpp>
+#include <ExtCtrls.hpp>
+#include "SHDocVw_OCX.h"
+#include <OleCtrls.hpp>
+
+//---------------------------------------------------------------------------
+class TMainForm : public TForm
+{
+__published: // IDE-managed Components
+ TComLed *ComLed1;
+ TComLed *ComLed2;
+ TComLed *ComLed3;
+ TSpeedButton *Led1OutSpeedButton;
+ TSpeedButton *Led1InSpeedButton;
+ TSpeedButton *Led2OutSpeedButton;
+ TSpeedButton *Led2InSpeedButton;
+ TSpeedButton *Led3OutSpeedButton;
+ TSpeedButton *Led3InSpeedButton;
+ TButton *Led1GetButton;
+ TButton *Led2GetButton;
+ TButton *Led3GetButton;
+ TButton *Led11Button;
+ TButton *Led10Button;
+ TButton *Led21Button;
+ TButton *Led20Button;
+ TButton *Led31Button;
+ TButton *Led30Button;
+ TLabeledEdit *XPortIPLabeledEdit;
+ TCppWebBrowser *CppWebBrowser;
+ TLabeledEdit *CameraURLLabeledEdit;
+ TButton *GoButton;
+ void __fastcall Led1GetButtonClick(TObject *Sender);
+ void __fastcall Led2GetButtonClick(TObject *Sender);
+ void __fastcall Led3GetButtonClick(TObject *Sender);
+ void __fastcall Led1OutSpeedButtonClick(TObject *Sender);
+ void __fastcall Led1InSpeedButtonClick(TObject *Sender);
+ void __fastcall Led2OutSpeedButtonClick(TObject *Sender);
+ void __fastcall Led2InSpeedButtonClick(TObject *Sender);
+ void __fastcall Led3OutSpeedButtonClick(TObject *Sender);
+ void __fastcall Led3InSpeedButtonClick(TObject *Sender);
+ void __fastcall Led11ButtonClick(TObject *Sender);
+ void __fastcall Led10ButtonClick(TObject *Sender);
+ void __fastcall Led21ButtonClick(TObject *Sender);
+ void __fastcall Led20ButtonClick(TObject *Sender);
+ void __fastcall Led31ButtonClick(TObject *Sender);
+ void __fastcall Led30ButtonClick(TObject *Sender);
+ void __fastcall XPortIPLabeledEditChange(TObject *Sender);
+ void __fastcall FormCreate(TObject *Sender);
+ void __fastcall FormDestroy(TObject *Sender);
+ void __fastcall GoButtonClick(TObject *Sender);
+private: // User declarations
+public: // User declarations
+ __fastcall TMainForm(TComponent* Owner);
+};
+//---------------------------------------------------------------------------
+extern PACKAGE TMainForm *MainForm;
+//---------------------------------------------------------------------------
+#endif
View
126 devices/xport/xportgpio.cpp
@@ -0,0 +1,126 @@
+#include "xportgpio.h"
+
+AnsiString XPortGPIO::hex_dump( const AnsiString& str, const AnsiString& delimiter )
+{
+ AnsiString result = "";
+
+ for( int i = 1; i <= str.Length(); i++ )
+ result += IntToHex( (int)(unsigned char)str[ i ], 2 ) + delimiter;
+
+ return result;
+}
+
+AnsiString XPortGPIO::exec_cmd( const AnsiString& cmd )
+{
+ TIdTCPClient* client = new TIdTCPClient(NULL);
+
+ AnsiString data;
+
+ try {
+ client->Host = host;
+ client->Port = port;
+
+ try {
+ client->Connect();
+ } catch( EIdSocketError& e ) {
+ throw Exception( AnsiString().sprintf( "Unable to connect to %s:%d (0x%X)", client->Host.c_str(), client->Port, client->Port ) );
+ }
+
+ client->WriteBuffer( cmd.data(), cmd.Length(), true );
+
+ std::time_t started = std::time(NULL);
+ while( client->CurrentReadBufferSize() < 1 && std::time(NULL) - started < timeout )
+ client->ReadFromStack( true, timeout );
+
+ if( client->CurrentReadBufferSize() < 1 )
+ throw Exception( "There is no response from XPort device" );
+
+ data = client->ReadString( 1 );
+ if( (unsigned char)data[1] == 0xFF )
+ throw Exception( "XPort device has returned 0xFF (wrong command)" );
+
+ started = std::time(NULL);
+ while( client->CurrentReadBufferSize() < 4 && std::time(NULL) - started < timeout )
+ client->ReadFromStack( true, timeout);
+
+ if( client->CurrentReadBufferSize() < 4 )
+ throw Exception( "There is no response from XPort device" );
+
+ data += client->ReadString( 4 );
+
+ if( data[1] != cmd[1] )
+ throw Exception(
+ AnsiString().sprintf(
+ "Wrong XPort response, first character must be 0x%02X but 0x%02X received [%s]",
+ (int)(unsigned char)cmd[1], (int)(unsigned char)data[1], hex_dump(data).c_str()
+ )
+ );
+
+ } __finally {
+ delete client;
+ }
+
+ return data;
+}
+
+XPortGPIO::Values XPortGPIO::to_values( const AnsiString& str )
+{
+ return
+ (XPortGPIO::Values)(unsigned char)str[1] << 0 |
+ (XPortGPIO::Values)(unsigned char)str[2] << 8 |
+ (XPortGPIO::Values)(unsigned char)str[3] << 16 |
+ (XPortGPIO::Values)(unsigned char)str[4] << 24
+ ;
+}
+
+AnsiString XPortGPIO::from_values( XPortGPIO::Values first, XPortGPIO::Values second )
+{
+ AnsiString v;
+ v.SetLength( 8 );
+
+ v[1] = first >> 0 & 0xff;
+ v[2] = first >> 8 & 0xff;
+ v[3] = first >> 16 & 0xff;
+ v[4] = first >> 24 & 0xff;
+ v[5] = second >> 0 & 0xff;
+ v[6] = second >> 8 & 0xff;
+ v[7] = second >> 16 & 0xff;
+ v[8] = second >> 24 & 0xff;
+
+ return v;
+}
+
+XPortGPIO::Values XPortGPIO::GetFunctions()
+{
+ return to_values( exec_cmd( AnsiString( "\x10\x00\x00\x00\x00\x00\x00\x00\x00", 9 ) ).SubString( 2, 4 ) );
+}
+
+XPortGPIO::Values XPortGPIO::GetDirections()
+{
+ return to_values( exec_cmd( AnsiString( "\x11\x00\x00\x00\x00\x00\x00\x00\x00", 9 ) ).SubString( 2, 4 ) );
+}
+
+XPortGPIO::Values XPortGPIO::GetActiveLevels()
+{
+ return to_values( exec_cmd( AnsiString( "\x12\x00\x00\x00\x00\x00\x00\x00\x00", 9 ) ).SubString( 2, 4 ) );
+}
+
+XPortGPIO::Values XPortGPIO::GetCurrentStates()
+{
+ return to_values( exec_cmd( AnsiString( "\x13\x00\x00\x00\x00\x00\x00\x00\x00", 9 ) ).SubString( 2, 4 ) );
+}
+
+XPortGPIO::Values XPortGPIO::SetDirections( XPortGPIO::Values mask, XPortGPIO::Values directions )
+{
+ return to_values( exec_cmd( AnsiString( "\x19" ) + from_values(mask, directions) ).SubString( 2, 4 ) );
+}
+
+XPortGPIO::Values XPortGPIO::SetActiveLevels( XPortGPIO::Values mask, XPortGPIO::Values levels )
+{
+ return to_values( exec_cmd( AnsiString( "\x1a" ) + from_values(mask, levels) ).SubString( 2, 4 ) );
+}
+
+XPortGPIO::Values XPortGPIO::SetStates( XPortGPIO::Values mask, XPortGPIO::Values states )
+{
+ return to_values( exec_cmd( AnsiString( "\x1b" ) + from_values(mask, states) ).SubString( 2, 4 ) );
+}
View
41 devices/xport/xportgpio.h
@@ -0,0 +1,41 @@
+#ifndef _XPORTGPIO_H
+#define _XPORTGPIO_H
+
+#include <vcl.h>
+#include <IdTCPClient.hpp>
+
+#include <ctime>
+
+class XPortGPIO {
+public:
+ typedef unsigned long Values;
+private:
+ AnsiString host;
+ int port;
+ int timeout;
+
+ AnsiString hex_dump( const AnsiString& str, const AnsiString& delimiter = "" );
+
+ AnsiString exec_cmd( const AnsiString& cmd );
+
+ Values to_values( const AnsiString& str );
+ AnsiString from_values( Values first, Values second );
+
+public:
+ XPortGPIO( const AnsiString& a_host, int a_port = 0x77F0, int a_timeout = 5 ) :
+ host( a_host ), port( a_port ), timeout( a_timeout )
+ {}
+
+ void set_host( const AnsiString& a_host ) { host = a_host; }
+ void set_port( int a_port ) { port = a_port; }
+
+ Values GetFunctions();
+ Values GetDirections();
+ Values GetActiveLevels();
+ Values GetCurrentStates();
+ Values SetDirections( Values mask, Values directions );
+ Values SetActiveLevels( Values mask, Values levels );
+ Values SetStates( Values mask, Values states );
+};
+
+#endif
View
127 devices/xport/xporttest.bpr
@@ -0,0 +1,127 @@
+<?xml version='1.0' encoding='utf-8' ?>
+<!-- C++Builder XML Project -->
+<PROJECT>
+ <MACROS>
+ <VERSION value="BCB.06.00"/>
+ <PROJECT value="xporttest.exe"/>
+ <OBJFILES value="xporttest.obj main.obj xportgpio.obj formload.obj"/>
+ <RESFILES value="xporttest.res"/>
+ <DEFFILE value=""/>
+ <RESDEPEN value="$(RESFILES) main.dfm"/>
+ <LIBFILES value=""/>
+ <LIBRARIES value="bcbie.lib cportlibcb6.lib indy.lib rtl.lib vcl.lib"/>
+ <SPARELIBS value="vcl.lib rtl.lib indy.lib cportlibcb6.lib bcbie.lib"/>
+ <PACKAGES value="vcl.bpi rtl.bpi vclx.bpi bcbsmp.bpi dbrtl.bpi adortl.bpi vcldb.bpi
+ qrpt.bpi bdertl.bpi vcldbx.bpi dsnap.bpi cds.bpi bdecds.bpi teeui.bpi
+ teedb.bpi tee.bpi teeqr.bpi ibxpress.bpi visualclx.bpi visualdbclx.bpi
+ vclie.bpi xmlrtl.bpi inet.bpi inetdbbde.bpi inetdbxpress.bpi inetdb.bpi
+ nmfast.bpi bcbie.bpi soaprtl.bpi dclocx.bpi dbexpress.bpi dbxcds.bpi
+ indy.bpi bcb2kaxserver.bpi PKIECTRLc6.bpi PKIEDBc6.bpi"/>
+ <PATHCPP value=".;"/>
+ <PATHPAS value=".;"/>
+ <PATHRC value=".;"/>
+ <PATHASM value=".;"/>
+ <DEBUGLIBPATH value="$(BCB)\lib\debug"/>
+ <RELEASELIBPATH value="$(BCB)\lib\release"/>
+ <LINKER value="ilink32"/>
+ <USERDEFINES value="_DEBUG"/>
+ <SYSDEFINES value="NO_STRICT"/>
+ <MAINSOURCE value="xporttest.cpp"/>
+ <INCLUDEPATH value="$(BCB)\include;$(BCB)\include\vcl;"/>
+ <LIBPATH value="$(BCB)\lib\obj;$(BCB)\lib;"/>
+ <WARNINGS value="-w-par"/>
+ <OTHERFILES value=""/>
+ </MACROS>
+ <OPTIONS>
+ <CFLAG1 value="-Od -H=$(BCB)\lib\vcl60.csm -Hc -Vx -Ve -X- -r- -a8 -b- -k -y -v -vi- -c
+ -tW -tWM"/>
+ <PFLAGS value="-$YD -$W -$O- -$A8 -v -JPHNE -M"/>
+ <RFLAGS value=""/>
+ <AFLAGS value="/mx /w2 /zd"/>
+ <LFLAGS value="-D&quot;&quot; -aa -Tpe -x -Gn -v"/>
+ <OTHERFILES value=""/>
+ </OPTIONS>
+ <LINKER>
+ <ALLOBJ value="c0w32.obj sysinit.obj $(OBJFILES)"/>
+ <ALLRES value="$(RESFILES)"/>
+ <ALLLIB value="$(LIBFILES) $(LIBRARIES) import32.lib cp32mt.lib"/>
+ <OTHERFILES value=""/>
+ </LINKER>
+ <FILELIST>
+ <FILE FILENAME="xporttest.res" FORMNAME="" UNITNAME="xporttest.res" CONTAINERID="ResTool" DESIGNCLASS="" LOCALCOMMAND=""/>
+ <FILE FILENAME="xporttest.cpp" FORMNAME="" UNITNAME="xporttest" CONTAINERID="CCompiler" DESIGNCLASS="" LOCALCOMMAND=""/>
+ <FILE FILENAME="main.cpp" FORMNAME="MainForm" UNITNAME="main" CONTAINERID="CCompiler" DESIGNCLASS="" LOCALCOMMAND=""/>
+ <FILE FILENAME="xportgpio.cpp" FORMNAME="" UNITNAME="xportgpio" CONTAINERID="CCompiler" DESIGNCLASS="" LOCALCOMMAND=""/>
+ <FILE FILENAME="formload.cpp" FORMNAME="" UNITNAME="formload" CONTAINERID="CCompiler" DESIGNCLASS="" LOCALCOMMAND=""/>
+ </FILELIST>
+ <BUILDTOOLS>
+ </BUILDTOOLS>
+
+ <IDEOPTIONS>
+[Version Info]
+IncludeVerInfo=0
+AutoIncBuild=0
+MajorVer=1
+MinorVer=0
+Release=0
+Build=0
+Debug=0
+PreRelease=0
+Special=0
+Private=0
+DLL=0
+Locale=1049
+CodePage=1251
+
+[Version Info Keys]
+CompanyName=
+FileDescription=
+FileVersion=1.0.0.0
+InternalName=
+LegalCopyright=
+LegalTrademarks=
+OriginalFilename=
+ProductName=
+ProductVersion=1.0.0.0
+Comments=
+
+[HistoryLists\hlIncludePath]
+Count=0
+
+[HistoryLists\hlLibraryPath]
+Count=0
+
+[HistoryLists\hlDebugSourcePath]
+Count=1
+Item0=$(BCB)\source\vcl
+
+[HistoryLists\hlConditionals]
+Count=1
+Item0=_DEBUG
+
+[Debugging]
+DebugSourceDirs=$(BCB)\source\vcl
+
+[Parameters]
+RunParams=
+Launcher=
+UseLauncher=0
+DebugCWD=
+HostApplication=
+RemoteHost=
+RemotePath=
+RemoteLauncher=
+RemoteCWD=
+RemoteDebug=0
+
+[Compiler]
+ShowInfoMsgs=0
+LinkDebugVcl=0
+LinkCGLIB=0
+
+[Language]
+ActiveLang=
+ProjectLang=
+RootDir=
+ </IDEOPTIONS>
+</PROJECT>
View
33 devices/xport/xporttest.cpp
@@ -0,0 +1,33 @@
+//---------------------------------------------------------------------------
+
+#include <vcl.h>
+#pragma hdrstop
+//---------------------------------------------------------------------------
+USEFORM("main.cpp", MainForm);
+//---------------------------------------------------------------------------
+WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
+{
+ try
+ {
+ Application->Initialize();
+ Application->CreateForm(__classid(TMainForm), &MainForm);
+ Application->Run();
+ }
+ catch (Exception &exception)
+ {
+ Application->ShowException(&exception);
+ }
+ catch (...)
+ {
+ try
+ {
+ throw Exception("");
+ }
+ catch (Exception &exception)
+ {
+ Application->ShowException(&exception);
+ }
+ }
+ return 0;
+}
+//---------------------------------------------------------------------------
View
13 devices/xport/xporttest.ini
@@ -0,0 +1,13 @@
+[MainForm]
+Left=231
+Top=142
+Width=867
+Height=798
+Led1Out=1
+Led1In=0
+Led2Out=1
+Led2In=0
+Led3Out=1
+Led3In=0
+XPortIP=localhost
+CameraURL=aha.ru
View
BIN  devices/xport/xporttest.res
Binary file not shown
View
7 languages/assembler/i8080/as-test/Makefile
@@ -0,0 +1,7 @@
+all:
+ asl test.asm
+ p2bin -r 0x-0x test.p
+
+clean:
+ -rm test.p test.bin
+
View
16 languages/assembler/i8080/as-test/test.asm
@@ -0,0 +1,16 @@
+ cpu 8080
+ org 0
+
+monitor equ 0f86ch
+
+msg macro addr
+ push h
+ lxi h, addr
+ call 0f816h
+ pop h
+ endm
+
+ msg hello_msg
+ jmp monitor
+
+hello_msg db "HELLO!", 0
View
41 languages/c++/fibonacci/fibo_sequence.cpp
@@ -0,0 +1,41 @@
+#include <iostream>
+#include <cstdlib>
+
+void iterative(int N) {
+ int a = 1;
+ int b = 1;
+ std::cout << a << " " << b << " ";
+ for (int i = 0; i < N; i++) {
+ int c = a + b;
+ std::cout << c << " ";
+ a = b;
+ b = c;
+ }
+ std::cout << std::endl;
+}
+
+// f(x) = f(x - 2) + f(x - 1)
+
+void do_recursive(int N, int i, int a, int b) {
+ std::cout << b << " ";
+ if (i < N)
+ do_recursive(N, i + 1, b, a + b);
+}
+
+void recursive(int N) {
+ int a = 1, b = 1;
+ std::cout << a << " ";
+ do_recursive(N, 0, a, b);
+}
+
+int main(int argc, char* argv[]) {
+ int N = argc > 1 ? std::atoi(argv[1]) : 10;
+ std::cout << "N = " << N << std::endl;
+
+ std::cout << "Iterative method" << std::endl;
+ iterative(N);
+
+ std::cout << "Recursive method" << std::endl;
+ recursive(N);
+ return 0;
+}
View
45 languages/php/ucs2/hex.php
@@ -0,0 +1,45 @@
+<?php
+
+function hex_dump( $str )
+{
+ $result = unpack( "H" . strlen( $str )*2 . "dump", $str );
+ return strtoupper( $result[ "dump" ] );
+}
+
+function pack_hex( $str )
+{
+ return pack( "H*", strtoupper( preg_replace( "/[^\dABCDEF]/", "", $str ) ) );
+}
+
+function smart_hex_dump( $data )
+{
+ $dump = false;
+
+ $result = "";
+
+ for( $i = 0; $i < strlen( $data ); $i++ ) {
+ $ch = ord( $data{ $i } );
+
+ if( $dump ) {
+ if( $ch < 0x20 || $ch > 0x7f || chr( $ch ) == ">" || chr( $ch ) == "<" )
+ $result .= sprintf( "%02X", $ch );
+ else {
+ $result .= ">" . chr( $ch );
+ $dump = false;
+ }
+ } else {
+ if( $ch < 0x20 || $ch > 0x7f || chr( $ch ) == ">" || chr( $ch ) == "<" ) {
+ $result .= "<" . sprintf( "%02X", $ch );
+ $dump = true;
+ } else
+ $result .= chr( $ch );
+ }
+ }
+
+ if( $dump )
+ $result .= ">";
+
+ return $result;
+}
+
+?>
View
46 languages/php/ucs2/intconv.php
@@ -0,0 +1,46 @@
+<?php
+
+function str2int( $str, $endian = "little" )
+{
+ $result = 0;
+
+ if( $endian == "big" )
+ for( $i = 0; $i < strlen( $str ); $i++ )
+ $result = ( $result << 8 ) | ( ord( $str{ $i } ) & 0xff );
+ else
+ for( $i = strlen( $str ) - 1; $i >= 0 ; $i-- )
+ $result = ( $result << 8 ) | ( ord( $str{ $i } ) & 0xff );
+
+ return $result;
+}
+
+function extract_int( $str, &$i )
+{
+ $result = str2int( substr( $str, $i, 4 ) );
+
+ $i += 4;
+
+ return $result;
+}
+
+function extract_short( $str, &$i )
+{
+ $result = str2int( substr( $str, $i, 2 ) );
+
+ $i += 2;
+
+ return $result;
+}
+
+function extract_string( $str, &$i )
+{
+ $sz = extract_int( $str, $i ) * 2;
+
+ $result = substr( $str, $i, $sz );
+
+ $i += $sz;
+
+ return decode_ucs2_string( $result, "d" );
+}
+
+?>
View
77 languages/php/ucs2/ucs2.php
@@ -0,0 +1,77 @@
+<?php
+
+require 'hex.php';
+
+function decode_ucs2( $ch, $codepage = "w", $endian = "little" )
+{
+ $ucs2_cyr_cp1251_table =
+ // 0123456789ABCDEF
+ " ¨ " . // 0
+ "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏ" . // 1
+ "ÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞß" . // 2
+ "àáâãäåæçèéêëìíîï" . // 3
+ "ðñòóôõö÷øùúûüýþÿ" . // 4
+ " ¸ " . // 5
+ " " . // 6
+ " " . // 7
+ " " . // 8
+ " " . // 9
+ " " . // A
+ " " . // B
+ " " . // C
+ " " . // D
+ " " . // E
+ " "; // F
+
+ $ucs2_cyr_dos_table =
+ // 0123456789ABCDEF
+ " ð " . // 0
+ "€‚ƒ„…†‡ˆ‰Š‹ŒŽ" . // 1
+ "‘’“”•–—˜™š›œžŸ" . // 2
+ " ¡¢£¤¥¦§¨©ª«¬­®¯" . // 3
+ "àáâãäåæçèéêëìíîï" . // 4
+ " ñ " . // 5
+ " " . // 6
+ " " . // 7
+ " " . // 8
+ " " . // 9
+ " " . // A
+ " " . // B
+ " " . // C
+ " " . // D
+ " " . // E
+ " "; // F
+
+ if( strlen( $ch ) < 2 ) return $ch;
+
+ if( $endian == "big" ) {
+ $page = $ch{ 0 };
+ $code = $ch{ 1 };
+ } else {
+ $page = $ch{ 1 };
+ $code = $ch{ 0 };
+ }
+
+ if( $page == chr( 0x00 ) ) return $code;
+
+ $table = $codepage == "w" ? $ucs2_cyr_cp1251_table : $ucs2_cyr_dos_table;
+
+ if( $page == chr( 0x04 ) ) {
+ $ch = $table[ ord( $code ) & 0xff ];
+ return $ch == " " ? '?' : $ch;
+ }
+
+ return "<" . hex_dump( $ch ) . ">";
+}
+
+function decode_ucs2_string( $str, $codepage = "w", $endian = "little" )
+{
+ $result = "";
+
+ for( $i = 0; $i < strlen( $str ); $i += 2 )
+ $result .= decode_ucs2( substr( $str, $i, 2 ), $codepage, $endian );
+
+ return $result;
+}
+
+?>
View
18 languages/python/serial/modem.py
@@ -0,0 +1,18 @@
+import serial
+
+def exec_cmd(port, cmd):
+ print "Exec '%s' command" % cmd
+ port.write(cmd + "\r")
+ while 1:
+ line = port.readline()
+ print line
+
+ if line.startswith("OK") or line.startswith("ERROR"):
+ break
+
+port = serial.Serial('COM3', timeout=2)
+print port
+
+exec_cmd( port, "ati4" )
+
+port.close()
View
23 languages/python/threads/threads.py
@@ -0,0 +1,23 @@
+import random
+import time
+import thread
+
+class MyThread:
+ def Start(self, index):
+ thread.start_new_thread(self.Run, ())
+ self.index = index
+
+ def Run(self):
+ i = 1
+ while 1:
+ print "Thread ", self.index, ": ", i
+ i = i + 1
+ sleeptime = (random.random() * 2) + 0.5
+ time.sleep(sleeptime/4)
+
+t1 = MyThread()
+t1.Start(1)
+
+MyThread().Start(2)
+
+while 1: pass
View
0  languages/python/begemot/begemon-convert.py → languages/python/xls/begemon-convert.py
File renamed without changes
View
10 wince/hello/hello.c
@@ -0,0 +1,10 @@
+#include <windows.h>
+#include <conio.h>
+
+int main( DWORD argc, LPTSTR argv[] )
+{
+ puts( "TEST\n" );
+ Sleep(5000);
+ return 1;
+}
+
View
6 wince/hello/hello1.c
@@ -0,0 +1,6 @@
+#include <windows.h>
+
+int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow)
+{
+ MessageBoxW(0, L"Test message!", L"HELLO!", 0);
+}
View
6 wince/hello/hello2.c
@@ -0,0 +1,6 @@
+#include <windows.h>
+
+int main()
+{
+ MessageBoxW(0, L"Test message!", L"HELLO!", 0);
+}
View
75 wince/hello/simple_window.c
@@ -0,0 +1,75 @@
+#include <windows.h>
+
+const char g_szClassName[] = "myWindowClass";
+
+// Step 4: the Window Procedure
+LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
+{
+ switch(msg)
+ {
+ case WM_CLOSE:
+ DestroyWindow(hwnd);
+ break;
+ case WM_DESTROY:
+ PostQuitMessage(0);
+ break;
+ default:
+ return DefWindowProc(hwnd, msg, wParam, lParam);
+ }
+ return 0;
+}
+
+int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow)
+{
+ WNDCLASSEX wc;
+ HWND hwnd;
+ MSG Msg;
+
+ //Step 1: Registering the Window Class
+ wc.cbSize = sizeof(WNDCLASSEX);
+ wc.style = 0;
+ wc.lpfnWndProc = WndProc;
+ wc.cbClsExtra = 0;
+ wc.cbWndExtra = 0;
+ wc.hInstance = hInstance;
+ wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
+ wc.hCursor = LoadCursor(NULL, IDC_ARROW);
+ wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
+ wc.lpszMenuName = NULL;
+ wc.lpszClassName = g_szClassName;
+ wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
+
+ if(!RegisterClassEx(&wc))
+ {
+ MessageBox(NULL, "Window Registration Failed!", "Error!",
+ MB_ICONEXCLAMATION | MB_OK);
+ return 0;
+ }
+
+ // Step 2: Creating the Window
+ hwnd = CreateWindowEx(
+ WS_EX_CLIENTEDGE,
+ g_szClassName,
+ "The title of my window",
+ WS_OVERLAPPEDWINDOW,
+ CW_USEDEFAULT, CW_USEDEFAULT, 240, 120,
+ NULL, NULL, hInstance, NULL);
+
+ if(hwnd == NULL)
+ {
+ MessageBox(NULL, "Window Creation Failed!", "Error!",
+ MB_ICONEXCLAMATION | MB_OK);
+ return 0;
+ }
+
+ ShowWindow(hwnd, nCmdShow);
+ UpdateWindow(hwnd);
+
+ // Step 3: The Message Loop
+ while(GetMessage(&Msg, NULL, 0, 0) > 0)
+ {
+ TranslateMessage(&Msg);
+ DispatchMessage(&Msg);
+ }
+ return Msg.wParam;
+}
View
1  windows/joystick/backup.cmd
@@ -0,0 +1 @@
+winrar u -v -r -s -m5 -ag-YYYY.MM.DD-HH.MM.SS -x*.rar -x*.zip joytest
View
4 windows/joystick/checkout-bin.cmd
@@ -0,0 +1,4 @@
+upx -9 joytest.exe
+winrar a -m5 -x*.rar -x*.zip -x*.rar -x*.bmp -m5 joytest-bin.zip joytest.exe
+winrar a joytest-bin.rar joytest-bin.zip
+del joytest-bin.zip
View
1  windows/joystick/clean.cmd
@@ -0,0 +1 @@
+del *.obj *.~* *.tds *.ddp *.cgl *.err *.dsk *.exe
View
129 windows/joystick/joytest.bpr
@@ -0,0 +1,129 @@
+<?xml version='1.0' encoding='utf-8' ?>
+<!-- C++Builder XML Project -->
+<PROJECT>
+ <MACROS>
+ <VERSION value="BCB.06.00"/>
+ <PROJECT value="joytest.exe"/>
+ <OBJFILES value="joytest.obj main.obj"/>
+ <RESFILES value="joytest.res"/>
+ <DEFFILE value=""/>
+ <RESDEPEN value="$(RESFILES) main.dfm"/>
+ <LIBFILES value=""/>
+ <LIBRARIES value="rtl.lib vcl.lib"/>
+ <SPARELIBS value="vcl.lib rtl.lib"/>
+ <PACKAGES value="vcl.bpi rtl.bpi vclx.bpi bcbsmp.bpi dbrtl.bpi adortl.bpi vcldb.bpi
+ qrpt.bpi bdertl.bpi vcldbx.bpi dsnap.bpi cds.bpi bdecds.bpi teeui.bpi
+ teedb.bpi tee.bpi teeqr.bpi ibxpress.bpi visualclx.bpi visualdbclx.bpi
+ vclie.bpi xmlrtl.bpi inet.bpi inetdbbde.bpi inetdbxpress.bpi inetdb.bpi
+ nmfast.bpi bcbie.bpi soaprtl.bpi dclocx.bpi dbexpress.bpi dbxcds.bpi
+ indy.bpi bcb2kaxserver.bpi ostvcl.bpi PKIECTRLc6.bpi PKIEDBc6.bpi
+ CPortLibCB6.bpi"/>
+ <PATHCPP value=".;"/>
+ <PATHPAS value=".;"/>
+ <PATHRC value=".;"/>
+ <PATHASM value=".;"/>
+ <DEBUGLIBPATH value="$(BCB)\lib\debug"/>
+ <RELEASELIBPATH value="$(BCB)\lib\release"/>
+ <LINKER value="ilink32"/>
+ <USERDEFINES value="_DEBUG"/>
+ <SYSDEFINES value="NO_STRICT"/>
+ <MAINSOURCE value="joytest.cpp"/>
+ <INCLUDEPATH value="$(BCB)\include;$(BCB)\include\vcl"/>
+ <LIBPATH value="$(BCB)\lib\obj;$(BCB)\lib;C:\lib\tpapro-4.06\source"/>
+ <WARNINGS value="-w-par"/>
+ <OTHERFILES value=""/>
+ </MACROS>
+ <OPTIONS>
+ <CFLAG1 value="-Od -H=$(BCB)\lib\vcl60.csm -Hc -Vx -Ve -X- -r- -a8 -b- -k -y -v -vi- -c
+ -tW -tWM"/>
+ <PFLAGS value="-$YD -$W -$O- -$A8 -v -JPHNE -M"/>
+ <RFLAGS value=""/>
+ <AFLAGS value="/mx /w2 /zd"/>
+ <LFLAGS value="-D&quot;&quot; -aa -Tpe -x -Gn -v"/>
+ <OTHERFILES value=""/>
+ </OPTIONS>
+ <LINKER>
+ <ALLOBJ value="c0w32.obj sysinit.obj $(OBJFILES)"/>
+ <ALLRES value="$(RESFILES)"/>
+ <ALLLIB value="$(LIBFILES) $(LIBRARIES) import32.lib cp32mt.lib"/>
+ <OTHERFILES value=""/>
+ </LINKER>
+ <FILELIST>
+ <FILE FILENAME="joytest.res" FORMNAME="" UNITNAME="joytest.res" CONTAINERID="ResTool" DESIGNCLASS="" LOCALCOMMAND=""/>
+ <FILE FILENAME="joytest.cpp" FORMNAME="" UNITNAME="joytest" CONTAINERID="CCompiler" DESIGNCLASS="" LOCALCOMMAND=""/>
+ <FILE FILENAME="main.cpp" FORMNAME="MainForm" UNITNAME="main" CONTAINERID="CCompiler" DESIGNCLASS="" LOCALCOMMAND=""/>
+ </FILELIST>
+ <BUILDTOOLS>
+ </BUILDTOOLS>
+
+ <IDEOPTIONS>
+[Version Info]
+IncludeVerInfo=0
+AutoIncBuild=0
+MajorVer=1
+MinorVer=0
+Release=0
+Build=0
+Debug=0
+PreRelease=0
+Special=0
+Private=0
+DLL=0
+Locale=1049
+CodePage=1251
+
+[Version Info Keys]
+CompanyName=
+FileDescription=
+FileVersion=1.0.0.0
+InternalName=
+LegalCopyright=
+LegalTrademarks=
+OriginalFilename=
+ProductName=
+ProductVersion=1.0.0.0
+Comments=
+
+[HistoryLists\hlIncludePath]
+Count=1
+Item0=$(BCB)\include;$(BCB)\include\vcl
+
+[HistoryLists\hlLibraryPath]
+Count=2
+Item0=$(BCB)\lib\obj;$(BCB)\lib;C:\lib\tpapro-4.06\source
+Item1=$(BCB)\lib\obj;$(BCB)\lib
+
+[HistoryLists\hlDebugSourcePath]
+Count=1
+Item0=$(BCB)\source\vcl
+
+[HistoryLists\hlConditionals]
+Count=1
+Item0=_DEBUG
+
+[Debugging]
+DebugSourceDirs=$(BCB)\source\vcl
+
+[Parameters]
+RunParams=
+Launcher=
+UseLauncher=0
+DebugCWD=
+HostApplication=
+RemoteHost=
+RemotePath=
+RemoteLauncher=
+RemoteCWD=
+RemoteDebug=0
+
+[Compiler]
+ShowInfoMsgs=0
+LinkDebugVcl=0
+LinkCGLIB=0
+
+[Language]
+ActiveLang=
+ProjectLang=
+RootDir=
+ </IDEOPTIONS>
+</PROJECT>
View
33 windows/joystick/joytest.cpp
@@ -0,0 +1,33 @@
+//---------------------------------------------------------------------------
+
+#include <vcl.h>
+#pragma hdrstop
+//---------------------------------------------------------------------------
+USEFORM("main.cpp", MainForm);
+//---------------------------------------------------------------------------
+WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
+{
+ try
+ {
+ Application->Initialize();
+ Application->CreateForm(__classid(TMainForm), &MainForm);
+ Application->Run();
+ }
+ catch (Exception &exception)
+ {
+ Application->ShowException(&exception);
+ }
+ catch (...)
+ {
+ try
+ {
+ throw Exception("");
+ }
+ catch (Exception &exception)
+ {
+ Application->ShowException(&exception);
+ }
+ }
+ return 0;
+}
+//---------------------------------------------------------------------------
View
BIN  windows/joystick/joytest.res
Binary file not shown
View
55 windows/joystick/main.cpp
@@ -0,0 +1,55 @@
+//---------------------------------------------------------------------------
+
+#include <vcl.h>
+#include <mmsystem.h>
+#pragma hdrstop
+
+#include "main.h"
+//---------------------------------------------------------------------------
+#pragma package(smart_init)
+#pragma resource "*.dfm"
+TMainForm *MainForm;
+//---------------------------------------------------------------------------
+__fastcall TMainForm::TMainForm(TComponent* Owner)
+ : TForm(Owner)
+{
+}
+//---------------------------------------------------------------------------
+void __fastcall TMainForm::FormCreate(TObject *Sender)
+{
+ int n = joyGetNumDevs();
+ if( n == 0 ) {
+ Application->MessageBox( "Джойстиков в системе не обнаружено", "Ошибка", MB_OK );
+ Application->Terminate();
+ }
+
+ for( int i = 0; i < n; i++ ) {
+ JOYINFO jiInfo;
+ if( joyGetPos( i, &jiInfo) == JOYERR_NOERROR /* != JOYERR_UNPLUGGED */ ) {
+ LogMemo->Lines->Add( AnsiString("Джойстик ") + i );
+ JoyIndexEdit->Text = i;
+ }
+ }
+
+ if( LogMemo->Lines->Count == 0 ) {
+ Application->MessageBox( "Джойстиков в системе не обнаружено", "Ошибка", MB_OK );
+ Application->Terminate();
+ }
+}
+//---------------------------------------------------------------------------
+void __fastcall TMainForm::TimerTimer(TObject *Sender)
+{
+ JOYINFO jiInfo;
+ int joy = JoyIndexEdit->Text.ToIntDef( 0 );
+ if( joyGetPos( joy, &jiInfo ) == JOYERR_NOERROR ) {
+ SpeedButton1->Down = jiInfo.wButtons & JOY_BUTTON1;
+ SpeedButton2->Down = jiInfo.wButtons & JOY_BUTTON2;
+ SpeedButton3->Down = jiInfo.wButtons & JOY_BUTTON3;
+ SpeedButton4->Down = jiInfo.wButtons & JOY_BUTTON4;
+ XLabeledEdit->Text = jiInfo.wXpos;
+ YLabeledEdit->Text = jiInfo.wYpos;
+ ZLabeledEdit->Text = jiInfo.wZpos;
+ }
+}
+//---------------------------------------------------------------------------
+
View
95 windows/joystick/main.dfm
@@ -0,0 +1,95 @@
+object MainForm: TMainForm
+ Left = 302
+ Top = 212
+ Width = 346
+ Height = 288
+ Color = clBtnFace
+ Font.Charset = DEFAULT_CHARSET
+ Font.Color = clWindowText
+ Font.Height = -11
+ Font.Name = 'MS Sans Serif'
+ Font.Style = []
+ OldCreateOrder = False
+ OnCreate = FormCreate
+ PixelsPerInch = 96
+ TextHeight = 13
+ object SpeedButton1: TSpeedButton
+ Left = 84
+ Top = 48
+ Width = 69
+ Height = 22
+ end
+ object SpeedButton2: TSpeedButton
+ Left = 8
+ Top = 48
+ Width = 69
+ Height = 22
+ end
+ object SpeedButton3: TSpeedButton
+ Left = 160
+ Top = 48
+ Width = 69
+ Height = 22
+ end
+ object SpeedButton4: TSpeedButton
+ Left = 236
+ Top = 48
+ Width = 69
+ Height = 22
+ end
+ object XLabeledEdit: TLabeledEdit
+ Left = 24
+ Top = 12
+ Width = 65
+ Height = 21
+ EditLabel.Width = 7
+ EditLabel.Height = 13
+ EditLabel.Caption = 'X'
+ LabelPosition = lpLeft
+ LabelSpacing = 10
+ TabOrder = 0
+ end
+ object YLabeledEdit: TLabeledEdit
+ Left = 108
+ Top = 12
+ Width = 65
+ Height = 21
+ EditLabel.Width = 7
+ EditLabel.Height = 13
+ EditLabel.Caption = 'Y'
+ LabelPosition = lpLeft
+ LabelSpacing = 10
+ TabOrder = 1
+ end
+ object ZLabeledEdit: TLabeledEdit
+ Left = 200
+ Top = 12
+ Width = 65
+ Height = 21
+ EditLabel.Width = 7
+ EditLabel.Height = 13
+ EditLabel.Caption = 'Z'
+ LabelPosition = lpLeft
+ LabelSpacing = 10
+ TabOrder = 2
+ end
+ object LogMemo: TMemo
+ Left = 8
+ Top = 136
+ Width = 281
+ Height = 101
+ TabOrder = 3
+ end
+ object JoyIndexEdit: TEdit
+ Left = 12
+ Top = 100
+ Width = 121
+ Height = 21
+ TabOrder = 4
+ end
+ object Timer: TTimer
+ OnTimer = TimerTimer
+ Left = 224
+ Top = 80
+ end
+end
View
35 windows/joystick/main.h
@@ -0,0 +1,35 @@
+//---------------------------------------------------------------------------
+
+#ifndef mainH
+#define mainH
+//---------------------------------------------------------------------------
+#include <Classes.hpp>
+#include <Controls.hpp>
+#include <StdCtrls.hpp>
+#include <Forms.hpp>
+#include <Buttons.hpp>
+#include <ExtCtrls.hpp>
+//---------------------------------------------------------------------------
+class TMainForm : public TForm
+{
+__published: // IDE-managed Components
+ TLabeledEdit *XLabeledEdit;
+ TLabeledEdit *YLabeledEdit;
+ TLabeledEdit *ZLabeledEdit;
+ TSpeedButton *SpeedButton1;
+ TSpeedButton *SpeedButton2;
+ TSpeedButton *SpeedButton3;
+ TSpeedButton *SpeedButton4;
+ TTimer *Timer;
+ TMemo *LogMemo;
+ TEdit *JoyIndexEdit;
+ void __fastcall FormCreate(TObject *Sender);
+ void __fastcall TimerTimer(TObject *Sender);
+private: // User declarations
+public: // User declarations
+ __fastcall TMainForm(TComponent* Owner);
+};
+//---------------------------------------------------------------------------
+extern PACKAGE TMainForm *MainForm;
+//---------------------------------------------------------------------------
+#endif
View
1  windows/lnkparse/backup.cmd
@@ -0,0 +1 @@
+winrar a -v -r -ag-YYYY.MM.DD-HH.MM.SS -x*.rar -x*.zip lnkparse
View
1  windows/lnkparse/build.cmd
@@ -0,0 +1 @@
+bcb /b lnkparse.bpr
View
1  windows/lnkparse/clean.cmd
@@ -0,0 +1 @@
+del /S *.obj *.exe *.tds *.~* *.cgl *.dcu *.~* *.dsk *.ddp *.dll *.exe *.fmt *.err
View
3  windows/lnkparse/lnkparse.bpf
@@ -0,0 +1,3 @@
+This file is used by the project manager only and should be treated like the project file
+
+ main
View
127 windows/lnkparse/lnkparse.bpr
@@ -0,0 +1,127 @@
+<?xml version='1.0' encoding='utf-8' ?>
+<!-- C++Builder XML Project -->
+<PROJECT>
+ <MACROS>
+ <VERSION value="BCB.06.00"/>
+ <PROJECT value="lnkparse.exe"/>
+ <OBJFILES value="main.obj"/>
+ <RESFILES value="lnkparse.res"/>
+ <DEFFILE value=""/>
+ <RESDEPEN value="$(RESFILES)"/>
+ <LIBFILES value=""/>
+ <LIBRARIES value="rtl.lib"/>
+ <SPARELIBS value="rtl.lib"/>
+ <PACKAGES value="vcl.bpi rtl.bpi vclx.bpi bcbsmp.bpi dbrtl.bpi adortl.bpi vcldb.bpi
+ qrpt.bpi bdertl.bpi vcldbx.bpi dsnap.bpi cds.bpi bdecds.bpi teeui.bpi
+ teedb.bpi tee.bpi teeqr.bpi ibxpress.bpi visualclx.bpi visualdbclx.bpi
+ vclie.bpi xmlrtl.bpi inet.bpi inetdbbde.bpi inetdbxpress.bpi inetdb.bpi
+ nmfast.bpi bcbie.bpi soaprtl.bpi dclocx.bpi dbexpress.bpi dbxcds.bpi
+ indy.bpi bcb2kaxserver.bpi"/>
+ <PATHCPP value=".;"/>
+ <PATHPAS value=".;"/>
+ <PATHRC value=".;"/>
+ <PATHASM value=".;"/>
+ <DEBUGLIBPATH value="$(BCB)\lib\debug"/>
+ <RELEASELIBPATH value="$(BCB)\lib\release"/>
+ <LINKER value="ilink32"/>
+ <USERDEFINES value="_DEBUG"/>
+ <SYSDEFINES value="NO_STRICT"/>
+ <MAINSOURCE value="lnkparse.bpf"/>
+ <INCLUDEPATH value="$(BCB)\include;$(BCB)\include\vcl"/>
+ <LIBPATH value="$(BCB)\lib\obj;$(BCB)\lib"/>
+ <WARNINGS value="-w-par"/>
+ <OTHERFILES value=""/>
+ </MACROS>
+ <OPTIONS>
+ <CFLAG1 value="-Od -H=$(BCB)\lib\vcl60.csm -Hc -Vx -Ve -X- -r- -a8 -b- -k -y -v -vi- -tWC
+ -tWM -c"/>
+ <PFLAGS value="-$YD -$W -$O- -$A8 -v -JPHNE -M"/>
+ <RFLAGS value=""/>
+ <AFLAGS value="/mx /w2 /zd"/>
+ <LFLAGS value="-D&quot;&quot; -ap -Tpe -x -Gn -v"/>
+ <OTHERFILES value=""/>
+ </OPTIONS>
+ <LINKER>
+ <ALLOBJ value="c0x32.obj sysinit.obj $(OBJFILES)"/>
+ <ALLRES value="$(RESFILES)"/>
+ <ALLLIB value="$(LIBFILES) $(LIBRARIES) import32.lib cp32mt.lib"/>
+ <OTHERFILES value=""/>
+ </LINKER>
+ <FILELIST>
+ <FILE FILENAME="lnkparse.res" FORMNAME="" UNITNAME="lnkparse.res" CONTAINERID="ResTool" DESIGNCLASS="" LOCALCOMMAND=""/>
+ <FILE FILENAME="lnkparse.bpf" FORMNAME="" UNITNAME="lnkparse" CONTAINERID="BPF" DESIGNCLASS="" LOCALCOMMAND=""/>
+ <FILE FILENAME="main.cpp" FORMNAME="" UNITNAME="main" CONTAINERID="CCompiler" DESIGNCLASS="" LOCALCOMMAND=""/>
+ </FILELIST>
+ <BUILDTOOLS>
+ </BUILDTOOLS>
+
+ <IDEOPTIONS>
+[Version Info]
+IncludeVerInfo=0
+AutoIncBuild=0
+MajorVer=1
+MinorVer=0
+Release=0
+Build=0
+Debug=0
+PreRelease=0
+Special=0
+Private=0
+DLL=0
+Locale=1049
+CodePage=1251
+
+[Version Info Keys]
+CompanyName=
+FileDescription=
+FileVersion=1.0.0.0
+InternalName=
+LegalCopyright=
+LegalTrademarks=
+OriginalFilename=
+ProductName=
+ProductVersion=1.0.0.0
+Comments=
+
+[HistoryLists\hlIncludePath]
+Count=1
+Item0=$(BCB)\include;$(BCB)\include\vcl
+
+[HistoryLists\hlLibraryPath]
+Count=1
+Item0=$(BCB)\lib\obj;$(BCB)\lib
+
+[HistoryLists\hlDebugSourcePath]
+Count=1
+Item0=$(BCB)\source\vcl
+
+[HistoryLists\hlConditionals]
+Count=1
+Item0=_DEBUG
+
+[Debugging]
+DebugSourceDirs=$(BCB)\source\vcl
+
+[Parameters]
+RunParams=&quot;C:\Documents and Settings\barsuk\Start Menu\Programs\Windows Media Player.lnk&quot;
+Launcher=
+UseLauncher=0
+DebugCWD=
+HostApplication=
+RemoteHost=
+RemotePath=
+RemoteLauncher=
+RemoteCWD=
+RemoteDebug=0
+
+[Compiler]
+ShowInfoMsgs=0
+LinkDebugVcl=0
+LinkCGLIB=0
+
+[Language]
+ActiveLang=
+ProjectLang=
+RootDir=
+ </IDEOPTIONS>
+</PROJECT>
View
BIN  windows/lnkparse/lnkparse.res
Binary file not shown
View
74 windows/lnkparse/main.cpp
@@ -0,0 +1,74 @@
+//---------------------------------------------------------------------------
+
+#pragma hdrstop
+#define NO_WIN32_LEAN_AND_MEAN
+#include <vcl.h>
+#include <utilcls.h> // TComInterface
+//---------------------------------------------------------------------------
+
+#pragma argsused
+
+#include <system.hpp>
+
+#include <string>
+#include <cstdio>
+
+std::string getSystemMessage( int error )
+{
+ static char msg[1024];
+
+ FormatMessage(
+ FORMAT_MESSAGE_FROM_SYSTEM |
+ FORMAT_MESSAGE_IGNORE_INSERTS,
+ NULL,
+ error,
+ MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
+ msg,
+ sizeof msg,
+ NULL
+ );
+
+ return msg;
+}
+
+void error( const char* msg, int error )
+{
+ std::fprintf( stderr, "Error: %s, 0x%08X, %s\n", msg, error, getSystemMessage(error).c_str() );
+ exit(0);
+}
+
+int main( int argc, char* argv[] )
+{
+ if( argc < 2 ) {
+ std::fprintf( stderr, "usage: %s lnkfile\n", argv[0] );
+ exit(0);
+ }
+
+ TComInterface<IShellLink> SL;
+
+ TInitOleT<int> init;
+
+ HRESULT hr = SL.CreateInstance( CLSID_ShellLink );
+ if( FAILED(hr) ) error( "CreateInstance()", hr );
+
+ TComInterface<IPersistFile> PF=SL; //конструктор, инкапсулирующий QueryInterface, можно также использовать operator=
+
+ hr = PF->Load(WideString(argv[1]).c_bstr(),0);
+ if( FAILED(hr) )
+ error( "Load()", hr );
+
+ char args[1024];
+ hr = SL->GetArguments( args, sizeof args );
+ if( FAILED(hr) )
+ error( "GetArguments()", hr );
+
+ char path[1024];
+ hr = SL->GetPath( path, sizeof path, NULL, 0 );
+ if( FAILED(hr) )
+ error( "GetPath()", hr );
+
+ std::printf( "%s %s", path, args );
+
+ return 0;
+}
+//---------------------------------------------------------------------------
View
2  windows/logoff-all/logoff-all.cmd
@@ -0,0 +1,2 @@
+@echo off
+for /F "skip=1 tokens=3" %%i in ('query process') do logoff.exe %%i
View
57 windows/ntprocesses/ps.c
@@ -0,0 +1,57 @@
+#include <windows.h>
+#include <stdio.h>
+#include <tchar.h>
+#include <psapi.h>
+
+void PrintProcessNameAndID( DWORD processID )
+{
+ TCHAR szProcessName[MAX_PATH] = TEXT("<unknown>");
+
+ // Get a handle to the process.
+
+ HANDLE hProcess = OpenProcess( PROCESS_QUERY_INFORMATION |
+ PROCESS_VM_READ,
+ FALSE, processID );
+
+ // Get the process name.
+
+ if (NULL != hProcess )
+ {
+ HMODULE hMod;
+ DWORD cbNeeded;
+
+ if ( EnumProcessModules( hProcess, &hMod, sizeof(hMod),
+ &cbNeeded) )
+ {
+ GetModuleBaseName( hProcess, hMod, szProcessName,
+ sizeof(szProcessName)/sizeof(TCHAR) );
+ }
+ }
+
+ // Print the process name and identifier.
+
+ _tprintf( TEXT("%s (PID: %u)\n"), szProcessName, processID );
+
+ CloseHandle( hProcess );
+}
+
+void main( )
+{
+ // Get the list of process identifiers.
+
+ DWORD aProcesses[1024], cbNeeded, cProcesses;
+ unsigned int i;
+
+ if ( !EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded ) )
+ return;
+
+ // Calculate how many process identifiers were returned.
+
+ cProcesses = cbNeeded / sizeof(DWORD);
+
+ // Print the name and process identifier for each process.
+
+ for ( i = 0; i < cProcesses; i++ )
+ if( aProcesses[i] != 0 )
+ PrintProcessNameAndID( aProcesses[i] );
+}
View
65 windows/ntprocesses/ps.cpp
@@ -0,0 +1,65 @@
+#include <windows.h>
+#include <stdio.h>
+#include <tchar.h>
+#include <psapi.h>
+
+class WindowsProcessInfo {
+public:
+ WindowsProcessInfo(DWORD pid);
+
+ const std::string& name() const { return __name; }
+ int pid() const { return __pid; }
+};
+
+void PrintProcessNameAndID( DWORD processID )
+{
+ TCHAR szProcessName[MAX_PATH] = TEXT("<unknown>");
+
+ // Get a handle to the process.
+
+ HANDLE hProcess = OpenProcess( PROCESS_QUERY_INFORMATION |
+ PROCESS_VM_READ,
+ FALSE, processID );
+
+ // Get the process name.
+
+ if (NULL != hProcess )
+ {
+ HMODULE hMod;
+ DWORD cbNeeded;
+
+ if ( EnumProcessModules( hProcess, &hMod, sizeof(hMod),
+ &cbNeeded) )
+ {
+ GetModuleBaseName( hProcess, hMod, szProcessName,
+ sizeof(szProcessName)/sizeof(TCHAR) );
+ }
+ }
+
+ // Print the process name and identifier.
+
+ _tprintf( TEXT("%s (PID: %u)\n"), szProcessName, processID );
+
+ CloseHandle( hProcess );
+}
+
+void main( )
+{
+ // Get the list of process identifiers.
+
+ DWORD aProcesses[1024], cbNeeded, cProcesses;
+ unsigned int i;
+
+ if ( !EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded ) )
+ return;
+
+ // Calculate how many process identifiers were returned.
+
+ cProcesses = cbNeeded / sizeof(DWORD);
+
+ // Print the name and process identifier for each process.
+
+ for ( i = 0; i < cProcesses; i++ )
+ if( aProcesses[i] != 0 )
+ PrintProcessNameAndID( aProcesses[i] );
+}
View
141 windows/service/actmonitor/actservice.cpp
@@ -0,0 +1,141 @@
+#include <windows.h>
+#include <stdio.h>
+#include <time.h>
+
+#define SLEEP_TIME (60 * 1000)
+#define LOGFILE "c:\\windows\\actservice.inf"
+
+SERVICE_STATUS ServiceStatus;
+SERVICE_STATUS_HANDLE hStatus;
+
+void ServiceMain(int argc, char** argv);
+void ControlHandler(DWORD request);
+int InitService();
+
+int WriteToLog(char* str)
+{
+ FILE* log;
+ log = fopen(LOGFILE, "a+");
+ if (log == NULL)
+ return -1;
+
+ fprintf(log, "%s\n", str);
+
+ fclose(log);
+ return 0;
+}
+
+void main()
+{
+ SERVICE_TABLE_ENTRY ServiceTable[2];
+ ServiceTable[0].lpServiceName = "ActivityMonitor";
+ ServiceTable[0].lpServiceProc = (LPSERVICE_MAIN_FUNCTION)ServiceMain;
+
+ ServiceTable[1].lpServiceName = NULL;
+ ServiceTable[1].lpServiceProc = NULL;
+ // Start the control dispatcher thread for our service
+ StartServiceCtrlDispatcher(ServiceTable);
+}
+
+
+void ServiceMain(int argc, char** argv)
+{
+ int error;
+
+ ServiceStatus.dwServiceType = SERVICE_WIN32;
+ ServiceStatus.dwCurrentState = SERVICE_START_PENDING;
+ ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN;
+ ServiceStatus.dwWin32ExitCode = 0;
+ ServiceStatus.dwServiceSpecificExitCode = 0;
+ ServiceStatus.dwCheckPoint = 0;
+ ServiceStatus.dwWaitHint = 0;
+
+ hStatus = RegisterServiceCtrlHandler(
+ "ActivityMonitor",
+ (LPHANDLER_FUNCTION)ControlHandler);
+ if (hStatus == (SERVICE_STATUS_HANDLE)0)
+ {
+ // Registering Control Handler failed
+ return;
+ }
+ // Initialize Service
+ error = InitService();
+ if (error)
+ {
+ // Initialization failed
+ ServiceStatus.dwCurrentState = SERVICE_STOPPED;
+ ServiceStatus.dwWin32ExitCode = -1;
+ SetServiceStatus(hStatus, &ServiceStatus);
+ return;
+ }
+ // We report the running status to SCM.
+ ServiceStatus.dwCurrentState = SERVICE_RUNNING;
+ SetServiceStatus (hStatus, &ServiceStatus);
+
+ // The worker loop of a service
+ while (ServiceStatus.dwCurrentState == SERVICE_RUNNING)
+ {
+ char buffer[10240];
+
+ time_t stamp = time(NULL);
+ struct tm* lt = localtime( &stamp );
+
+ sprintf(buffer,
+ "%04d/%02d/%02d %02d:%02d:%02d",
+ lt->tm_year + 1900, lt->tm_mon + 1, lt->tm_mday,
+ lt->tm_hour, lt->tm_min, lt->tm_sec
+ );
+
+ int result = WriteToLog(buffer);
+ if (result)
+ {
+ ServiceStatus.dwCurrentState = SERVICE_STOPPED;
+ ServiceStatus.dwWin32ExitCode = -1;
+ SetServiceStatus(hStatus, &ServiceStatus);
+ return;
+ }
+
+ Sleep(SLEEP_TIME);
+ }
+ return;
+}
+
+// Service initialization
+int InitService()
+{
+ int result;
+ result = WriteToLog("Activity monitoring started.");
+ return(result);
+}
+
+// Control handler function
+void ControlHandler(DWORD request)
+{
+ switch(request)
+ {
+ case SERVICE_CONTROL_STOP:
+ WriteToLog("Activity monitoring stopped.");
+
+ ServiceStatus.dwWin32ExitCode = 0;
+ ServiceStatus.dwCurrentState = SERVICE_STOPPED;
+ SetServiceStatus (hStatus, &ServiceStatus);
+ return;
+
+ case SERVICE_CONTROL_SHUTDOWN:
+ WriteToLog("Activity monitoring stopped.");
+
+ ServiceStatus.dwWin32ExitCode = 0;
+ ServiceStatus.dwCurrentState = SERVICE_STOPPED;
+ SetServiceStatus (hStatus, &ServiceStatus);
+ return;
+
+ default:
+ break;
+ }
+
+ // Report current status
+ SetServiceStatus (hStatus, &ServiceStatus);
+
+ return;
+}
+
View
1  windows/service/actmonitor/build.cmd
@@ -0,0 +1 @@
+bcc32 actservice.cpp
View
1  windows/service/actmonitor/clear.cmd
@@ -0,0 +1 @@
+del *.tds *.obj *.exe
View
131 windows/service/actmonitor/example/service.cpp
@@ -0,0 +1,131 @@
+#include <windows.h>
+#include <stdio.h>
+
+#define SLEEP_TIME 5000
+#define LOGFILE "C:\\MyServices\\memstatus.txt"
+
+SERVICE_STATUS ServiceStatus;
+SERVICE_STATUS_HANDLE hStatus;
+
+void ServiceMain(int argc, char** argv);
+void ControlHandler(DWORD request);
+int InitService();
+
+int WriteToLog(char* str)
+{
+ FILE* log;
+ log = fopen(LOGFILE, "a+");
+ if (log == NULL)
+ return -1;
+ fprintf(log, "%s\n", str);
+ fclose(log);
+ return 0;
+}
+
+void main()
+{
+ SERVICE_TABLE_ENTRY ServiceTable[2];
+ ServiceTable[0].lpServiceName = "MemoryStatus";
+ ServiceTable[0].lpServiceProc = (LPSERVICE_MAIN_FUNCTION)ServiceMain;
+
+ ServiceTable[1].lpServiceName = NULL;
+ ServiceTable[1].lpServiceProc = NULL;
+ // Start the control dispatcher thread for our service
+ StartServiceCtrlDispatcher(ServiceTable);
+}
+
+
+void ServiceMain(int argc, char** argv)
+{
+ int error;
+
+ ServiceStatus.dwServiceType = SERVICE_WIN32;
+ ServiceStatus.dwCurrentState = SERVICE_START_PENDING;
+ ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN;
+ ServiceStatus.dwWin32ExitCode = 0;
+ ServiceStatus.dwServiceSpecificExitCode = 0;
+ ServiceStatus.dwCheckPoint = 0;
+ ServiceStatus.dwWaitHint = 0;
+
+ hStatus = RegisterServiceCtrlHandler(
+ "MemoryStatus",
+ (LPHANDLER_FUNCTION)ControlHandler);
+ if (hStatus == (SERVICE_STATUS_HANDLE)0)
+ {
+ // Registering Control Handler failed
+ return;
+ }
+ // Initialize Service
+ error = InitService();
+ if (error)
+ {
+ // Initialization failed
+ ServiceStatus.dwCurrentState = SERVICE_STOPPED;
+ ServiceStatus.dwWin32ExitCode = -1;
+ SetServiceStatus(hStatus, &ServiceStatus);
+ return;
+ }
+ // We report the running status to SCM.
+ ServiceStatus.dwCurrentState = SERVICE_RUNNING;
+ SetServiceStatus (hStatus, &ServiceStatus);
+
+ MEMORYSTATUS memory;
+ // The worker loop of a service
+ while (ServiceStatus.dwCurrentState == SERVICE_RUNNING)
+ {
+ char buffer[16];
+ GlobalMemoryStatus(&memory);
+ sprintf(buffer, "%d", memory.dwAvailPhys);
+ int result = WriteToLog(buffer);
+ if (result)
+ {
+ ServiceStatus.dwCurrentState = SERVICE_STOPPED;
+ ServiceStatus.dwWin32ExitCode = -1;
+ SetServiceStatus(hStatus, &ServiceStatus);
+ return;
+ }
+
+ Sleep(SLEEP_TIME);
+ }
+ return;
+}
+
+// Service initialization
+int InitService()
+{
+ int result;
+ result = WriteToLog("Monitoring started.");
+ return(result);
+}
+
+// Control handler function
+void ControlHandler(DWORD request)
+{
+ switch(request)
+ {
+ case SERVICE_CONTROL_STOP:
+ WriteToLog("Monitoring stopped.");
+
+ ServiceStatus.dwWin32ExitCode = 0;
+ ServiceStatus.dwCurrentState = SERVICE_STOPPED;
+ SetServiceStatus (hStatus, &ServiceStatus);
+ return;
+
+ case SERVICE_CONTROL_SHUTDOWN:
+ WriteToLog("Monitoring stopped.");
+
+ ServiceStatus.dwWin32ExitCode = 0;
+ ServiceStatus.dwCurrentState = SERVICE_STOPPED;
+ SetServiceStatus (hStatus, &ServiceStatus);
+ return;
+
+ default:
+ break;
+ }
+
+ // Report current status
+ SetServiceStatus (hStatus, &ServiceStatus);
+
+ return;
+}
+
View
3  windows/service/actmonitor/start.cmd
@@ -0,0 +1,3 @@