-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextern.cpp
More file actions
73 lines (62 loc) · 1.28 KB
/
extern.cpp
File metadata and controls
73 lines (62 loc) · 1.28 KB
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
#ifdef _WIN32
#define DLLEXPORT __declspec(dllexport)
#else
#define DLLEXPORT
#endif
#include <pthread.h>
#include <cstdio>
#include <cstdlib>
#include <cstdarg>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <numeric>
#include <future>
#include <vector>
#include <execution>
#include <Windows.h>
extern "C" DLLEXPORT double printd(double X) {
fprintf(stderr, "%f\n", X);
return 0;
}
std::vector<unsigned char> buffer;
extern "C" DLLEXPORT int bprint(const char* str, ...)
{
for(int i = 0; i < strlen(str); i++)
{
buffer.push_back(str[i]);
}
return 0;
}
extern "C" DLLEXPORT int bprintfinish(...)
{
va_list vl;
va_start( vl, &buffer[0] );
fwrite(&buffer[0], buffer.size(), 1, stdout);
va_end(vl);
buffer.clear();
return 0;
}
extern "C" DLLEXPORT int print(const char* str, ...)
{
va_list vl;
va_start( vl, str );
fwrite(str, strlen(str), 1, stdout);
va_end(vl);
return 0;
}
extern "C" DLLEXPORT int printi(unsigned int X)
{
printf("%i", X);
return 0;
}
extern "C" DLLEXPORT HANDLE Win32GetStdHandle(int getHandle)
{
return GetStdHandle(getHandle);
}
extern "C" DLLEXPORT int Win32WriteFile(HANDLE console, const char* str)
{
DWORD dwBytesWritten{};
WriteFile(console, str, strlen(str), &dwBytesWritten, 0);
return 0;
}