//+------------------------------------------------------------------+ //| Win32API_write.mq4 | //| amenbo | //| | //+------------------------------------------------------------------+ #property copyright "amenbo" // #import "kernel32.dll" int _lopen (string path, int of); int _lcreat (string path, int attrib); int _llseek (int handle, int offset, int origin); int _lread (int handle, string buffer, int bytes); int _lwrite (int handle, string buffer, int bytes); int _lclose (int handle); #import // //+------------------------------------------------------------------+ //| script program start function | //+------------------------------------------------------------------+ int start() { //---- string path="C:\\myLog\\API.txt"; string buffer="ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"; string cr="\r\n";//改行&リターン int count=StringLen (buffer); int result_o; int result_o2; int result_o3; int result_o4; int handle_o=_lopen (path,1);//write_mode // if(handle_o<0) { int handle_c=_lcreat (path,0);//create file(mode;reading or writing) int result_c=_lclose (handle_c);//close file handle_o= -1; } // if (handle_o<0) { int handle_o2=_lopen (path,1);//try open_file again(write_mode) if(handle_o2<0) { Print("Error opening file ",path); return(0); } } // if(handle_o>0) { // result_o2=_llseek (handle_o,0,2); result_o3=_lwrite (handle_o,cr,2);//2バイト書き込み result_o3=_lwrite (handle_o,buffer,count); result_o4=_lclose (handle_o); // }else{ // result_o2=_llseek (handle_o2,0,0); result_o3=_lwrite (handle_o2,buffer,count); result_o4=_lclose (handle_o2); // } //-------- // if(result_o2<0) { Print("Error placing cursor"); return(0); } // if(result_o3<0) { Print("Error writing to file ",path," ",count," bytes"); result_o4=_lclose (handle_o2); } // if(result_o4<0) { Print("Error closing file ",path); return(0); } //---- PlaySound("alert2.wav"); // //------- return(0); }