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,该库虽然功能强大,但是与文件内容的交互还得通 ...
随机推荐
- 09Microsoft SQL Server 表数据插入,更新,删除
Microsoft SQL Server 表数据插入,更新,删除 向表中插入数据 INSERT INTO insert into tb1 values(0004,'张凤凤') insert into ...
- wpf 自定义Button按钮
创建ButtonEx类 public class ButtonEx : Button { static ButtonEx() { DefaultStyleKeyProperty.OverrideMet ...
- A5. JVM 如何判断GC对象
[概述] 在堆里面存放着 Java 世界中几乎所有的对象实例,垃圾收集器在对堆进行回收前,第一件事情就是要确定这些对象之中哪些还 “存活” 着,哪些已经 “死去”(即不可能再被任何途径使用的对象). ...
- MAC 打开Chrome打开开发者工具的快捷键
mac下safari和chrome打开开发者工具的快捷键相同,都是 option(alt)+command+i 这个是我的默认配置,没有更改过的.
- 一起看看 scrollHeight,clientHeight,offsetHeight,scrollTop是个啥
scrollHeight最终数值的组成: var scrollHeight = currentElementContent.height +currentElement.paddingTop+curr ...
- python_ 学习笔记(hello world)
python中的循环语句 循环语句均可以尾随一个else语句块,该块再条件为false后执行一次 如果使用break跳出则不执行. for it in [1,2,3,4]: print(it,end= ...
- shell日志颜色处理
记录一下shell日志颜色处理 _COLORS=${BS_COLORS:-$(tput colors >/dev/)} __detect_color_support() { # shellche ...
- Python随笔day03
温故知新: 注释: 单行注释 # 多行注释 ‘’’ ‘’’ 或者 “”” “”” 注意:三个单引号或双引号可以用于表示多行字符串. 判断输入的字符串是否是数字 salary = inpu ...
- 2.8 补充:export
linux export 的作用 功能说明:设置或显示环境变量. 语 法:export [-fnp][变量名称]=[变量设置值] 补充说明:在shell中执行程序时,shell会提供一组环 ...
- Spring常用注解总结 hibernate注解
1.@Resource和@Autowired @Resource和@Autowired功能一样在容器查找匹配的Bean @Autowired默认按照byType方式进行bean匹配,@Resource ...