[ACPPAGE] Make use of the PCH.
[reactos.git] / dll / cpl / console / console.c
index c75a63d..d2cd2d7 100644 (file)
 /*
  * PROJECT:         ReactOS Console Configuration DLL
  * LICENSE:         GPL - See COPYING in the top level directory
- * FILE:            dll/win32/console/console.c
- * PURPOSE:         initialization of DLL
- * PROGRAMMERS:     Johannes Anderwald (johannes.anderwald@student.tugraz.at)
+ * FILE:            dll/cpl/console/console.c
+ * PURPOSE:         Initialization
+ * PROGRAMMERS:     Johannes Anderwald (johannes.anderwald@reactos.org)
+ *                  Hermes Belusca-Maito (hermes.belusca@sfr.fr)
  */
 
 #include "console.h"
 
-#define NUM_APPLETS    (1)
-#define WM_SETCONSOLE (WM_USER+10)
+#define NDEBUG
+#include <debug.h>
 
-
-LONG APIENTRY InitApplet(HWND hwnd, UINT uMsg, LPARAM wParam, LPARAM lParam);
 INT_PTR CALLBACK OptionsProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
 INT_PTR CALLBACK FontProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
 INT_PTR CALLBACK LayoutProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
 INT_PTR CALLBACK ColorsProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
 
-HINSTANCE hApplet = 0;
+HINSTANCE hApplet = NULL;
 
-/* Applets */
-APPLET Applets[NUM_APPLETS] =
-{
-  {IDC_CPLICON, IDS_CPLNAME, IDS_CPLDESCRIPTION, InitApplet}
-};
+/* Local copy of the console information */
+PCONSOLE_STATE_INFO ConInfo = NULL;
+/* What to do with the console information */
+static BOOL SetConsoleInfo  = FALSE;
+static BOOL SaveConsoleInfo = FALSE;
 
-static COLORREF s_Colors[] =
+static VOID
+InitPropSheetPage(PROPSHEETPAGEW *psp,
+                  WORD idDlg,
+                  DLGPROC DlgProc)
 {
-       RGB(0, 0, 0),
-       RGB(0, 0, 128),
-       RGB(0, 128, 0),
-       RGB(0, 128, 128),
-       RGB(128, 0, 0),
-       RGB(128, 0, 128),
-       RGB(128, 128, 0),
-       RGB(192, 192, 192),
-       RGB(128, 128, 128),
-       RGB(0, 0, 255),
-       RGB(0, 255, 0),
-       RGB(0, 255, 255),
-       RGB(255, 0, 0),
-       RGB(255, 0, 255),
-       RGB(255, 255, 0),
-       RGB(255, 255, 255)
-};
-
-static void
-InitPropSheetPage(PROPSHEETPAGE *psp, WORD idDlg, DLGPROC DlgProc, LPARAM lParam)
+    ZeroMemory(psp, sizeof(*psp));
+    psp->dwSize      = sizeof(*psp);
+    psp->dwFlags     = PSP_DEFAULT;
+    psp->hInstance   = hApplet;
+    psp->pszTemplate = MAKEINTRESOURCEW(idDlg);
+    psp->pfnDlgProc  = DlgProc;
+    psp->lParam      = 0;
+}
+
+static VOID
+InitDefaultConsoleInfo(PCONSOLE_STATE_INFO pConInfo)
 {
-  ZeroMemory(psp, sizeof(PROPSHEETPAGE));
-  psp->dwSize = sizeof(PROPSHEETPAGE);
-  psp->dwFlags = PSP_DEFAULT;
-  psp->hInstance = hApplet;
-  psp->pszTemplate = MAKEINTRESOURCE(idDlg);
-  psp->pfnDlgProc = DlgProc;
-  psp->lParam = lParam;
+    // FIXME: Also retrieve the value of REG_DWORD CurrentPage.
+    ConCfgGetDefaultSettings(pConInfo);
 }
 
-PConsoleInfo
-AllocConsoleInfo()
+static INT_PTR
+CALLBACK
+ApplyProc(HWND hwndDlg,
+          UINT uMsg,
+          WPARAM wParam,
+          LPARAM lParam)
 {
-       PConsoleInfo pConInfo;
+    UNREFERENCED_PARAMETER(lParam);
 
-       pConInfo = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(ConsoleInfo));
+    switch (uMsg)
+    {
+        case WM_INITDIALOG:
+        {
+            CheckDlgButton(hwndDlg, IDC_RADIO_APPLY_CURRENT, BST_CHECKED);
+            return TRUE;
+        }
+        case WM_COMMAND:
+        {
+            if (LOWORD(wParam) == IDOK)
+            {
+                if (IsDlgButtonChecked(hwndDlg, IDC_RADIO_APPLY_CURRENT) == BST_CHECKED)
+                    EndDialog(hwndDlg, IDC_RADIO_APPLY_CURRENT);
+                else
+                    EndDialog(hwndDlg, IDC_RADIO_APPLY_ALL);
+            }
+            else if (LOWORD(wParam) == IDCANCEL)
+            {
+                EndDialog(hwndDlg, IDCANCEL);
+            }
+            break;
+        }
+        default:
+            break;
+    }
 
-       return pConInfo;
+    return FALSE;
 }
 
-void
-InitConsoleDefaults(PConsoleInfo pConInfo)
+VOID
+ApplyConsoleInfo(HWND hwndDlg)
 {
-       /* Initialize struct */
-       pConInfo->InsertMode = TRUE;
-       pConInfo->HistoryBufferSize = 50;
-       pConInfo->NumberOfHistoryBuffers = 5;
-    pConInfo->ScreenText = RGB(192, 192, 192);
-       pConInfo->ScreenBackground = RGB(0, 0, 0);
-       pConInfo->PopupText = RGB(128, 0, 128);
-       pConInfo->PopupBackground = RGB(255, 255, 255);
-       pConInfo->WindowSize = (DWORD)MAKELONG(80, 25);
-       pConInfo->WindowPosition = UINT_MAX;
-       pConInfo->ScreenBuffer = MAKELONG(80, 300);
-       pConInfo->UseRasterFonts = TRUE;
-       pConInfo->FontSize = (DWORD)MAKELONG(8, 12);
-       pConInfo->FontWeight = FW_NORMAL;
-       memcpy(pConInfo->Colors, s_Colors, sizeof(s_Colors));
-}
+    static BOOL ConsoleInfoAlreadySaved = FALSE;
+
+    /*
+     * We already applied all the console properties (and saved if needed).
+     * Nothing more needs to be done.
+     */
+    if (ConsoleInfoAlreadySaved)
+        goto Done;
+
+    /*
+     * If we are setting the default parameters, just save them,
+     * otherwise display the confirmation & apply dialog.
+     */
+    if (ConInfo->hWnd == NULL)
+    {
+        SetConsoleInfo  = FALSE;
+        SaveConsoleInfo = TRUE;
+    }
+    else
+    {
+        INT_PTR res = DialogBoxW(hApplet, MAKEINTRESOURCEW(IDD_APPLYOPTIONS), hwndDlg, ApplyProc);
 
+        SetConsoleInfo  = (res != IDCANCEL);
+        SaveConsoleInfo = (res == IDC_RADIO_APPLY_ALL);
 
-INT_PTR
-CALLBACK
-ApplyProc(
-  HWND hwndDlg,
-  UINT uMsg,
-  WPARAM wParam,
-  LPARAM lParam
-)
-{
-       HWND hDlgCtrl;
-
-       UNREFERENCED_PARAMETER(lParam);
-
-       switch(uMsg)
-       {
-               case WM_INITDIALOG:
-               {
-                       hDlgCtrl = GetDlgItem(hwndDlg, IDC_RADIO_APPLY_CURRENT);
-                       SendMessage(hDlgCtrl, BM_SETCHECK, BST_CHECKED, 0);
-                       return TRUE;
-               }
-               case WM_COMMAND:
-               {
-                       if (LOWORD(wParam) == IDOK)
-                       {
-                               hDlgCtrl = GetDlgItem(hwndDlg, IDC_RADIO_APPLY_CURRENT);
-                               if ( SendMessage(hDlgCtrl, BM_GETCHECK, 0, 0) == BST_CHECKED )
-                                       EndDialog(hwndDlg, IDC_RADIO_APPLY_CURRENT);
-                               else
-                                       EndDialog(hwndDlg, IDC_RADIO_APPLY_ALL);
-                       }
-                       else if (LOWORD(wParam) == IDCANCEL)
-                       {
-                               EndDialog(hwndDlg, IDCANCEL);
-                       }
-                       break;
-               }
-               default:
-                       break;
-       }
-       return FALSE;
-
-}
+        if (SetConsoleInfo == FALSE)
+        {
+            /* Don't destroy when the user presses cancel */
+            SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, PSNRET_INVALID_NOCHANGEPAGE);
+            return;
+        }
+    }
 
-void
-ApplyConsoleInfo(HWND hwndDlg, PConsoleInfo pConInfo)
-{
-       INT_PTR res = 0;
-
-       res = DialogBox(hApplet, MAKEINTRESOURCE(IDD_APPLYOPTIONS), hwndDlg, ApplyProc);
-
-       if (res == IDCANCEL)
-       {
-               /* Don't destroy when user presses cancel */
-               SetWindowLongPtr(hwndDlg, DWL_MSGRESULT, PSNRET_INVALID_NOCHANGEPAGE);
-       }
-       else if ( res == IDC_RADIO_APPLY_ALL )
-       {
-               pConInfo->AppliedConfig = TRUE;
-               SetWindowLongPtr(hwndDlg, DWL_MSGRESULT, PSNRET_NOERROR);
-               SendMessage(pConInfo->hConsoleWindow, PM_APPLY_CONSOLE_INFO, (WPARAM)pConInfo, (LPARAM)TRUE);
-       }
-       else if ( res == IDC_RADIO_APPLY_CURRENT )
-       {
-               pConInfo->AppliedConfig = TRUE;
-               SetWindowLongPtr(hwndDlg, DWL_MSGRESULT, PSNRET_NOERROR);
-               SendMessage(pConInfo->hConsoleWindow, PM_APPLY_CONSOLE_INFO, (WPARAM)pConInfo, (LPARAM)TRUE);
-       }
+    /*
+     * We applied all the console properties (and saved if needed).
+     * Set the flag so that if this function is called again, we won't
+     * need to redo everything again.
+     */
+    ConsoleInfoAlreadySaved = TRUE;
+
+Done:
+    /* Options have been applied */
+    SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, PSNRET_NOERROR);
+    return;
 }
 
 /* First Applet */
-LONG APIENTRY
-InitApplet(HWND hwnd, UINT uMsg, LPARAM wParam, LPARAM lParam)
+static LONG
+APIENTRY
+InitApplet(HANDLE hSectionOrWnd)
 {
-       PROPSHEETPAGE psp[4];
-       PROPSHEETHEADER psh;
-       INT i=0;
-       PConsoleInfo pConInfo;
-       WCHAR szTitle[100];
-       PConsoleInfo pSharedInfo = (PConsoleInfo)wParam;
-
-       UNREFERENCED_PARAMETER(uMsg);
-
-       /*
-        * console.dll shares information with win32csr with wParam, lParam
-        *
-        * wParam is a pointer to a ConsoleInfo struct
-        * lParam is a boolean parameter which specifies whether defaults should be shown
-        */
-
-       pConInfo = AllocConsoleInfo();
-       if (!pConInfo)
-       {
-               return 0;
-       }
-
-       if (lParam)
-       {
-               /* Use defaults */
-               InitConsoleDefaults(pConInfo);
-       }
-       else
-       {
-               if (IsBadReadPtr((const void *)pSharedInfo, sizeof(ConsoleInfo)))
-               {
-                       /* Use defaults */
-                       InitConsoleDefaults(pConInfo);
-               }
-               else
-               {
-                       pConInfo->InsertMode = pSharedInfo->InsertMode;
-                       pConInfo->HistoryBufferSize = pSharedInfo->HistoryBufferSize;
-                       pConInfo->NumberOfHistoryBuffers = pSharedInfo->NumberOfHistoryBuffers;
-                       pConInfo->ScreenText = pSharedInfo->ScreenText;
-                       pConInfo->ScreenBackground =  pSharedInfo->ScreenBackground;
-                       pConInfo->PopupText = pSharedInfo->PopupText;
-                       pConInfo->PopupBackground = pSharedInfo->PopupBackground;
-                       pConInfo->WindowSize = pSharedInfo->WindowSize;
-                       pConInfo->WindowPosition = pSharedInfo->WindowPosition;
-                       pConInfo->ScreenBuffer = pSharedInfo->ScreenBuffer;
-                       pConInfo->UseRasterFonts = pSharedInfo->UseRasterFonts;
-                       pConInfo->FontSize = pSharedInfo->FontSize;
-                       pConInfo->FontWeight = pSharedInfo->FontWeight;
-                       memcpy(pConInfo->Colors, pSharedInfo->Colors, sizeof(s_Colors));
-               }
-       }
-
-       /* console window -> is notified on a property change event */
-       pConInfo->hConsoleWindow = hwnd;
-
-       ZeroMemory(&psh, sizeof(PROPSHEETHEADER));
-       psh.dwSize = sizeof(PROPSHEETHEADER);
-       psh.dwFlags =  PSH_PROPSHEETPAGE | PSH_NOAPPLYNOW;
-       if(_tcslen(pConInfo->szProcessName))
-       {
-               psh.dwFlags |= PSH_PROPTITLE;
-               psh.pszCaption = pConInfo->szProcessName;
-       }
-       else
-       {
-               if (!GetConsoleTitleW(szTitle, sizeof(szTitle)/sizeof(WCHAR)))
-               {
-                       _tcscpy(szTitle, _T("cmd.exe"));
-               }
-               szTitle[(sizeof(szTitle)/sizeof(WCHAR))-1] = _T('\0');
-               psh.pszCaption = szTitle;
-       }
-
-       psh.hwndParent = hwnd;
-       psh.hInstance = hApplet;
-       psh.hIcon = LoadIcon(hApplet, MAKEINTRESOURCE(IDC_CPLICON));
-       psh.nPages = 4;
-       psh.nStartPage = 0;
-       psh.ppsp = psp;
-
-       InitPropSheetPage(&psp[i++], IDD_PROPPAGEOPTIONS, (DLGPROC) OptionsProc, (LPARAM)pConInfo);
-       InitPropSheetPage(&psp[i++], IDD_PROPPAGEFONT, (DLGPROC) FontProc, (LPARAM)pConInfo);
-       InitPropSheetPage(&psp[i++], IDD_PROPPAGELAYOUT, (DLGPROC) LayoutProc, (LPARAM)pConInfo);
-       InitPropSheetPage(&psp[i++], IDD_PROPPAGECOLORS, (DLGPROC) ColorsProc, (LPARAM)pConInfo);
-
-       return (PropertySheet(&psh) != -1);
-}
+    INT_PTR Result;
+    PCONSOLE_STATE_INFO pSharedInfo = NULL;
+    WCHAR szTitle[MAX_PATH + 1];
+    PROPSHEETPAGEW psp[4];
+    PROPSHEETHEADERW psh;
+    INT i = 0;
+
+    /*
+     * Because of Windows compatibility, we need to behave the same concerning
+     * information sharing with CONSRV. For some obscure reason the designers
+     * decided to use the CPlApplet hWnd parameter as being either a handle to
+     * the applet's parent caller's window (in case we ask for displaying
+     * the global console settings), or a handle to a shared section holding
+     * a CONSOLE_STATE_INFO structure (they don't use the extra l/wParams).
+     */
+
+    /*
+     * Try to open the shared section via the handle parameter. If we succeed,
+     * it means we were called by CONSRV for retrieving/setting parameters for
+     * a given console. If we fail, it means we are retrieving/setting default
+     * global parameters (and we were either called by CONSRV or directly by
+     * the user via the Control Panel, etc...)
+     */
+    pSharedInfo = MapViewOfFile(hSectionOrWnd, FILE_MAP_READ, 0, 0, 0);
+    if (pSharedInfo != NULL)
+    {
+        /*
+         * We succeeded. We were called by CONSRV and are retrieving
+         * parameters for a given console.
+         */
+
+        /* Copy the shared data into our allocated buffer */
+        DPRINT1("pSharedInfo->cbSize == %lu ; sizeof(CONSOLE_STATE_INFO) == %u\n",
+                pSharedInfo->cbSize, sizeof(CONSOLE_STATE_INFO));
+        ASSERT(pSharedInfo->cbSize >= sizeof(CONSOLE_STATE_INFO));
+
+        /* Allocate a local buffer to hold console information */
+        ConInfo = HeapAlloc(GetProcessHeap(),
+                            HEAP_ZERO_MEMORY,
+                            pSharedInfo->cbSize);
+        if (ConInfo)
+            RtlCopyMemory(ConInfo, pSharedInfo, pSharedInfo->cbSize);
+
+        /* Close the section */
+        UnmapViewOfFile(pSharedInfo);
+        CloseHandle(hSectionOrWnd);
+
+        if (!ConInfo) return 0;
+    }
+    else
+    {
+        /*
+         * We failed. We are retrieving the default global parameters.
+         */
+
+        /* Allocate a local buffer to hold console information */
+        ConInfo = HeapAlloc(GetProcessHeap(),
+                            HEAP_ZERO_MEMORY,
+                            sizeof(CONSOLE_STATE_INFO));
+        if (!ConInfo) return 0;
+
+        /*
+         * Setting the console window handle to NULL indicates we are
+         * retrieving/setting the default console parameters.
+         */
+        ConInfo->hWnd = NULL;
+        ConInfo->ConsoleTitle[0] = UNICODE_NULL;
+
+        /* Use defaults */
+        InitDefaultConsoleInfo(ConInfo);
+    }
 
-/* Control Panel Callback */
-LONG CALLBACK
-CPlApplet(
-       HWND hwndCPl,
-       UINT uMsg,
-       LPARAM lParam1,
-       LPARAM lParam2)
-{
-  switch(uMsg)
-  {
-    case CPL_INIT:
+    /* Initialize the font support */
+    hCurrentFont = CreateConsoleFont(ConInfo);
+    if (hCurrentFont == NULL)
+        DPRINT1("InitApplet: CreateConsoleFont failed\n");
+
+    /* Initialize the property sheet structure */
+    ZeroMemory(&psh, sizeof(psh));
+    psh.dwSize = sizeof(psh);
+    psh.dwFlags = PSH_PROPSHEETPAGE | PSH_PROPTITLE | /* PSH_USEHICON */ PSH_USEICONID | PSH_NOAPPLYNOW;
+
+    if (ConInfo->ConsoleTitle[0] != UNICODE_NULL)
+    {
+        wcsncpy(szTitle, L"\"", MAX_PATH);
+        wcsncat(szTitle, ConInfo->ConsoleTitle, MAX_PATH - wcslen(szTitle));
+        wcsncat(szTitle, L"\"", MAX_PATH - wcslen(szTitle));
+    }
+    else
+    {
+        wcscpy(szTitle, L"ReactOS Console");
+    }
+    psh.pszCaption = szTitle;
+
+    if (pSharedInfo != NULL)
     {
-      return TRUE;
+        /* We were started from a console window: this is our parent (or ConInfo->hWnd is NULL) */
+        psh.hwndParent = ConInfo->hWnd;
     }
-    case CPL_GETCOUNT:
+    else
     {
-      return NUM_APPLETS;
+        /* We were started in another way (--> default parameters). Caller's window is our parent. */
+        psh.hwndParent = (HWND)hSectionOrWnd;
     }
-    case CPL_INQUIRE:
+
+    psh.hInstance = hApplet;
+    // psh.hIcon = LoadIcon(hApplet, MAKEINTRESOURCEW(IDC_CPLICON));
+    psh.pszIcon = MAKEINTRESOURCEW(IDC_CPLICON);
+    psh.nPages = ARRAYSIZE(psp);
+    psh.nStartPage = 0;
+    psh.ppsp = psp;
+
+    InitPropSheetPage(&psp[i++], IDD_PROPPAGEOPTIONS, OptionsProc);
+    InitPropSheetPage(&psp[i++], IDD_PROPPAGEFONT   , FontProc   );
+    InitPropSheetPage(&psp[i++], IDD_PROPPAGELAYOUT , LayoutProc );
+    InitPropSheetPage(&psp[i++], IDD_PROPPAGECOLORS , ColorsProc );
+
+    /* Display the property sheet */
+    RegisterWinPrevClass(hApplet);
+    Result = PropertySheetW(&psh);
+    UnRegisterWinPrevClass(hApplet);
+
+    /* First cleanup */
+    if (hCurrentFont) DeleteObject(hCurrentFont);
+    hCurrentFont = NULL;
+
+    /* Save the console settings */
+    if (SetConsoleInfo)
     {
-      CPLINFO *CPlInfo = (CPLINFO*)lParam2;
-      CPlInfo->idIcon = Applets[0].idIcon;
-      CPlInfo->idName = Applets[0].idName;
-      CPlInfo->idInfo = Applets[0].idDescription;
-      break;
+        HANDLE hSection;
+
+        /*
+         * Create a memory section to share with CONSRV, and map it.
+         */
+        hSection = CreateFileMappingW(INVALID_HANDLE_VALUE,
+                                      NULL,
+                                      PAGE_READWRITE,
+                                      0,
+                                      ConInfo->cbSize,
+                                      NULL);
+        if (!hSection)
+        {
+            DPRINT1("Error when creating file mapping, error = %d\n", GetLastError());
+            goto Quit;
+        }
+
+        pSharedInfo = MapViewOfFile(hSection, FILE_MAP_ALL_ACCESS, 0, 0, 0);
+        if (!pSharedInfo)
+        {
+            DPRINT1("Error when mapping view of file, error = %d\n", GetLastError());
+            CloseHandle(hSection);
+            goto Quit;
+        }
+
+        /* Copy the console information into the section */
+        RtlCopyMemory(pSharedInfo, ConInfo, ConInfo->cbSize);
+
+        /* Unmap it */
+        UnmapViewOfFile(pSharedInfo);
+
+        /* Signal to CONSRV that it can apply the new configuration */
+        SendMessageW(ConInfo->hWnd, WM_SETCONSOLEINFO, (WPARAM)hSection, 0);
+
+        /* Close the section and return */
+        CloseHandle(hSection);
     }
-    case CPL_DBLCLK:
+
+    if (SaveConsoleInfo)
     {
-      InitApplet(hwndCPl, uMsg, lParam1, lParam2);
-      break;
+        /* Default settings saved when ConInfo->hWnd == NULL */
+        ConCfgWriteUserSettings(ConInfo, ConInfo->hWnd == NULL);
     }
-  }
-  return FALSE;
+
+Quit:
+    /* Cleanup */
+    HeapFree(GetProcessHeap(), 0, ConInfo);
+    ConInfo = NULL;
+
+    return (Result != -1);
 }
 
+/* Control Panel Callback */
+LONG
+CALLBACK
+CPlApplet(HWND hwndCPl,
+          UINT uMsg,
+          LPARAM lParam1,
+          LPARAM lParam2)
+{
+    switch (uMsg)
+    {
+        case CPL_INIT:
+            return TRUE;
+
+        case CPL_EXIT:
+            // TODO: Free allocated memory
+            break;
+
+        case CPL_GETCOUNT:
+            return 1;
+
+        case CPL_INQUIRE:
+        {
+            CPLINFO *CPlInfo = (CPLINFO*)lParam2;
+            CPlInfo->idIcon  = IDC_CPLICON;
+            CPlInfo->idName  = IDS_CPLNAME;
+            CPlInfo->idInfo  = IDS_CPLDESCRIPTION;
+            break;
+        }
+
+        case CPL_DBLCLK:
+            InitApplet((HANDLE)hwndCPl);
+            break;
+    }
+
+    return FALSE;
+}
 
 INT
 WINAPI
-DllMain(
-       HINSTANCE hinstDLL,
-       DWORD     dwReason,
-       LPVOID    lpvReserved)
+DllMain(HINSTANCE hinstDLL,
+        DWORD     dwReason,
+        LPVOID    lpvReserved)
 {
-  UNREFERENCED_PARAMETER(lpvReserved);
-
-  switch(dwReason)
-  {
-    case DLL_PROCESS_ATTACH:
-    case DLL_THREAD_ATTACH:
-      hApplet = hinstDLL;
-      break;
-  }
-  return TRUE;
+    UNREFERENCED_PARAMETER(lpvReserved);
+
+    switch (dwReason)
+    {
+        case DLL_PROCESS_ATTACH:
+            hApplet = hinstDLL;
+            DisableThreadLibraryCalls(hinstDLL);
+            break;
+    }
+
+    return TRUE;
 }