-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.c
89 lines (70 loc) · 1.81 KB
/
main.c
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
//? Marius Negrutiu ([email protected]) :: 2013/06/07
#include "main.h"
// Global variables
HINSTANCE g_hModule = NULL;
// Notifications
extern VOID UtilsUnload();
// NSIS plugin API
extra_parameters *g_ep = NULL;
HWND g_hwndparent = NULL;
//++ DllMain
BOOL WINAPI DllMain(
HINSTANCE hInst,
ULONG ul_reason_for_call,
LPVOID lpReserved
)
{
if ( ul_reason_for_call == DLL_PROCESS_ATTACH ) {
g_hModule = hInst;
CoInitialize( NULL );
} else if ( ul_reason_for_call == DLL_PROCESS_DETACH ) {
UtilsUnload();
g_hModule = NULL;
CoUninitialize();
}
return TRUE;
}
//+ PluginCallback
UINT_PTR __cdecl PluginCallback( enum NSPIM iMessage )
{
switch ( iMessage )
{
case NSPIM_UNLOAD:
DebugString( _T( "NSPIM_UNLOAD\n" ) );
//x UtilsUnload(); // DLL_PROCESS_DETACH will handle this
break;
case NSPIM_GUIUNLOAD:
DebugString( _T( "NSPIM_GUIUNLOAD\n" ) );
break;
}
return 0;
}
//+ MyStrFind
/// Finds the first occurrence of a substring in a string
/// E.g. MyStrFind( L"aaabbbcccbbb", L"bbb" ) returns pointer to L"bbbcccbbb"
/// If no match is found, NULL is returned
LPCTSTR MyStrFind( _In_ LPCTSTR pszStr, _In_ LPCTSTR pszSubstr, _In_ BOOL bMatchCase )
{
LPCTSTR psz;
if ( pszStr && *pszStr && pszSubstr && *pszSubstr ) {
int iSubstrLen = lstrlen( pszSubstr );
for (psz = pszStr; *psz; psz++)
if (CompareString( LOCALE_USER_DEFAULT, (bMatchCase ? 0 : NORM_IGNORECASE), psz, (int)iSubstrLen, pszSubstr, (int)iSubstrLen ) == CSTR_EQUAL)
return psz;
}
return NULL;
}
//+ DebugString
#if _DEBUG || DBG
VOID DebugString( _In_ LPCTSTR pszFormat, _In_opt_ ... )
{
if (pszFormat && *pszFormat) {
TCHAR szStr[1024]; /// Enough? Dynamic?
va_list args;
va_start( args, pszFormat );
wvsprintf( szStr, pszFormat, args );
va_end( args );
OutputDebugString( szStr );
}
}
#endif