#ifdef USERLOG_EXPORTS
#define USERLOG_API __declspec(dllexport)
#else
#define USERLOG_API __declspec(dllimport)
#endif

#include <iostream>
#include <fstream>



//#define __USING_MTRACE__
#define __USING_COSTUMLOG__
#define __INCLUDEHOOKINFO__
//#define __TIMING__
#define __ENCODE_BASE64__

#define LOGPREFIX " UL: "
#define LOGPREFIXCONT " ULC: "
#define LOGPREFIXWSTRING L" UL: "

#define NUMHOOKS 2

#define CALLWNDHOOKID 0
#define GETMSGHOOKID 1

#ifdef __USING_COSTUMLOG__
#define LOGFILE "usagelog.txt"
#endif

typedef struct _HOOKDATA {
	int nType;
	HOOKPROC hkproc;
	HHOOK hookhandle;
	bool active;
} HOOKDATA;

HOOKDATA myhookdata[NUMHOOKS];

#ifdef __cplusplus
extern "C" {
#endif

/**
 * API function that starts the logging of messages. 
 * All required hooks and logging mechanisms are initialized. 
 */
USERLOG_API void __cdecl InitUsagelog();

/**
 * API function that stopts the logging of messages. 
 * All existing hooks are released and if required, logging mechnisms are stopped.
 */
USERLOG_API void __cdecl ReleaseUsagelog();

#ifdef __cplusplus
} // extern "C"
#endif


void InitHookdata();

void InitHooks();

void ReleaseHooks();


LRESULT CALLBACK CallWndProc(int nCode, WPARAM wParam, LPARAM lParam);

LRESULT CALLBACK GetMsgProc(int nCode, WPARAM wParam, LPARAM lParam);

void HookProc(int nFrom, int nCode, PMSG msg);

/**
 * Compares two messages parameter-wise. 
 * TODO: Check if this works better, if MSG.time and MSG.pt are ignored in the comparison, as they are missing in CWPSTRUCT.
 * TODO: In case of CWPSTRICT both values are per default -1. 
 */
bool MessageEquals(const MSG & msg1, const MSG & msg2);

void WriteLogentryWString(PMSG msg, int nFrom);

int replaceWithXmlEntitiesWString(const wchar_t * source, wchar_t ** target, size_t sourceLength);

#ifdef __USING_COSTUMLOG__
void InitLogfile();

void CloseLogfile();
#endif