MT4调用Windows API进行文件读写操作
/*导入相关函数*/
#import "kernel32.dll"
int CreateDirectoryW(string directoryName,int type);
int CreateFileW(string Filename, int AccessMode, int ShareMode, int PassAsZero, int CreationMode, int FlagsAndAttributes, int AlsoPassAsZero);
int WriteFile(int FileHandle, string BufferPtr, int BufferLength, int &BytesWritten[], int PassAsZero);
int ReadFile(int FileHandle, uchar &Buffer[], int BufferLength, int & BytesRead[], int PassAsZero);
int CloseHandle(int FileHandle);
int GetFileSize(int FileHandle, int PassAsZero);
#import
/*读文件*/
string ReadFile(string Filename)
{
string strFileContents = "";
int h = CreateFileW(Filename, 0x80000000 /*GENERIC_READ*/, /*SHARE READ|WRITE*/, , /*OPEN_EXISTING*/, , );
if (h == -) {
// Open failed
} else {
int sz = GetFileSize(h, );
if (sz > ) {
uchar buffer[];
ArrayResize(buffer, sz);
int read[];
ReadFile(h, buffer, sz, read, );
if (read[] == sz)
strFileContents = CharArrayToString(buffer, , read[]);
}
}
CloseHandle(h);
return strFileContents;
}
/*写文件*/
void WriteFile(string filePath,string str)
{
int BytesWritten[] = {};
uchar WriteBuffer[];
StringToCharArray(str, WriteBuffer);
int FileHandle = CreateFileW(FileName, , , , , , );
WriteFile(FileHandle,WriteBuffer,StringLen(str),BytesWritten,);
CloseHandle(FileHandle);
}
MT4调用Windows API进行文件读写操作的更多相关文章
- C#调用windows API的一些方法
使用C#调用windows API(从其它地方总结来的,以备查询) C#调用windows API也可以叫做C#如何直接调用非托管代码,通常有2种方法: 1. 直接调用从 DLL 导出的函数. 2. ...
- C#调用Windows API函数截图
界面如下: 下面放了一个PictureBox 首先是声明函数: //这里是调用 Windows API函数来进行截图 //首先导入库文件 [System.Runtime.InteropServices ...
- PHP文件读写操作之文件写入代码
在PHP网站开发中,存储数据通常有两种方式,一种以文本文件方式存储,比如txt文件,一种是以数据库方式存储,比如Mysql,相对于数据库存储,文件存储并没有什么优势,但是文件读写操作在基本的PHP开发 ...
- 【转】用C#调用Windows API向指定窗口发送
一.调用Windows API. C#下调用Windows API方法如下: 1.引入命名空间:using System.Runtime.InteropServices; 2.引用需要使用的方法,格式 ...
- C#中调用Windows API的要点 .
介绍 API(Application Programming Interface),我想大家不会陌生,它是我们Windows编程的常客,虽然基于.Net平台的C#有了强大的类库,但是,我们还是不能否认 ...
- Kotlin入门(27)文件读写操作
Java的文件处理用到了io库java.io,该库虽然功能强大,但是与文件内容的交互还得通过输入输出流中转,致使文件读写操作颇为繁琐.因此,开发者通常得自己重新封装一个文件存取的工具类,以便在日常开发 ...
- 用C#调用Windows API向指定窗口发送按键消息 z
用C#调用Windows API向指定窗口发送 一.调用Windows API. C#下调用Windows API方法如下: 1.引入命名空间:using System.Runtime.Interop ...
- 用C#调用Windows API向指定窗口发送按键消息
一.调用Windows API. C#下调用Windows API方法如下: 1.引入命名空间:using System.Runtime.InteropServices; 2.引用需要使用的方法,格式 ...
- Kotlin入门-文件读写操作
转 https://blog.csdn.net/aqi00/article/details/83241762 Java的文件处理用到了io库java.io,该库虽然功能强大,但是与文件内容的交互还得通 ...
随机推荐
- 牛客多校Round 10
咕咕咕.... 去烽火台和兵马俑了
- org-table
Table of Contents 1. table 1.1. 创建方式 1.2. 重新对齐 1.3. 行列编辑 1.4. 区域 1.5. 计算 1.6. 其他的 1.7. 行宽度 1.8. 列分 ...
- Linux的net.ipv4.tcp_timestamps参数
Q1 今天发生了一个奇怪的现象,在家里始终打开公司的网站打开不了,我就齐了怪了,然后我就各种测试,从ping到dig域名,然后再curl,都是没有问题的,但是就是打不开,最好没有办法只能抓包了,从抓包 ...
- centos7安装:license information(license not accepted)
安装centos7的时候明明已经选择了默认的许可证信息,不知道哪里出错了,安装到最后,就会显示license information(license not accepted)的信息.解决方法如下: ...
- 多校 1010 Taotao Picks Apples(补题)
>>点击进入原题<< 思路:题解很有意思,适合线段树进阶 考虑每次修改不叠加,因此我们可以从如何对原序列进行预处理着手.通过观察可以发现,将原序列从任意位置断开,我们可以通过分 ...
- A - Restaurant
UVA 1468 Description Mr. Kim is planning to open a new restaurant. His city is laid out as a grid ...
- BZOJ 3277 串 & BZOJ 3473 字符串 (广义后缀自动机、时间复杂度分析、启发式合并、线段树合并、主席树)
标签那么长是因为做法太多了... 题目链接: (bzoj 3277) https://www.lydsy.com/JudgeOnline/problem.php?id=3277 (bzoj 3473) ...
- Scala解析Json格式
Scala解析Json格式 代码块 Scala原生包 导入包 import scala.util.parsing.json._ def main(args: Array[String]): Unit ...
- [luoguP1474] 货币系统 Money Systems(背包)
传送门 背包 ——代码 #include <cstdio> #include <iostream> #define LL long long int v, n; LL f[10 ...
- Codeforces 158B (数学)
B. Mushroom Scientists time limit per test 2 seconds memory limit per test 256 megabytes input stand ...