summaryrefslogtreecommitdiff
path: root/exip/main.cpp
blob: a7753e1c5161fba9c49e334ae87621d611ae769e (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
#include "common.h"
#include "options.h"
#include "getip.h"

HINSTANCE hInst;
PLUGINLINK *pluginLink;

HANDLE hNetlibUser = 0;
HANDLE mainThread;

// plugin stuff
PLUGININFO pluginInfo={
	sizeof(PLUGININFO),
	"ExIP",
	PLUGIN_MAKE_VERSION(0, 0, 0, 1),
	"Retreive external IP address",
	"Scott Ellis",
	"mail@scottellis.com.au",
	"© 2005 Scott Ellis",
	"http://www.scottellis.com.au/",
	0,		//not transient
	0		//doesn't replace anything built-in
};

BOOL WINAPI DllMain(HINSTANCE hinstDLL,DWORD fdwReason,LPVOID lpvReserved)
{
	hInst=hinstDLL;
	return TRUE;
}

extern "C" __declspec(dllexport) PLUGININFO* MirandaPluginInfo(DWORD mirandaVersion)
{
	return &pluginInfo;
}





unsigned long __stdcall GetIPThread(void *param) {
	RetreiveIP();
	return 0;
}

/*
bool power_message = false;
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	PAINTSTRUCT ps;
	HDC hdc;

	switch (message) 
	{
		case WM_COMMAND:
			break;
		case WM_PAINT:
			hdc = BeginPaint(hWnd, &ps);
			// TODO: Add any drawing code here...
			RECT rt;
			GetClientRect(hWnd, &rt);
			if(power_message)
				DrawText(hdc, "Power message!", strlen("Power message!"), &rt, DT_CENTER);
			else
				DrawText(hdc, "Hello world!", strlen("Hello world!"), &rt, DT_CENTER);
			EndPaint(hWnd, &ps);
			break;
		case WM_DESTROY:
		case WM_CLOSE:
			DestroyWindow(hWnd);
			break;

		case WM_POWERBROADCAST:
			power_message = true;
			InvalidateRect(hWnd, 0, TRUE);
			break;


		default:
			return DefWindowProc(hWnd, message, wParam, lParam);
   }
   return 0;
}


ATOM MyRegisterClass(HINSTANCE hInstance)
{
	WNDCLASSEX wcex;

	wcex.cbSize = sizeof(WNDCLASSEX); 

	wcex.style			= CS_HREDRAW | CS_VREDRAW;
	wcex.lpfnWndProc	= (WNDPROC)WndProc;
	wcex.cbClsExtra		= 0;
	wcex.cbWndExtra		= 0;
	wcex.hInstance		= hInstance;
	wcex.hIcon			= 0; //LoadIcon(hInstance, (LPCTSTR)IDI_SCREENDUMP);
	wcex.hCursor		= LoadCursor(NULL, IDC_ARROW);
	wcex.hbrBackground	= (HBRUSH)(COLOR_WINDOW+1);
	wcex.lpszMenuName	= 0;//(LPCSTR)IDC_SCREENDUMP;
	wcex.lpszClassName	= "TestPowerMessagesWindowClass";
	wcex.hIconSm		= 0;//LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);

	return RegisterClassEx(&wcex);
}

DWORD CALLBACK MessagePumpThread(LPVOID param) {
	CallService(MS_SYSTEM_THREAD_PUSH, 0, 0);

	MyRegisterClass(hInst);

	HWND hWnd = CreateWindow("TestPowerMessagesWindowClass", "Test", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInst, NULL);
	ShowWindow(hWnd, SW_SHOW);
	UpdateWindow(hWnd);

	MSG msg;
	// GetMessage returns -1 when hwndProgress is an invalid handle - so it exits when that window is destroyed
	while(GetMessage(&msg, hWnd, 0, 0) > 0 && !Miranda_Terminated()) {
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}
	
	CallService(MS_SYSTEM_THREAD_POP, 0, 0);
	return 0;
}
*/

int OnModulesLoaded(WPARAM wParam, LPARAM lParam) {

	NETLIBUSER nl_user = {0};
	nl_user.cbSize = sizeof(nl_user);
	nl_user.szSettingsModule = MODULE;
	nl_user.szDescriptiveName = "External IP";
	nl_user.flags = NUF_OUTGOING | NUF_HTTPCONNS;

	hNetlibUser = (HANDLE)CallService(MS_NETLIB_REGISTERUSER, 0, (LPARAM)&nl_user);

	DWORD tid;
	CloseHandle(CreateThread(0, 0, GetIPThread, 0, 0, &tid));

	//CloseHandle(CreateThread(0, 0, MessagePumpThread, 0, 0, &tid));

	return 0;
}

extern "C" __declspec(dllexport) int Load(PLUGINLINK *link)
{
	pluginLink=link;
	DuplicateHandle( GetCurrentProcess(), GetCurrentThread(), GetCurrentProcess(), &mainThread, THREAD_SET_CONTEXT, FALSE, 0 );

	HookEvent(ME_SYSTEM_MODULESLOADED, OnModulesLoaded);	

	HookEvent(ME_OPT_INITIALISE, OptInit );

	return 0;
}

extern "C" __declspec(dllexport) int Unload(void)
{
	CallService(MS_NETLIB_CLOSEHANDLE, (WPARAM)hNetlibUser, 0);
	return 0;
}