First painful steps with VC++ Express 2005 Beta 2 and DirectX9

Hi!

I am currently making my first experiences with .NET programming and the Beta 2.


My first questsion is simple: Is there any way to rename the default "Form1" class/files (which are created when generating a new Forms project) in an easy way I solved the problem by searching for all occurences of "Form1" through the whole solution and replacing them by e.g. "MainWindow". This seems very complicated.


My second question is more complex. I tried to use DirectX in an .NET Forms applivation. I use a form with a single button an want to play a sound when clicking that button (this is only for testing). When calling the following line:

   Device^ SoundOutputDevice = gcnew Device();

to get a device handle (like written in the manged DirectX documentation) I get the following error dialog:

   Managed Debugging Assistant 'LoaderLock' has detected a problem
   in 'd:\Develop\Projekte\TUMID.NET\debug\TUMID.NET.exe'.

   Additional Information: Attempting managed execution inside OS Loader lock.
   Do not attempt to run managed code inside a DllMain or image initialization
   function.

   See :\WINDOWS\Microsoft.NET\Framework\v2.0.50215
   \sdk\bin\mdaBoilerplate.exe.mda.config for documentation.

What does this mean The given file doesn't exist.


Then I saw a line in the main file which doesn't seem to be C++ syntax but is compiled without problems:
  
   [STAThreadAttribute]

What does this mean and what kind of syntax is used here !


My last question: I tried to use the System::String class for string operations. Aren't there any operator (e.g. "+") to manipulate Strings

Many thanks in advance!

Regards, Jordy



Answer this question

First painful steps with VC++ Express 2005 Beta 2 and DirectX9

  • Fire2Burn

    I am facing this problem also. I am quite frustrated. I would like to keep using Visual Studio 2005.. but I might have to go back to sharpdevelop. I remember directx with C# worked in there.

    As for DllMain(), I check to see if the handle was created for the form before I did anything and its still giving me the error. Any updates on this I have the June 2005 SDK update and the Net.2.0 framework that came with the VS2005 beta CDs and the latest 1.1 framework.

    Cheers,
    Aditya

  • xiaobinker

    I've run into the exact same issue with my C++/CLI project.  I'm using VS.Net Beta 2 and DirectX9.0 SDK (April 2005).  I've tried referencing assemblies from previous releases from December 2004/February 2005, but the results are the same (assuming I referenced the right assemblies).

    While these errors can be continued through, it then seems to leave my program in an unusable state.  Any help would be appreciated.

    James

  • johnedw

     Jordy wrote:

    My first questsion is simple: Is there any way to rename the default "Form1" class/files (which are created when generating a new Forms project) in an easy way I solved the problem by searching for all occurences of "Form1" through the whole solution and replacing them by e.g. "MainWindow". This seems very complicated.


    Not yet: refactoring is not available in VC++ 2005. Might be on the list for the next release as it is already available for C#

     Jordy wrote:

    When calling the following line:
       Device^ SoundOutputDevice = gcnew Device();

    to get a device handle (like written in the manged DirectX documentation) I get the following error dialog:
       Managed Debugging Assistant 'LoaderLock' has detected a problem in 'd:\Develop\Projekte\TUMID.NET\debug\TUMID.NET.exe'.


    The loader lock problem exists for mixed (native and managed) mode executables. I think it has to do with some restrictions on what is allowed in a module entry function like DllMain. It exists in .Net 1.x and was reported by Microsoft as fixed in 2.0.

    If that is true it might be a problem of the DirectX wrapper. Never did DirectX stuff, but might it be that you use a DirectX wrapper which was built with Managed C++ based on Net 1.x.
    What assembly do you reference to use the Device class

       

     Jordy wrote:

       [STAThreadAttribute]
    What does this mean and what kind of syntax is used here !


    IIRC attributed programming was introduced with VS2002. With attributes you can either give the C++ compiler some information which it can use for generating code (this is used e.g. in native COM programming) or it can add metadata to several pieces of your assembly.
    The above one tells the main thread to be an STA thread, i.e. CoInitializeEx(0, COINIT_APARTMENTTHREADED) will be used to initialize COM.

     Jordy wrote:

    My last question: I tried to use the System:Tongue Tiedtring class for string operations. Aren't there any operator (e.g. "+") to manipulate Strings


    The String objects contain immutable data. It is not designed to hold mutable data. You should use StringBuilder instead which has an Append method.

    HTH,
    SvenC


  • Zelalem

    This error happens in C# too.

    VS 2005 Beta 2
    June 2005 DirectX SDK


  • Mrhaboobi

    Do you know if the DirectX April 05 distribution is using .NET 1.1 or .NET 2.0


  • boates

    Has anyone found a solution to this problem I am encountering the same error while using Visual Studio 2005 Beta2 (VC++) and DirectX 9.0 April 2005 SDK. As someone eluded to before, I can continue through the errors, but the performance disappears and I get refresh rates around a few seconds for just one polygon.
  • ChrisVanDam

    Hi,

    It looks like most of your questions has been answered except of this one.

     Jordy wrote:
    When calling the following line:

       Device^ SoundOutputDevice = gcnew Device();

    to get a device handle (like written in the manged DirectX documentation) I get the following error dialog:

       Managed Debugging Assistant 'LoaderLock' has detected a problem
       in 'd:\Develop\Projekte\TUMID.NET\debug\TUMID.NET.exe'.

    What does this mean The given file doesn't exist.



    This diagnostic mean that managed code is called while loader lock is held. More information in this paper http://msdn.microsoft.com/library/default.asp url=/library/en-us/dnvs05/html/debgb1LdLk.asp (ignore that it says Beta 1, it is the same in Beta 2).

    With this said, you should not be calling this in DllMain(), contructors of globals/statics, so it is most likely bug in your code. Move this code past initialization run in your object.

    Unfortunately right now the only channels to report bugs to DirectX team other then Product Support and newsgroups. I will shoot email right now to DirectX Team and ask them to follow up on this thread and rest of them.

    Thanks,
    Nikola
    VC++



  • savoiu

    Ok. I tried renaming with the properties windows. It works almost automatically. The include line for the form had to be adapted manually. I didn't know that the properties windows I useful for project files to, I used it for objects and forms only.

    I am using the April 05 SDK for DirectX so I think it is the most actual distribution.


  • twbrandt

    Unfortunately not. I didn't find any solution. I think we simply need an update of DirectX or .NET2.0 to restore the compatibility.

    Does somone know an MS contact person which can definitely help solving this problem soon

  • Roland2

    Well, it is not actually a problem in the sense that it will not arise if you execute your program standalone (that is, not by the "run" button in VS). The LoaderLock is a MDA (Managed Debugging Assistant) that usually helps you to detect flaws in your code by popping a notice window up when your app does a "potentially problematic" operation. These operations, though usually won't cause an exception by themselves, point something's wrong in the app that could cause a hard-to-trace excepcion later.
    In this particular case, I think the flaw is in the wrapper MDX uses to load the DirectX dlls. I guess that the first time MDX is used (an object is created, a method gets called, etc.), the wrapper dinamically loads the native DX DLLs, maybe in a separate thread. However, the process is marked as "loading DLL" by the OS, and, when your app tries to continue executing managed code (either more calls to DX or simply, your code), the LoaderLock MDA interprets this is a potentially risky situation. In fact, it is not, because the MDX wrapper won't call DX functions until the DLLs have finished loading (but LoaderLock doesn't know that).

    Workarounds:
    1.-Press F5 each time you encounter this MDA (painful!)
    2.-Only execute your app outside the debugger, so the MDA is not there to interrupt you (definitely a no-no!)
    3.-Disable that particular MDA. This is done in the "mda application config file", named ApplicationName.exe.mda.config (just like app.config, but with mda between exe/dll and config). However, the MSDN documentation on this point is a bit clumsy. Personally, I still haven't been able to turn LoaderLock down.

    Habbit

  • Gary Smith

     Jordy wrote:

    Hi!

    I am currently making my first experiences with .NET programming and the Beta 2.


    My first questsion is simple: Is there any way to rename the default "Form1" class/files (which are created when generating a new Forms project) in an easy way I solved the problem by searching for all occurences of "Form1" through the whole solution and replacing them by e.g. "MainWindow". This seems very complicated.


    My second question is more complex. I tried to use DirectX in an .NET Forms applivation. I use a form with a single button an want to play a sound when clicking that button (this is only for testing). When calling the following line:

       Device^ SoundOutputDevice = gcnew Device();

    to get a device handle (like written in the manged DirectX documentation) I get the following error dialog:

       Managed Debugging Assistant 'LoaderLock' has detected a problem
       in 'd:\Develop\Projekte\TUMID.NET\debug\TUMID.NET.exe'.

       Additional Information: Attempting managed execution inside OS Loader lock.
       Do not attempt to run managed code inside a DllMain or image initialization
       function.

       See :\WINDOWS\Microsoft.NET\Framework\v2.0.50215
       \sdk\bin\mdaBoilerplate.exe.mda.config for documentation.

    What does this mean The given file doesn't exist.


    Then I saw a line in the main file which doesn't seem to be C++ syntax but is compiled without problems:
      
       [STAThreadAttribute]

    What does this mean and what kind of syntax is used here !


    My last question: I tried to use the System:Tongue Tiedtring class for string operations. Aren't there any operator (e.g. "+") to manipulate Strings

    Many thanks in advance!

    Regards, Jordy




    Hi,

    I'll just try to address your two questions...

    1. Renaming a Form after creating a project isn't that complicated, All you have to do is rename it on the properties page... (Considering if you just created your project) but if codes exist, try using third party products like AXTools (www.axtools.com) But I doubt that they support vs2005...

    2. Are you using the latest DirectX SDK I have a similar problem with the October SDK. But as i see this was already fixed on the later SDK's...

    I just inserted this code to "patch" the problem...

    Just create a header file, with this content:
    namespace Microsoft {
    namespace DirectX {
    namespace PrivateImplementationDetails {
    __nogc struct IDirect3DDevice9 {}; // I was playing with Direct3d
    // Also include other IDirects...
    }
    }
    }

    BTW, I created this on VS 2003 i'm not quite sure if it would work in 2005...
    But I suggest try dowloading the latest SDK...



    cheers,


    Paul June A. Domag


  • Amitkumar

     SvenC wrote:


    The loader lock problem exists for mixed (native and managed) mode executables. I think it has to do with some restrictions on what is allowed in a module entry function like DllMain. It exists in .Net 1.x and was reported by Microsoft as fixed in 2.0.

    If that is true it might be a problem of the DirectX wrapper. Never did DirectX stuff, but might it be that you use a DirectX wrapper which was built with Managed C++ based on Net 1.x.
    What assembly do you reference to use the Device class

    I am using the April 05 DirectX distribution if this is what you are asking for.

    Currently I have two version of .NET framework on my PC: Version 1.1. and 2.0 beta 2. But this shoudln't cause any problems. I found no information about the .NET version used by DirectX in the docs but it seems that it uses .NET1.1 because the documentation refers to VC++ 2003.

     SvenC wrote:

    IIRC attributed programming was introduced with VS2002. With attributes you can either give the C++ compiler some information which it can use for generating code (this is used e.g. in native COM programming) or it can add metadata to several pieces of your assembly.
    The above one tells the main thread to be an STA thread, i.e. CoInitializeEx(0, COINIT_APARTMENTTHREADED) will be used to initialize COM.


    Is there any reason why #pragma isn't used for this


     SvenC wrote:

    The String objects contain immutable data. It is not designed to hold mutable data. You should use StringBuilder instead which has an Append method.


    Oh, I see.

    Thank you very much!


  • First painful steps with VC++ Express 2005 Beta 2 and DirectX9