2

Ok so I have a C# user interface which uses a C++ DLL. The DLL is actually an OpenGL/SDL game. Once the game has finished it goes back to the C# UI. This all works nicely and as far as I know, correctly.

The problem comes when I try to exit the actual program. The C# form closes, however an error follows shortly which is pretty undescriptive. I assume it is something to do with the DLL, perhaps it is still open? How does one make sure that the DLL has closed properly? Or how do you close it all together?

I'm opening the DLL as follows:

    [DllImport("AsteroidGame.dll")]
    public static extern int EntryPoint();

    private void rungame()
    {
            EntryPoint();
    }

Thanks in advance.

EDIT

The error simply says:

vshost32.exe has stopped working

Noviz
  • 59
  • 1
  • 8
  • 2
    What is the "undescriptive" error? =) – Chris Barlow May 04 '11 at 21:03
  • It says: vshost32.exe has stopped working. After I click ok on this message it finally closes. – Noviz May 04 '11 at 21:06
  • 2
    did you enable the checkbox -> Properties -> Debug -> Enable unmanaged code debugging as suggested in this link: http://stackoverflow.com/questions/735621/vshost32-exe-crash-when-calling-unmanaged-dll – Johnv2020 May 04 '11 at 21:09
  • No I didn't. I'll do it now. I really am rubbish at searching this website lol – Noviz May 04 '11 at 21:13
  • Ok it appears that it gets to the point of running the destructors and it fails when trying to delete a texture (glDeleteTextures( 1, &m_MainMenuTexture );) – Noviz May 04 '11 at 21:16

2 Answers2

5

The dll is unloaded by Windows when the application exits. During this process the static variables of your dll will be destroyed. If your game did not properly end and some loop is still sending events to e.g. a static class which in turn routes them into your C# UI you can get this sort of error.

At first you should check if you did call all cleanup routines of your game engine before you exit the C# UI. If that does not help you need to debug further into unmanaged code.

Yorus, Alois Kraus

Alois Kraus
  • 13,229
  • 1
  • 38
  • 64
1

You cant unload an external assembly from c#, you can only unload the App Domain that loaded it. You could create an App Domain (http://msdn.microsoft.com/en-us/library/system.appdomain.aspx) then load the c++ assembly from here. When you are finished with the game, unload the App Domain.

Eamonn McEvoy
  • 8,876
  • 14
  • 53
  • 83