Back to index

lightning-sunbird  0.9+nobinonly
mapiipc.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 //
00038 //  MAPI IPC Routines
00039 //  Written by: Rich Pizzarro (rhp@netscape.com)
00040 //  November 1997
00041 //
00042 #include <windows.h>
00043 #include <windowsx.h>
00044 #include <nscpmapi.h>   // Should live in Communicator
00045 
00046 #include "resource.h"
00047 #include "mapiipc.h"
00048 #include "mapismem.h"
00049 #include "trace.h"
00050 
00051 #ifndef WIN32
00052 #include <string.h>
00053 #endif 
00054 
00055 //
00056 // Necessary variables...
00057 //
00058 static LONG       instanceCount = 0;
00059 HWND                              hWndMAPI = NULL;
00060 char                              szClassName[] = "NetscapeMAPIClient";
00061 char              szWindowName[] = "NetscapeMAPI";
00062 
00063 //
00064 // External declares...
00065 //
00066 extern HINSTANCE  hInstance;
00067 
00068 void 
00069 ProcessCommand(HWND hWnd, int id, HWND hCtl, UINT codeNotify) 
00070 { 
00071        switch (id) 
00072        {
00073        case IDOK:   
00074        case IDCANCEL:
00075               {
00076                      ShowWindow(hWnd, SW_HIDE);
00077               }
00078               
00079        default:
00080               ;
00081        }
00082 }
00083 
00084 BOOL CALLBACK LOADDS 
00085 MyDlgProc(HWND hWndMain, UINT wMsg, WPARAM wParam, LPARAM lParam) 
00086 {
00087   switch (wMsg) 
00088   {
00089   case WM_INITDIALOG: 
00090     {
00091       hWndMAPI = hWndMain;
00092     }
00093     break;
00094     
00095   case WM_CLOSE:
00096 //    DestroyWindow(hWndMain);
00097     break;
00098     
00099   case WM_DESTROY:
00100     hWndMain = NULL;
00101     break;
00102 
00103   case WM_COMMAND:
00104          HANDLE_WM_COMMAND(hWndMAPI, wParam, lParam, ProcessCommand);
00105     break;
00106 
00107   default:
00108     return FALSE;
00109   }
00110 
00111   return TRUE;
00112 }
00113 
00114 BOOL 
00115 InitInstance(HINSTANCE hInstance)
00116 {
00117   //
00118   // Create a main window for this application instance.  
00119   //
00120   /* RICHIE - TRY SOME CHANGES!!!
00121   hWndMAPI = CreateDialog((HINSTANCE) hInstance, 
00122         MAKEINTRESOURCE(ID_DIALOG_QAHOOK),
00123         (HWND) NULL, (DLGPROC) MyDlgProc);
00124    ******/
00125   hWndMAPI = CreateWindow(
00126               szClassName,  // pointer to registered class name
00127               szWindowName, // pointer to window name
00128               WS_CHILD,         // window style
00129               -10,                 // horizontal position of window
00130               -10,             // vertical position of window
00131               1,               // window width
00132               1,               // window height
00133               GetDesktopWindow(),  // handle to parent or owner window
00134               NULL,          // handle to menu or child-window identifier
00135               hInstance,      // handle to application instance
00136               NULL          // pointer to window-creation data
00137               );
00138   if (!hWndMAPI)
00139     return FALSE;
00140   else
00141     return TRUE;
00142 }
00143 
00144 BOOL 
00145 InitApp(void)
00146 {
00147 #ifdef WIN32
00148   WNDCLASS wc;
00149   wc.style         = 0; 
00150   wc.lpfnWndProc   = DefDlgProc; 
00151   wc.cbClsExtra    = 0; 
00152   wc.cbWndExtra    = DLGWINDOWEXTRA; 
00153   wc.hInstance     = hInstance; 
00154   wc.hIcon         = LoadIcon(hInstance, MAKEINTRESOURCE(ID_ICON_APP)); 
00155   wc.hCursor       = LoadCursor(0, IDC_ARROW); 
00156   wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
00157   wc.lpszMenuName  = NULL; 
00158   wc.lpszClassName = szClassName;
00159   
00160   if(!RegisterClass(&wc))
00161     return FALSE;
00162 #endif
00163   
00164   return TRUE;
00165 } // end InitApp
00166 
00167 BOOL
00168 InitDLL(void)
00169 {
00170   if (hWndMAPI != NULL)
00171     return TRUE;
00172 
00173   if (!InitApp()) 
00174   { 
00175     return FALSE;
00176   }
00177   
00178   if (!InitInstance(hInstance)) 
00179   {    
00180     return FALSE;
00181   }
00182   
00183 //  ShowWindow(hWndMAPI, SW_SHOW);    Just for jollies
00184   return(TRUE);
00185 }
00186 
00187 //*************************************************************
00188 //* Calls exposed for rest of DLL...
00189 //*************************************************************
00190 //
00191 // Purpose: Open the API
00192 // Return: 1 on success
00193 //         0 on failure
00194 //
00195 DWORD nsMAPI_OpenAPI(void)
00196 {
00197   if (instanceCount > 0)
00198   {
00199     return(1);
00200   }
00201 
00202   ++instanceCount;
00203   return(1);
00204 }
00205 
00206 //
00207 // Purpose: Close the API
00208 //
00209 void nsMAPI_CloseAPI(void)
00210 {
00211   --instanceCount;
00212   if (instanceCount <= 0)
00213   {
00214     instanceCount = 0;
00215   }
00216 
00217   return;
00218 }
00219 
00220 //
00221 // Send the actual request to Communicator
00222 //
00223 LRESULT
00224 SendMAPIRequest(HWND hWnd, 
00225                 DWORD mapiRequestID, 
00226                 MAPIIPCType *ipcInfo)
00227 {
00228 LRESULT         returnVal = 0;
00229 COPYDATASTRUCT  cds;
00230 
00231   if (!InitDLL())
00232   {
00233     return 0;
00234   }
00235 
00236   cds.dwData = mapiRequestID;
00237   cds.cbData = sizeof(MAPIIPCType);
00238   cds.lpData = ipcInfo;
00239 
00240   // Make the call into Communicator
00241   returnVal = SendMessage(hWnd, WM_COPYDATA, (WPARAM) hWndMAPI, (LPARAM) &cds);
00242 
00243   // Now kill the window...
00244   DestroyWindow(hWndMAPI);
00245   hWndMAPI = NULL;
00246   UnregisterClass(szClassName, hInstance);
00247   
00248   return returnVal;
00249 }