summaryrefslogtreecommitdiff
path: root/plugins/MirandaG15/src/Miranda.cpp
blob: 6776c397ef3b183abaf761757beeeddc257f414b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223

/*
 * Miranda IM LCD Plugin
 * Displays incoming text messages on an LCD.
 *
 * Copyright (c) 2003 Martin Rubli, mrubli@gmx.net
 *
 ******************************************************************************
 * This file is part of Miranda IM LCD Plugin.
 *
 * Miranda IM LCD Plugin is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as published
 * by the Free Software Foundation; either version 2 of the License, or (at
 * your option) any later version.
 *
 * Miranda IM LCD Plugin is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
 * Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with Miranda IM LCD Plugin; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 ******************************************************************************
 *
 * Miranda.cpp: Miranda plugin initialisation
 */

/*
 * TODO:

*/
/*
 * CHANGES:
 */
/*
 * KNOWN BUGS:
 *
 */

/*
 * IDEAS:
 *
 */

#ifdef _DEBUG
	#include <crtdbg.h>
	#define _CRTDBG_MAP_ALLOC
#endif

#include "StdAfx.h"

#include "CAppletManager.h"
#include "CConfig.h"

#include "m_system.h"

// SETTINGS
#define LCD_FPS 10

//************************************************************************
// Variables
//************************************************************************
bool g_bInitialized;
bool g_bUnicode;
// AppletManager object
 CAppletManager* g_AppletManager;

// Plugin Information

HINSTANCE hInstance;
int hLangpack;

// Initialization Hook
static HANDLE hMIHookModulesLoaded;

// {58D63981-14C1-4099-A3F7-F4FAA4C8FC59}
#define MIID_G15APPLET	{ 0x58d63981, 0x14c1, 0x4099, { 0xa3, 0xf7, 0xf4, 0xfa, 0xa4, 0xc8, 0xfc, 0x59 } }

static const MUUID interfaces[] = {MIID_G15APPLET, MIID_LAST};
	
static PLUGININFOEX pluginInfo = {
	sizeof(PLUGININFOEX),
	APP_NAME,
	PLUGIN_MAKE_VERSION(0,1,2,0),
	"Provides an interface to use Miranda from the LCD of various Logitech devices",
	"Martin Kleinhans",
	"mail@mkleinhans.de",
	"© 2009 Martin Kleinhans",
	"http://www.mkleinhans.de",
	0,		// not transient
	// {798221E1-E47A-4dc8-9077-1E576F9C4307}
	{ 0x798221e1, 0xe47a, 0x4dc8, { 0x90, 0x77, 0x1e, 0x57, 0x6f, 0x9c, 0x43, 0x7 } }
};

// Function Prototypes
int Init(WPARAM,LPARAM);
void UnInit();



//************************************************************************
// Exported Functions
//************************************************************************
extern "C" {
	__declspec(dllexport) const MUUID * MirandaPluginInterfaces(void)
	{
		return interfaces;
	}

	__declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD mirandaVersion)
	{
		// Are we running under Unicode Windows version ?
		g_bUnicode = (GetVersion() & 0x80000000) == 0;
		if (g_bUnicode) {
		  pluginInfo.flags = 1; // UNICODE_AWARE
		}
		return &pluginInfo;
	}
	
	
	// Called by Miranda to load the plugin.
	// We defer initialization until Miranda's module loading process completed and return 0 to
	// mark success, everything else will cause the plugin to be freed right away.
	int __declspec(dllexport) Load()
	{
		g_bInitialized = false;
		InitDebug();
		TRACE(_T("Plugin loaded\n"));
		// Schedule actual initialization for later
		// (We don't really need the handle but want to be able to release it properly later ...)
		hMIHookModulesLoaded = HookEvent(ME_SYSTEM_MODULESLOADED, Init);
		if(hMIHookModulesLoaded == 0)
		{
			tstring text = _T("Failed to initialize the Applet.\nThe plugin will not be loaded. ");
			tstring title = _T(APP_SHORTNAME);
			MessageBox(NULL, text.c_str(), title.c_str(), MB_OK | MB_ICONEXCLAMATION);
			return 1;
		}
		return 0;
	}

	// Called by Miranda when the plugin should unload itself.
	int __declspec(dllexport) Unload(void)
	{
		if(!g_bInitialized) {
			TRACE(_T("ERROR: Unload requested, but plugin is not initialized?!\n"));		
			return 0;
		}
		TRACE(_T("-------------------------------------------\nUnloading started\n"));
		UnInit();
		TRACE(_T("Unloading successful\n"));
		TRACE(_T("Cleaning up: "));
		UnhookEvent(hMIHookModulesLoaded);			// just to be really correct ...
		UnInitDebug();
		TRACE(_T("OK!\n"));
		return 0;
	}
}

//************************************************************************
// DllMain
//
// EntryPoint of the DLL
//************************************************************************
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
	
	hInstance = hinstDLL;
	return TRUE;
}

//************************************************************************
// Init
//
// Called after Miranda has finished loading all modules
// This is where the main plugin initialization happens and the
// connection to the LCD is established,
//************************************************************************
int Init(WPARAM wParam,LPARAM lParam)
{
	g_AppletManager = new CAppletManager();
	// Memoryleak Detection
	#ifdef _DEBUG
		_CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
		
	#endif
	
	 // set up the LCD context as non-autostart, non-persist, callbacked
	CConfig::Initialize();

	// Initialize the output object
    if(!g_AppletManager->Initialize(toTstring(APP_SHORTNAME)))
	{
		if(CConfig::GetBoolSetting(SKIP_DRIVER_ERROR)) {
			tstring text = _T("Failed to initialize the LCD connection\n Make sure you have the newest Logitech drivers installed (>=1.03).\n");
			tstring title = _T(APP_SHORTNAME);
			MessageBox(NULL, text.c_str(), title.c_str(), MB_OK | MB_ICONEXCLAMATION);
		}
		
		TRACE(_T("Initialization failed!.\n"));
		return 0;
	}
	
	g_bInitialized = true;
	TRACE(_T("Initialization completed successfully.\n-------------------------------------------\n"));
	return 0;
}
//************************************************************************
// UnInit
//
// Called when the plugin is about to be unloaded
//************************************************************************
void UnInit(void)
{
	g_AppletManager->Shutdown();	
	delete g_AppletManager;
	UnhookEvent(hMIHookModulesLoaded);
	
//#ifdef _DEBUG
//	_CrtDumpMemoryLeaks();
//#endif
}