Code Repo    |     RSS
MD's Technical Sharing



Wednesday, April 30, 2008

Register a DLL via COM under Windows Mobile

On Windows XP, one can register a COM DLL by using regsvr32. On Windows CE, there is a similiar tool called regsvrce.exe.

The DLL must export the following function for registration to be successful:

STDAPI DllRegisterServer()
{
return AMovieDllRegisterServer2( TRUE );
}

STDAPI
DllUnregisterServer()
{
return AMovieDllRegisterServer2( FALSE );
}

extern "C" BOOL WINAPI DllEntryPoint(HINSTANCE, ULONG, LPVOID);

BOOL APIENTRY
DllMain(HANDLE hModule,
DWORD dwReason
,
LPVOID lpReserved
)
{
return DllEntryPoint((HINSTANCE)(hModule), dwReason, lpReserved);
}

If the DLL is built in Visual Studio 2005, an export file (extension .DEF) needs to be created:

EXPORTS
DllMain PRIVATE
DllGetClassObject PRIVATE
DllCanUnloadNow PRIVATE
DllRegisterServer PRIVATE
DllUnregisterServer PRIVATE
Read More »

Wednesday, April 16, 2008

Synchronising OneNote notebook among different computers via FTP

OneNote does not support saving a Notebook directly via FTP. However, with the following step, we can conveniently do the trick:


  • Register for a free FTP account at http://www.drivehq.com/



  • Download Netdrive (www.netdrive.net/), a Windows utility to map FTP/WebDav folder as network driver



  • Use NetDrive to map the free FTP account into a local drive, such as Z.



  • In OneNote 2007, choose Menu->Share->Create Share Notebook. Enter a name for the notebook, then select Multiple users will use this Notebook, and pick On a server. After that, choose to save the notebook onto the network drive you just map in step (3).



  • On other computers you wish to use this notebook, re-perform step 1, 2 and 3. In step 4, do not create a new notebook, but instead use File/Open and choose to open the shared notebook.



  • Done! Everytime you make changes, OneNote will automatically save the changes and upload it to the FTP server. Your changes can be seen by all users of this notebook.




  • Cons: OneNote is not optimized to work with FTP connection. Every time you make change to a notebook, Onenote deletes an entire file and create new one. This is very slow and if for some reasons, the FTP upload fails, the notebook file will disappear and can only be restored from OneNote backup.

    An alternative is to use BestSync (http://www.risefly.com/fsedwld.htm). It allows syncing between local folders as well as FTP folders.


    References


  • OneNote 2007: Notebook Upload via FTP, http://colbyafrica.blogspot.com/2008/05/onenote-2007-notebook-upload-via-ftp.html



  • Syncing OneNote 2007 notes across your many PCs , http://blogs.msdn.com/chris_pratley/archive/2006/06/07/621692.aspx


  • Read More »

    Monday, April 14, 2008

    Windows Vista Misc

    The following contains some tips and tricks and some other interesting information I come across while using Windows Vista.

    1. Turn off User Account Control: Start->Run->Msconfig->Tools->Disable UAC. Need reboot

    2. Show Run in start menu: Right click the Start menu, choose Properties. Choose the Start menu tab, choose Customize, and then check Show Run

    3. Show menu bar in Windows Explorer:

    • Press the ALT key while an item in the explorer toolbar is selected
    • Click Organize on the toolbar, point to Layout, and then click Menu Bar.
    4. Window Help (.hlp file) is not available on Windows Vista. To view old Windows help files, download WinHlp32.exe from here

    5. Hyperterminal has been removed from Windows Vista. As an alternative, use putty

    6. Telnet is also not installed by default. To install the telnet client:

    • Open Control Panel, Programs, and then click Turn Windows features on or off.
    • In the Windows Features dialog box, select the Telnet Client check box.
    Read More »

    #define Preprocessor Directive

    In C++: Define a constant:

    #define UNICODE
    //Check if a constant is defined:
    #ifdef UNICODE
    #define MessageBox MessageBoxW
    #else
    #define MessageBox MessageBoxA
    #endif
    //Undefine a constant
    #undef UNICODE

    In VB.NET - Define a constant:
    • #Const MyConst = TRUE (FALSE defaults to undefined)
    • Or in Project Properties>Compile>Advanced Compiler Settings>Custom Constants and type the custom constants, e.g.: Smartphone=TRUE, MyConst=TRUE
    Check if a constant is defined:

    #If MyConst = TRUE Then
    'Do something
    #else
    'Do something
    #end if
    Read More »

    Friday, April 11, 2008

    Setting connection priority on Windows XP


    To set which connection will be used for Internet access if there are multiple connections available:

    Method 1:

    Open Start -> Settings -> Network Connections -> Advanced -> Advanced Settings -> [tab] Adapters and Bindings. Use the arrows to set the connection priorities. The topmost connection has the highest priority.

    Method 2:

    If method 1 doesn't work, set the connection priority by manually specifying the connection metric.

    1. Open the Network Connections dialog box (go to Start, Settings, Control Panel, and select the Network Connections applet).
    2. Right-click the desired link, then select Properties.
    3. Select "Internet Protocol (TCP/IP)," then click Properties.
    4. Click the Advanced button at the bottom of the dialog.
    5. Clear "Automatic metric," then enter a metric value between 1 and 9999.


    A lower metric has a higher priority.

    Reference:



    Read More »

    Tuesday, April 8, 2008

    Design an IVR System on Windows Mobile

    The architecture of TAPI on Windows CE (which is the core of windows mobile devices), per se, support DTMF sending and detection. However, in reality, it is not possible to rely on TAPI's DTMF capabilities to develop an IVR system for windows mobile devices. This writing explains why.

    First, sending DTMF is straight forward. One can use lineGenerateTone to send DTMF and this works on most phones. To detect DTMF, there are 2 approaches:

    1. Approach 1 seems straight forward. Use lineMonitorDigits on the open line to be informed when DTMF is received during an active call. However, on most tested phones, lineMonitorDigits fails, indicating it's not implemented by the OEM. This, however, works on a desktop with a modem attached.

    1. Perform analysis of the call audio stream and use algorithm to detect DTMF. To do this, we must use lineGetID to retrieve a handle to the "wave/out" or "wave/in" device of the active call and work on the audio stream coming from these devices. However, in the first place, lineGetID fails, simply because the device does not make the audio stream available to TAPI. There is possibly a physical separation layer between the phone audio hardware and the telephony logic. Some sites suggest that lineGetID when used to get wave devices require that the line be opened in LINEMEDIAMODE_AUTOMATEDVOICE. However, when tested, lineOpen in automated voice mode fails with LINEERR_INVALMEDIAMODE, suggesting that TSP does not support this.

    There is yet, another crude but working approach, which is, to turn on the loudspeaker, to the max. volume, during an active call. The microphone will pick up sounds from the speaker. The code will then be able to record whatever sound coming from the microphone, and detect any DTMF. This is a bit unreliable as it will pick up a lot of noises from the environment and the DTMF algorithm must be designed to work with a wide range of signal-to-noises ratios (SNR). However, in a silent environment, it does work. The attached solution demonstrates this idea. There are 2 projects in the solution
    • IVR_Lib_Dotnet project: The library used by the main projects. It contains functions to record voice from the phone speaker as well as playing back.
      • TAPI.cs: C# wrapper for TAPI
      • Wave folder: supports playing/recording of Wave file from .NET. The classes was taken from .NET Compact Framework Sample: P/Invoke Library
      • DTMF folder: support detecting DTMF from a wave stream using the the Goertzel Algorithm. This contains the following file
        • Goertzel.cs: the pure Goertzel algorithm
        • DTMFDetector.cs: algorithm to detect DTMF from a wave recording.
        • DTMFCapture.cs: this uses a timer to keep on scanning a WaveIn stream for any possible DTMF. It calls DTMFDetector.cs as often as the timer interval
    • DTMF_Detector: this project is only for testing of the DTMFDetector.cs class. Provide it a WAVE file and it will report any DTMF found in the file. Only 1 DTMF per file is supported.
    • TAPI_IVR_Demo: the main project. It contains 2 forms
      • TAPI_Test.cs: for testing of the TAPI.cs class, including making calls and hanging up.
      • IVRDemo.cs: the main IVR system.
    To detect DTMF, a new instance of the class must first be initialized:

    wi = new WaveIn();
    myCapture
    = new DTMFCapture(wi);

    //raise when a key is pressed
    myCapture
    .DTMFKeyPressed += new DTMFCapture.DTMFEventHandler(myCapture_DTMFKeyPressedOption2);

    //raised when timeout waiting for DTMF
    myCapture
    .Timeout += new EventHandler(myCapture_Timeout);

    //start DTMF monitoring
    myCapture
    .StartMonitoring();
    To play a WAV file:
    playWave(getAppDir() + "\\recordings\\voicemail.wav", 2000);
    To perform recording:
    saveRecord = true;
    myCapture
    .StopMonitoring();
    wi
    = new WaveIn();
    wi
    .Preload(60 * 1000, 1024);

    wi
    .Start();

    Download source code

    The attached project is only meant to be used as a proof-of-concept IVR application running on Windows Mobile. The approach that the project takes makes it impossible to use it for any serious purposes other than running a few test calls.


    References:

    Read More »

    Signing CAB files with temporary certificate during development

    1. Refer to Create Temporary Certificates for Use During Development on how to create a test certificate.

    2. Copy signtool.exe from "C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\" to the cabsigntool folder if it's not already there.

    3. Use cabsigntool to sign the CAB file:

    cabsigntool oldCAB.CAB newCAB.CAB

    to sign the CAB file locally. This will sign the CAB file header as well as its contents with the local certificate.

    4. Done. When opening in Explorer, the Property tab will show that the CAB has been signed.

    5. The signed CAB files will not be trusted by the device by default. To make the device trust the signed CAB files, the development root cert must be installed on the device manually.

    6. In production, locally signed CAB files components (.EXE, .DLL) will need to be uploaded to signing authority website portal, where it will be signed again. Developers will download the signed files from the portal, package them back into CAB files, sign the CAB file header again using signtool. The sign CAB file must be uploaded to the portal again and the finally signed CAB file ready for release will be available for download from the portal.
    Read More »

    Restoring the OneNote Guide

    If you didn't delete the OneNote Guide notebook folder then you can do this:
    1. Open OneNote
    2. File-->Open-->Notebook
    3. Go to Documents\OneNote Notebooks
    4. Find the OneNote Guide folder and click on it
    5. Click Open
    6. Success!
    If you deleted the OneNote Guide notebook folder then please do this:
    1. Open OneNote
    2. File-->Open-->Section
    3. Go to %programfiles%\Microsoft Office\OFFICE12\LCID\
    4. The LCID is the folder for your language & locale; for EN-US this is 1033
    5. Double click on ONGuide.onepkg
    6. Unpack the notebook by going through the wizard
    7. Success!
    Reference: Restoring the OneNote Guide
    Read More »