summaryrefslogtreecommitdiff
path: root/plugins/LotusNotify/src/debug.cpp
blob: e814d6f508464fefe0334dbd443b27af38ccc855 (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
#include "stdafx.h"
#include "debug.h"

HNETLIBUSER netlibHandle;

void logRegister(){
	// Register netlib user for logging function
	NETLIBUSER nlu = {};
	nlu.flags = NUF_UNICODE | NUF_NOOPTIONS;
	nlu.szSettingsModule = PLUGINNAME;
	nlu.ptszDescriptiveName = mir_a2u(PLUGINNAME);
	netlibHandle = Netlib_RegisterUser(&nlu);
}

void logUnregister(){
	Netlib_CloseHandle(netlibHandle);
	netlibHandle = NULL;
}

void log(const wchar_t* szText){

	if (netlibHandle) {
		Netlib_LogW(netlibHandle, szText);
	}

	#ifdef _DEBUG
	OutputDebugString(szText);
	#endif //_DEBUG
}

void log_p(const wchar_t* szText, ...){
	va_list args;
	va_start(args, szText);
	int len = _vscwprintf(szText, args ) + 1; // _vscprintf doesn't count terminating '\0' //!!!!!!!!!!!!!!!!
	wchar_t* buffer = new wchar_t[len * sizeof(wchar_t)];
	mir_vsnwprintf(buffer, len, szText, args);
	va_end(args);
	log(buffer);
	delete[] buffer;
}