forked from scalingdata/gowinlog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bookmark.c
55 lines (49 loc) · 1.45 KB
/
bookmark.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
// +build windows
#include "bookmark.h"
ULONGLONG CreateBookmark() {
return (ULONGLONG)EvtCreateBookmark(NULL);
}
ULONGLONG CreateBookmarkFromXML(char* xmlString) {
size_t xmlWideLen= mbstowcs(NULL, xmlString, 0) + 1;
LPWSTR lxmlString = malloc(xmlWideLen * sizeof(wchar_t));
if (!lxmlString) {
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
return 0;
}
// Convert Go string to wide characters
mbstowcs(lxmlString, xmlString, xmlWideLen);
return (ULONGLONG)EvtCreateBookmark(lxmlString);
}
int UpdateBookmark(ULONGLONG hBookmark, ULONGLONG hEvent) {
return EvtUpdateBookmark((EVT_HANDLE)hBookmark, (EVT_HANDLE)hEvent);
}
char* RenderBookmark(ULONGLONG hBookmark) {
DWORD dwUsed;
DWORD dwProps;
DWORD dwSize = 0;
EvtRender(NULL, (EVT_HANDLE)hBookmark, EvtRenderBookmark, dwSize, NULL, &dwUsed, &dwProps);
if (GetLastError() != ERROR_INSUFFICIENT_BUFFER){
return NULL;
}
dwSize = dwUsed + 1;
LPWSTR xmlWide = malloc((dwSize) * sizeof(wchar_t));
if (!xmlWide) {
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
return NULL;
}
int renderResult = EvtRender(NULL, (EVT_HANDLE)hBookmark, EvtRenderBookmark, dwSize, xmlWide, &dwUsed, &dwProps);
if (!renderResult) {
free(xmlWide);
return 0;
}
size_t xmlNarrowLen = wcstombs(NULL, xmlWide, 0) + 1;
void* xmlNarrow = malloc(xmlNarrowLen);
if (!xmlNarrow) {
free(xmlWide);
SetLastError(ERROR_NOT_ENOUGH_MEMORY);
return NULL;
}
wcstombs(xmlNarrow, xmlWide, xmlNarrowLen);
free(xmlWide);
return xmlNarrow;
}