0
votes

I've got a huge problem. I was writting an WFA + C++/CLI DLL application. Everything worked fine until I had to sent it to my friend. Every time he executed the exe file from bin/debug (+additional dll and xml files) nothing happened (he doesn't have Visual Studio installed). The problem doesn't occur to me. On my PC everything works fine.

What i noticed (after couple of hours looking up the solution) is that somehow this is the critical moment :

log = new StreamWriter("log.txt", true);
log.WriteLine("3c");
log.Close();

materialTypeComboBox.SelectedIndex = 0;

log = new StreamWriter("log.txt", true);
log.WriteLine("3d");
log.Close();

"3c" is the last line in my simple log file every time my friend execute this. If I comment this, app crashes on

foreach (RadioButton item in someGroupBox.Controls.OfType<RadioButton>()) { ... }

Seems like WFA's Controls cause that effect, but how is it possible? I tried changing target framework form 3.5 to 4.5.1, building project in Debug and Relase mode, x86, x64, using a installShield projects (I thought I missed some references while sending him the app), one-click installer, creating empty project and paste sources - without any success.

How could it be? No exception, no message box, nothing. Just click and nothing happens. Does anybody know some solution?

2
A. does the program exit immediately after launch? check the task manager. B. check event viewer, there ought to be something log somewhere by the system.kennyzx

2 Answers

1
votes

Windows Forms is renown for it's ability to silently swallow exceptions. I would highly recommend logging unhandled exceptions. To log unhandled exceptions, do the following:

Application.ThreadException += new ThreadExceptionEventHandler(UnhandledUIException);
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(UnhandledException);


private static void UnhandledUIException(object sender, ThreadExceptionEventArgs e)
{
    // Log exception
}

private static void UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
    // Log exception
}

Info: http://msdn.microsoft.com/en-us/library/system.appdomain.unhandledexception.aspx

Info: http://msdn.microsoft.com/en-us/library/system.windows.forms.application.threadexception.aspx

-1
votes

SOLVED:

The problem was with the DLL - with Dependency Walker I discovered that my DLL needs msvcr120.dll to run, and even including it to project output folder did not help, and also msvcr causes the x84/x64 mismatch error. Recompiling DLL solved problem:

Statically Linking the DLLs Make sure you resolve it for both Release and Debug. The steps are slightly different.

Release

In Visual Studio, I went to the project Properties. I changed my Configuration to Release. I went under Configuration Properties | C/C++ | Code Generation Look at the Runtime Library setting. It is set to this: Multi-threaded DLL (/MD) Change it to this: Multi-threaded (/MT) Rebuild. Debug Almost exactly the same as release.

Debug

In Visual Studio, I went to the project Properties. I changed my Configuration to Debug. I went under Configuration Properties | C/C++ | Code Generation Look at the Runtime Library setting. It is set to this: Multi-threaded Debug DLL (/MDd) Change it to this: Multi-threaded Debug (/MTd) Rebuild the debug

http://www.rhyous.com/2010/09/16/avoiding-the-msvcr100-dll-or-msvcr100d-dll/