DLL Hell - page 2

 
JC:

As far as I am aware, the @ simply indicates a verbatim string literal. It is not going to control where the file is written.

Your code works for me in a copy of MT4 installed outside \Program Files, and crashes if MT4 is installed inside \Program Files. 

If I run MT4 from a location such as C:\MyMT4, i.e. such that the executable is C:\MyMT4\terminal.exe, then the file ClientMessage.txt is created at C:\MyMT4\ClientMessage.txt. This is obviously going to cause problems if MT4 is inside a protected area of disk such as \Program Files.

If I change your code as follows ...

        public static void WriteMe(string line)
        {
            try
            {
                using (StreamWriter writer = new StreamWriter(@"ClientMessage.txt", true))
                {
                    writer.WriteLine(line);
                }
            }
            catch (Exception e)
            {
                System.Diagnostics.Trace.WriteLine(e.Message);
            }
        }

... then the exception which is logged when I use the DLL from a copy of MT4 within Program Files is, very unsurprisingly, as follows:

Access to the path 'C:\Program Files (x86)\xxxx\ClientMessage.txt' is denied.


 

THANKS JC!!

Where is the exception written to?  I went looking into the event viewer and couldn't find it.

To everyone, I apologize.  I was wrong.  It WAS where the file was getting written that was making it crash.

 
Michael:

Where is the exception written to?  I went looking into the event viewer and couldn't find it.

The usual way of monitoring the output of Trace.WriteLine is DbgView: https://technet.microsoft.com/en-us/sysinternals/debugview.aspx
 
JC:
The usual way of monitoring the output of Trace.WriteLine is DbgView: https://technet.microsoft.com/en-us/sysinternals/debugview.aspx

Thanks.

I thought there was a way to write the exception in the catch segment to the event viewer.

 
Michael:

I thought there was a way to write the exception in the catch segment to the event viewer.

DbgView is usually preferred for ad-hoc debug logging, but if you want to write to the Windows event logs then you can try things such as this.
 
JC:
DbgView is usually preferred for ad-hoc debug logging, but if you want to write to the Windows event logs then you can try things such as this.
Thanks again.