2 * Copyright (c) 2006 Secure Endpoints Inc.
4 * Permission is hereby granted, free of charge, to any person
5 * obtaining a copy of this software and associated documentation
6 * files (the "Software"), to deal in the Software without
7 * restriction, including without limitation the rights to use, copy,
8 * modify, merge, publish, distribute, sublicense, and/or sell copies
9 * of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29 /* This file provides the entry points for the module. The purpose of
30 each entry point is explained below.
33 kmm_module h_khModule; /* KMM's handle to this module */
34 HINSTANCE hInstance; /* handle to our DLL */
35 HMODULE hResModule; /* handle to DLL containing language specific resources */
37 const wchar_t * my_facility = MYPLUGIN_FACILITYW;
39 /* locales and n_locales are used to provide information to NetIDMgr
40 about the locales that we support. Each locale that is supported
41 is represented by a single line below. NetIDMgr will pick a
42 suitable locale from this list as described in the documentation
43 for kmm_set_locale_info(). */
44 kmm_module_locale locales[] = {
46 /* there needs to be at least one language that is supported.
47 Here we declare that to be US English, and make it the
49 LOCALE_DEF(MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US),
50 MYPLUGIN_DLLBASEW L"_en_us.dll", /* this is the name of
58 KMM_MLOC_FLAG_DEFAULT)
60 int n_locales = ARRAYLENGTH(locales);
62 /*******************************************************************
64 *****************************************************************
66 This is the entry point for the module. Each module can provide
67 multiple plugins and each plugin will need a separate entry point.
68 Generally, the module entry point will set up localized resources
69 and register the plugins.
72 KHMEXP khm_int32 KHMAPI init_module(kmm_module h_module) {
74 khm_int32 rv = KHM_ERROR_SUCCESS;
76 wchar_t description[KMM_MAXCCH_DESC];
79 h_khModule = h_module;
81 rv = kmm_set_locale_info(h_module, locales, n_locales);
82 if(KHM_SUCCEEDED(rv)) {
83 /* if the call succeeded, then NetIDMgr has picked a localized
84 resource DLL for us to use. */
85 hResModule = kmm_get_resource_hmodule(h_module);
89 /* TODO: Perform any other required initialization operations. */
91 /* register our plugin */
92 ZeroMemory(&pi, sizeof(pi));
94 pi.name = MYPLUGIN_NAMEW;
95 pi.type = KHM_PITYPE_MISC;
97 /* An icon is optional, but we provide one anyway. */
98 pi.icon = LoadImage(hResModule, MAKEINTRESOURCE(IDI_PLUGIN),
99 IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR | LR_DEFAULTSIZE);
101 pi.msg_proc = plugin_msg_proc;
102 pi.description = description;
103 pi.dependencies = L"AfsCred\0";
104 t = LoadString(hResModule, IDS_PLUGIN_DESC,
105 description, ARRAYLENGTH(description));
107 description[0] = L'\0';
109 description[ARRAYLENGTH(description) - 1] = L'\0';
111 rv = kmm_provide_plugin(h_module, &pi);
113 /* TODO: register any additional plugins */
115 /* Returning a successful code (KHM_ERROR_SUCCESS) will cause the
116 plugins to be initialized. If no plugin is successfully
117 registered while processing init_module or if a code other than
118 KHM_ERROR_SUCCESS is returned, the module will be immediately
125 /**********************************************************
127 ********************************************************
129 Called by the NetIDMgr module manager when unloading the module.
130 This will get called even if the module is being unloaded due to an
131 error code returned by init_module(). This callback is required. */
132 KHMEXP khm_int32 KHMAPI exit_module(kmm_module h_module) {
134 /* Unregistering the plugin is not required at this point. */
136 /* TODO: Perform any other required cleanup here. */
138 return KHM_ERROR_SUCCESS; /* the return code is ignored */
141 /* General DLL initialization. It is advisable to not do anything
142 here and also keep in mind that the plugin will be loaded at a time
143 where some threads have already started. So DLL_THREAD_ATTACH will
144 not fire for every thread. In addition, the plugin will be
145 unloaded before the application and all the threads terminate. */
146 BOOL WINAPI DllMain(HINSTANCE hinstDLL,
151 case DLL_PROCESS_ATTACH:
152 hInstance = hinstDLL;
155 case DLL_PROCESS_DETACH:
158 case DLL_THREAD_ATTACH:
161 case DLL_THREAD_DETACH: