2013년 11월 4일 월요일

Command Tricks

COMMAND(Batch) tricks

Find all file(directory) including sub dir.

dir "dirname" /A:D /S /B

Find all sub dir + remove dir

FOR /f "tokens=*" %a in ('dir *.delete /A:D /B /S') DO RMDIR /S /Q %a

Find *.cpp and *.h

dir /s /b *.cpp;*.h

find trace*.cpp

dir /s /b trace*.cpp

find text “Trace” in *.cpp + *.h

dir /s /b *.cpp;*.h | find "Trace"

Written with StackEdit.

dumpbin - vs의 nm같은 tool

덤프빈 다운로드 / 

DumpBin execution version
DumpBin.zip download

사용법

아래처럼 옵션 다음에 실행파일의 path 를 적어주면 된다.
dumpbin /option exe_path
c:\>dumpbin /disasem c:\windows\notepad.exe

자세한 설명은 아래를 참고하자.

/EXPORTS

c:\>dumpbin /exports c:\windows\system32/ntdll.dll

이렇게 하면, export 하고 있는 함수의 리스트를 볼 수 있다.

Referenece

  1. http://originaldll.com/
  2. http://www.nodevice.com/dll/MSDIS110_DLL/item10670.html

2013년 7월 4일 목요일

create thread mfc

create thread in mfc


1. class member function thread

header

private: 
static DWORD TestThread(LPVOID lpParameter);

usage cpp

m_hTestThread = ::CreateThread(NULL,0, (LPTHREAD_START_ROUTINE) MpWatcherWnd::TestThread, (void*)(this), 0, &dwTestThread);

definition cpp


DWORD TestClass::TestThread(LPVOID lpParameter)
{
TestClass* pTest = (TestClass*)lpParameter;
if (pTest)
{
// work
}
else
{
// error!
}
return 0;
}


2. global thread


2013년 7월 3일 수요일

NSIS Installer

basic help 


http://nsis.sourceforge.net/Main_Page
http://www.kippler.com/doc/nsis/

tutorial

http://nsis.sourceforge.net/Category:Tutorials

sample

http://nsis.sourceforge.net/Category:Code_Examples
http://nsis.sourceforge.net/A_simple_installer_with_start_menu_shortcut_and_uninstaller

download

http://nsis.sourceforge.net/Download


useful links

no?

basic usage

sample.nsi
; sample.nsi
;
; This script is based on example1.nsi, but it remember the directory, 
; has uninstall support and (optionally) installs start menu shortcuts.
;
; It will install Sample.nsi into a directory that the user selects,

;--------------------------------

; define includes
!include "WinMessages.nsh"
!include "FileFunc.nsh"
!include "LogicLib.nsh"

; The version of the installer
!define VERSION "1.2.1"

; The name of the installer
Name "Sample ${VERSION}"

; The file to write
OutFile "Sample.${VERSION}.exe"

; The default installation directory
InstallDir "$PROGRAMFILES\Sample"

; define reserved files
ReserveFile "Sample.exe"
ReserveFile "Sample.dll"
ReserveFile "Sample.sys"
ReserveFile "Sample.txt"


; Registry key to check for directory (so if you install again, it will 
; overwrite the old one automatically)
InstallDirRegKey HKLM "Software\Sample" "C:\Program Files\Sample\"

; Request application privileges for Windows Vista
RequestExecutionLevel admin

; Define Interval variable
Var /GLOBAL DefaultInterval

;--------------------------------

; Pages

; describe license
PageEx license
   LicenseData license.txt
PageExEnd
Page components
Page instfiles
UninstPage uninstConfirm
UninstPage instfiles

;--------------------------------
; Functions

Function .onInit

FunctionEnd

Function .onInstSuccess

FunctionEnd

Function un.onInit

FunctionEnd

Function un.onUninstSuccess

FunctionEnd


;--------------------------------
; The stuff to install
Section "Sample ${VERSION}"
SectionIn RO

; Set output path to the installation directory.
SetOutPath $INSTDIR

; Write the installation path into the registry
WriteRegStr HKLM SOFTWARE\Sample "Install_Dir" "$INSTDIR"
 
; Write the uninstall keys for Windows
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Sample" "DisplayName" "Sample"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Sample" "Publisher" "Sample Co., Ltd."
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Sample" "UninstallString" '"$INSTDIR\uninstall.exe"'
WriteUninstaller "uninstall.exe"

; Copy Sample.sys
SetOutPath "C:\WINDOWS\system32\drivers\"
File Sample.sys

; Copy Sample files
;SetOutPath "C:\Program Files\Sample\"
SetOutPath $INSTDIR
File Sample.exe
File Sample.dll
File Sample.txt
SectionEnd

; Optional section (can be disabled by the user)
Section "Start Menu Shortcuts"
CreateDirectory "$SMPROGRAMS\Sample"
CreateShortCut "$SMPROGRAMS\Sample\Uninstall.lnk" "$INSTDIR\uninstall.exe" "" "$INSTDIR\uninstall.exe" 0
SectionEnd

;--------------------------------

; Uninstaller

Section "Uninstall"
; Stop and remove Services
ExecWait '"Cmd.exe" /c net stop Sample'
ExecWait '"Cmd.exe" /c $INSTDIR\Sample.exe -remove'
; Remove registry keys
DeleteRegKey HKLM "SYSTEM\CurrentControlSet\Services\Sample"
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Sample"
DeleteRegKey HKLM "SYSTEM\CurrentControlSet\Services\Sample"
DeleteRegKey HKLM "Software\Sample"

; Remove files and uninstaller
Delete "$INSTDIR\Sample.nsi"
Delete "$INSTDIR\uninstall.exe"
Delete "$INSTDIR\*.*"
Delete "C:\windows\system32\drivers\Sample.sys"

; Remove shortcuts, if any
Delete "$SMPROGRAMS\Sample\*.*"

; Remove directories used
RMDir "$SMPROGRAMS\Sample"
RMDir "$INSTDIR"
SectionEnd



2013년 6월 24일 월요일

SetForegoundWindow without taskbar flashing(blinking, flickering)


ㅡ.ㅡ ::SetForegoundWindow() 가 호출은 정상으로 되나 동작을 이상하게 할때가 있음.

특히 #Windows7 일때.

그럴때 써볼만한 팁들 모음

1. How to bring window to top with SetForegroundWindow()

2. SetForegroundWindow Win32-API not always works on Windows-

void SetForegroundWindowInternal(HWND hWnd)
{
 if(!::IsWindow(hWnd)) return;

 //relation time of SetForegroundWindow lock
 DWORD lockTimeOut = 0;
 HWND  hCurrWnd = ::GetForegroundWindow();
 DWORD dwThisTID = ::GetCurrentThreadId(),
  dwCurrTID = ::GetWindowThreadProcessId(hCurrWnd,0);

 //we need to bypass some limitations from Microsoft :)
 if(dwThisTID != dwCurrTID)
 {
  ::AttachThreadInput(dwThisTID, dwCurrTID, TRUE);

  ::SystemParametersInfo(SPI_GETFOREGROUNDLOCKTIMEOUT,0,&lockTimeOut,0);
  ::SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT,0,0,SPIF_SENDWININICHANGE | SPIF_UPDATEINIFILE);

  ::AllowSetForegroundWindow(ASFW_ANY);
 }

 ::SetForegroundWindow(hWnd);

 if(dwThisTID != dwCurrTID)
 {
  ::SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT,0,(PVOID)lockTimeOut,SPIF_SENDWININICHANGE | SPIF_UPDATEINIFILE);
  ::AttachThreadInput(dwThisTID, dwCurrTID, FALSE);
 }
}