-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDLLSample.cpp
More file actions
146 lines (136 loc) · 3.62 KB
/
Copy pathDLLSample.cpp
File metadata and controls
146 lines (136 loc) · 3.62 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
//+------------------------------------------------------------------+
//| Sample DLL for MQL4 |
//| Copyright 2001-2016, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#include <afx.h>
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include"stdafx.h"
//---
#define MT4_EXPFUNC __declspec(dllexport)
//please be noted that delete usr_Dll
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
#pragma pack(push,1)
struct RateInfo
{
__int64 ctm;
double open;
double low;
double high;
double close;
unsigned __int64 vol_tick;
int spread;
unsigned __int64 vol_real;
};
#pragma pack(pop)
//---
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
BOOL APIENTRY DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
//---
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
//---
return(TRUE);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
MT4_EXPFUNC int __stdcall GetTestIntValue(void)
{
printf("GetIntValue takes %d\n", 999);
return(999);
}
//+------------------------------------------------------------------+
//Make Sure if the file is exist!
MT4_EXPFUNC bool __stdcall MyDllFindFile(wchar_t *strFileName)
{
bool ret;
CFileFind fileFind;
CString strFileName1;
strFileName1.Format(_T("%s"), strFileName);
// WideCharToMultiByte(CP_ACP, 0, strFileName, 256, (wchar_t *)strFileName1.GetBuffer(0), 256, NULL, NULL);
// strFileName1.ReleaseBuffer(0);
if (TRUE == fileFind.FindFile(strFileName1))
{
ret = true;
}
else
{
ret = false;
}
return ret;
}
//Create New File, if already exist,empty it!
MT4_EXPFUNC bool __stdcall MyDllCreateFile(wchar_t *strFileName)
{
bool ret;
CFile file;
CString strFileName1;
strFileName1.Format(_T("%s"), strFileName);
CFileException exp;
if (TRUE == file.Open(strFileName1, CFile::modeCreate, &exp))
{
file.Close();
ret = true;
}
else
{
ret = false;
}
return ret;
}
//write int to the first line of the file!
MT4_EXPFUNC bool __stdcall MyDllWriteFileIntFirst(wchar_t *strFileName, int number)
{
CStdioFile file;
CString strFileName1;
strFileName1.Format(_T("%s"), strFileName);
CString strInfo;
strInfo.Format(_T("%d"), number);
if (FALSE == file.Open(strFileName1, CStdioFile::modeWrite | CStdioFile::shareDenyRead | CFile::shareDenyWrite))
{
return false;
}
file.WriteString(strInfo);
file.Close();
return true;
}
//Read int from the first line of the file!
MT4_EXPFUNC int __stdcall MyDllReadFileIntFirst(wchar_t *strFileName)
{
CStdioFile file;
CString strFileName1;
strFileName1.Format(_T("%s"), strFileName);
int number;
if (FALSE == file.Open(strFileName1, CFile::modeRead))
{
return -1;
}
CString strText;
if (FALSE == file.ReadString(strText))
{
file.Close();
return -2;
}
file.Close();
number = _ttoi(strText);
if ((number >= 1000) || (number <= 10))
{
number = -3;
}
return number;
}