Home>
bool cdeldlg ::writetofile (cstring svalue)
{
  cstring sfile=getexepath () + "\\ 1.log";
  cstdiofile file;
  if (file.open (sfile, cfile ::modecreate | cfile ::modewrite | cfile ::modenotruncate))
  {
    file.seektoend ();//move the file pointer to the end
    file.writestring (svalue);
    file.close ();
  }
  return false;
}

The getexepath () code is as follows:

//return the directory where the executable is located (not including the last "\")
cstring getexepath ()
{
  char sfilename [256]={0};
  cstring spath=_t ("");
  getmodulefilename (afxgetinstancehandle (), sfilename, 255);
  spath.format ("%s", sfilename);
  int pos=spath.reversefind ("\\");
  if (pos!=-1)
    spath=spath.left (pos);
  else
    spath=_t ("");
  return spath;
}
c
  • Previous Four very useful PHP functions
  • Next C # NET method for automatic webpage login