2011年6月28日 星期二

CreateWaitableTimer

1. Create

HANDLE hTimer = CreateWaitableTimer(NULL,FALSE,NULL);

2. Set

LARGE_INTEGER liDueTime;
const int nTimerUnitsPerSecond=10*1000*1000; // the unit of timer is 100 nano seconds
// Set the event the first time 2 seconds after calling SetWaitableTimer
 liDueTime.QuadPart= -(STARTTIMERAFTERSECOND * m_nTimerUnitsPerSecond );
int nTimerInterVal = 10;

SetWaitableTimer(hTimer,&liDueTime, (nTimerInterVal*nTimerUnitsPerSecond), NULL, NULL, false);   


3. Use


// Wait for the timer.
if (WaitForSingleObject(hTimer, INFINITE) != WAIT_OBJECT_0)
        printf("WaitForSingleObject failed (%d)\n", GetLastError());
else printf("Timer was signaled.\n");

Detect microphone VC++, waveInGetNumDevs

An easy way to detect the number of waveindevice using waveInGetNumDevs function

#include <Mmsystem.h>
#pragma comment( lib, "Winmm.lib" )

UINT nDevices =     waveInGetNumDevs();

2011年6月14日 星期二

[InstallScript] MsiGetProperty, MsiSetProperty

There's a function to get value from  Property in installscript

MsiGetProperty (hMSI, "ProductCode", szProductCode, numSize);

or set property


MsiSetProperty(hMSI, "NeedScheduleReboot", "1")   ;

this example show how to set reboot after installation

2011年6月13日 星期一

[Installshield] Access Installation Interview in InstallScript MSI project

There's no Installation Interview in project assist panel  within a Installscript MSI project.


To modify which dialog boxes are displayed by modifying the OnFirstUIBefore event in the InstallScript view.

2011年6月2日 星期四

[InstallShield] installscript parse date time and RenameFile

 This example code displays using GetSystemInfo to get system time, using StrGetTokens to parse date, time and RenameFile to rename files.

///////////////////////////////////////////////
// some defines are not showing here

function RenameDBFile(hMSI)
    STRING     szPath,szFileNameDB,szFileNameDBLog ,svResultDB,svResultLog,strDate,strTime,szRenameDB,szRenameDBLog;
    INT       nvDate,nvTime;
    LIST   listDate, listTime;
    STRING  svDdy, svDmn, svDyr, szDelim,szTimeStamp,svHr, svMin, svSec;
  

begin 
   
   
    GetSystemInfo(DATE, nvDate, strDate);
    GetSystemInfo(TIME, nvTime, strTime);
     
 
     
     listDate = ListCreate (STRINGLIST);
     listTime = ListCreate (STRINGLIST);
     StrGetTokens(listDate,strDate,"-");
    ListGetFirstString(listDate,svDmn);
    ListGetNextString(listDate,svDdy);
    ListGetNextString(listDate,svDyr);
    ListDestroy(listDate);
    StrGetTokens(listTime,strTime,":");
    ListGetFirstString(listTime,svHr);
    ListGetNextString(listTime,svMin);
    ListGetNextString(listTime,svSec);
    ListDestroy(listTime);
    szTimeStamp = "."+svDmn + "_" + svDdy + "_" + svDyr + "_" + svHr+ "_"+svMin+ "_"+svSec;
       
    szPath = ProgramFilesFolder + DB_DATA_PATH;   
    szFileNameDB = DB_FILENAME;
    szFileNameDBLog = DB_LOG_FILENAME;   
    szRenameDB = DB_FILENAME + szTimeStamp + ".bak";
    szRenameDBLog = DB_LOG_FILENAME +  szTimeStamp +".bak";
  
  // Set SRCDIR and TARGETDIR for RenameFile
    SRCDIR = szPath;
    TARGETDIR = szPath; 
                            
   
    if(FindFile(szPath, szFileNameDB, svResultDB) = 0 ) then
          RenameFile(szFileNameDB,szRenameDB); 
                 
        endif;
    if(FindFile(szPath, szFileNameDBLog, svResultLog) = 0 ) then
          RenameFile(szFileNameDBLog,szRenameDBLog);
        endif;

end;

Dialog with SysLink control create fail

Using VS2008 SP1, adding a SysLink Control into a dailog and everything is fine in DEBUG mode.
When running in release mode.... something goes wrong, the dialog won't show up and return -1 fail code...
I traced this problem for a while i found it is the problem of SysLink
 
I saw a blog http://twigstechtips.blogspot.com/2010/03/c-dialogs-with-syslink-control-do-not.html 
 
The main reason the Syslink causes the DialogBox() command to fail is because it requires unicode text support, starting from ComCtl32.dll 6. 
 
add this code will solve the problem
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")