Work only inside debuger?!

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Stephan Schaem

    #1

    Work only inside debuger?!

    get this string when I press CTRL-F5 to run:

    ØB-

    I get this string when I press F5 to run:

    Mobile Intel(R) Celeron(R) CPU 1.50GHz


    I started with a 100% C++ unmanaged program and
    I wanted to display the processor name, and so I gave the .net framework a try.

    So I injected this code in one of the .cpp file (nothing more, nothing less)

    #using <system.dll>
    #using <System.Managem ent.dll>

    using namespace System;
    using namespace System::Managem ent;

    void Function() {

    ......

    ManagementObjec tSearcher* query1 = new ManagementObjec tSearcher("SELE CT * FROM Win32_processor ") ;
    ManagementObjec tCollection* queryCollection 1 = query1->Get();
    ManagementObjec tCollection::Ma nagementObjectE numerator* queryEnum1 = queryCollection 1->GetEnumerator( );
    queryEnum1->MoveNext();
    ManagementBaseO bject* object = queryEnum1->get_Current( );
    Object* cpuName = object->GetPropertyVal ue(L"Name");

    .....

    // Emit html with processor name
    html.td(AtlHtml Attrs("%s", cpuName->ToString())) ;

    }

    Stephan

  • Tian Min Huang

    #2
    RE: Work only inside debuger?!

    Hello Stephan,

    Thanks for your post. I did some test on my side, and now I'd like to share
    the following information with you:

    I reviewed your code and built a sample console application, it works
    properly on my side with and without VS .NET 2003 debugger.

    To narrow down the problem, please tell me what version of VS .NET you are
    using, 2002 or 2003. I recommend you create a new console program to check
    whether other project will also reproduce the problem on your side.

    It the problem only occurs to a specific project, could you please post the
    project and I will be glad to check it.

    I look forward to hearing from you.

    Have a nice day!

    Regards,

    HuangTM
    Microsoft Online Partner Support
    MCSE/MCSD

    Get Secure! -- www.microsoft.com/security
    This posting is provided "as is" with no warranties and confers no rights.

    Comment

    • Stephan Schaem

      #3
      Re: Work only inside debuger?!

      Thanks for looking into it.

      I cannot post the project, but will try to inject that code in some already existing MS Win32 SDK sample
      and see if it behave the same.

      To recap the problem: I have a win32 (100% unmanaged C++ project, with inline assembly and all) and
      want to use some of the new API in it. I'm at the stage where it compile (after allot of project setting massage)
      and link (with warning... for example I lost my "edit and continue" :(( ) and run fine when the debugger is invoked.

      Stephan

      "Tian Min Huang" <timhuang@onlin e.microsoft.com > wrote in message news:O8Y$4r7iDH A.1392@cpmsftng xa06.phx.gbl...[color=blue]
      > Hello Stephan,
      >
      > Thanks for your post. I did some test on my side, and now I'd like to share
      > the following information with you:
      >
      > I reviewed your code and built a sample console application, it works
      > properly on my side with and without VS .NET 2003 debugger.
      >
      > To narrow down the problem, please tell me what version of VS .NET you are
      > using, 2002 or 2003. I recommend you create a new console program to check
      > whether other project will also reproduce the problem on your side.
      >
      > It the problem only occurs to a specific project, could you please post the
      > project and I will be glad to check it.
      >
      > I look forward to hearing from you.
      >
      > Have a nice day!
      >
      > Regards,
      >
      > HuangTM
      > Microsoft Online Partner Support
      > MCSE/MCSD
      >
      > Get Secure! -- www.microsoft.com/security
      > This posting is provided "as is" with no warranties and confers no rights.
      >[/color]


      Comment

      • Stu Smith

        #4
        Re: Work only inside debuger?!

        AtlHtmlAttrs seems to be expecting unmanaged strings of some sort, and
        you're giving it a managed string. They certainly aren't guaranteed to be
        the same thing (although for some odd reason, as you've found out, in debug
        mode they are interchangeable ).

        You'll need to use something like this (*NOTE* untested!):

        inline CString ToStr( System::String *strParam )
        {
        using System::Runtime ::InteropServic es::Marshal;
        System::IntPtr ptr = Marshal::String ToHGlobalAnsi( strParam );
        CString str = static_cast<LPC TSTR>( const_cast<void *>(static_cast< const
        void*>( ptr ) ) );
        Marshal::FreeHG lobal( ptr );
        return str;
        }

        .....

        html.td(AtlHtml Attrs("%s", ToStr(cpuName->ToString())) );


        Hope that helps,

        Stu



        "Stephan Schaem" <sschaem@seriou smagic.com> wrote in message
        news:e72V%23cdi DHA.2536@TK2MSF TNGP10.phx.gbl. ..
        get this string when I press CTRL-F5 to run:

        ØB-

        I get this string when I press F5 to run:

        Mobile Intel(R) Celeron(R) CPU 1.50GHz


        I started with a 100% C++ unmanaged program and
        I wanted to display the processor name, and so I gave the .net framework a
        try.

        So I injected this code in one of the .cpp file (nothing more, nothing less)

        #using <system.dll>
        #using <System.Managem ent.dll>

        using namespace System;
        using namespace System::Managem ent;

        void Function() {

        ......

        ManagementObjec tSearcher* query1 = new ManagementObjec tSearcher("SELE CT *
        FROM Win32_processor ") ;
        ManagementObjec tCollection* queryCollection 1 = query1->Get();
        ManagementObjec tCollection::Ma nagementObjectE numerator* queryEnum1 =
        queryCollection 1->GetEnumerator( );
        queryEnum1->MoveNext();
        ManagementBaseO bject* object = queryEnum1->get_Current( );
        Object* cpuName = object->GetPropertyVal ue(L"Name");

        .....

        // Emit html with processor name
        html.td(AtlHtml Attrs("%s", cpuName->ToString())) ;

        }

        Stephan


        Comment

        • David Notario

          #5
          Re: Work only inside debuger?!

          Hi Stephan.

          Can you send me a standalone repro? (.exe). Also, please indicate which version of the CLR this is.



          --
          David Notario
          Software Design Engineer - CLR JIT Compiler


          "Stephan Schaem" <sschaem@seriou smagic.com> wrote in message news:e72V%23cdi DHA.2536@TK2MSF TNGP10.phx.gbl. ..
          get this string when I press CTRL-F5 to run:

          ØB-

          I get this string when I press F5 to run:

          Mobile Intel(R) Celeron(R) CPU 1.50GHz


          I started with a 100% C++ unmanaged program and
          I wanted to display the processor name, and so I gave the .net framework a try.

          So I injected this code in one of the .cpp file (nothing more, nothing less)

          #using <system.dll>
          #using <System.Managem ent.dll>

          using namespace System;
          using namespace System::Managem ent;

          void Function() {

          .....

          ManagementObjec tSearcher* query1 = new ManagementObjec tSearcher("SELE CT * FROM Win32_processor ") ;
          ManagementObjec tCollection* queryCollection 1 = query1->Get();
          ManagementObjec tCollection::Ma nagementObjectE numerator* queryEnum1 = queryCollection 1->GetEnumerator( );
          queryEnum1->MoveNext();
          ManagementBaseO bject* object = queryEnum1->get_Current( );
          Object* cpuName = object->GetPropertyVal ue(L"Name");

          ....

          // Emit html with processor name
          html.td(AtlHtml Attrs("%s", cpuName->ToString())) ;

          }

          Stephan

          Comment

          • Girish Bharadwaj

            #6
            Re: Work only inside debuger?!

            Just to make sure, you might want to verify the different compiler options
            between the release build and the debug build..
            Of course, you might want to check errors in every step .. :)
            --
            Girish Bharadwaj
            "David Notario" <dnotario@onlin e.microsoft.com > wrote in message
            news:en2bLMujDH A.1656@tk2msftn gp13.phx.gbl...
            Hi Stephan.

            Can you send me a standalone repro? (.exe). Also, please indicate which
            version of the CLR this is.



            --
            David Notario
            Software Design Engineer - CLR JIT Compiler


            "Stephan Schaem" <sschaem@seriou smagic.com> wrote in message
            news:e72V%23cdi DHA.2536@TK2MSF TNGP10.phx.gbl. ..
            get this string when I press CTRL-F5 to run:

            ØB-

            I get this string when I press F5 to run:

            Mobile Intel(R) Celeron(R) CPU 1.50GHz


            I started with a 100% C++ unmanaged program and
            I wanted to display the processor name, and so I gave the .net framework a
            try.

            So I injected this code in one of the .cpp file (nothing more, nothing less)

            #using <system.dll>
            #using <System.Managem ent.dll>

            using namespace System;
            using namespace System::Managem ent;

            void Function() {

            ......

            ManagementObjec tSearcher* query1 = new ManagementObjec tSearcher("SELE CT *
            FROM Win32_processor ") ;
            ManagementObjec tCollection* queryCollection 1 = query1->Get();
            ManagementObjec tCollection::Ma nagementObjectE numerator* queryEnum1 =
            queryCollection 1->GetEnumerator( );
            queryEnum1->MoveNext();
            ManagementBaseO bject* object = queryEnum1->get_Current( );
            Object* cpuName = object->GetPropertyVal ue(L"Name");

            .....

            // Emit html with processor name
            html.td(AtlHtml Attrs("%s", cpuName->ToString())) ;

            }

            Stephan


            Comment

            • Stephan Schaem

              #7
              Re: Work only inside debuger?!

              I never tested the release build... The binary code executed is the same,
              the diference betwen both result is if the visual studio debugger is running
              or not.

              Stephan

              "Girish Bharadwaj" <girishb.at.mvp s.dot.org> wrote in message
              news:uo%23tyxZk DHA.2000@TK2MSF TNGP12.phx.gbl. ..[color=blue]
              > Just to make sure, you might want to verify the different compiler options
              > between the release build and the debug build..
              > Of course, you might want to check errors in every step .. :)
              > --
              > Girish Bharadwaj
              > "David Notario" <dnotario@onlin e.microsoft.com > wrote in message
              > news:en2bLMujDH A.1656@tk2msftn gp13.phx.gbl...
              > Hi Stephan.
              >
              > Can you send me a standalone repro? (.exe). Also, please indicate which
              > version of the CLR this is.
              >
              >
              >
              > --
              > David Notario
              > Software Design Engineer - CLR JIT Compiler
              > http://xplsv.com/blogs/devdiary/
              >
              > "Stephan Schaem" <sschaem@seriou smagic.com> wrote in message
              > news:e72V%23cdi DHA.2536@TK2MSF TNGP10.phx.gbl. ..
              > get this string when I press CTRL-F5 to run:
              >
              > ØB-
              >
              > I get this string when I press F5 to run:
              >
              > Mobile Intel(R) Celeron(R) CPU 1.50GHz
              >
              >
              > I started with a 100% C++ unmanaged program and
              > I wanted to display the processor name, and so I gave the .net framework a
              > try.
              >
              > So I injected this code in one of the .cpp file (nothing more, nothing[/color]
              less)[color=blue]
              >
              > #using <system.dll>
              > #using <System.Managem ent.dll>
              >
              > using namespace System;
              > using namespace System::Managem ent;
              >
              > void Function() {
              >
              > .....
              >
              > ManagementObjec tSearcher* query1 = new ManagementObjec tSearcher("SELE CT *
              > FROM Win32_processor ") ;
              > ManagementObjec tCollection* queryCollection 1 = query1->Get();
              > ManagementObjec tCollection::Ma nagementObjectE numerator* queryEnum1 =
              > queryCollection 1->GetEnumerator( );
              > queryEnum1->MoveNext();
              > ManagementBaseO bject* object = queryEnum1->get_Current( );
              > Object* cpuName = object->GetPropertyVal ue(L"Name");
              >
              > ....
              >
              > // Emit html with processor name
              > html.td(AtlHtml Attrs("%s", cpuName->ToString())) ;
              >
              > }
              >
              > Stephan
              >
              >[/color]


              Comment

              • Stephan Schaem

                #8
                Re: Work only inside debuger?!

                Thank you! this work.

                I would like to rant that this is completly insane...

                And I would like to see MS post their reasoning behind creating this
                complete mess!

                This type of complexity to access a string is simply unaceptable.

                MS team : Stop making managed only API , you are killing the simplicity,
                efficiency, cleaness of
                the C++ language !

                Stephan

                "Stu Smith" <stuarts@remove .digita.com> wrote in message
                news:ONqZTVMjDH A.2416@TK2MSFTN GP10.phx.gbl...[color=blue]
                > AtlHtmlAttrs seems to be expecting unmanaged strings of some sort, and
                > you're giving it a managed string. They certainly aren't guaranteed to be
                > the same thing (although for some odd reason, as you've found out, in[/color]
                debug[color=blue]
                > mode they are interchangeable ).
                >
                > You'll need to use something like this (*NOTE* untested!):
                >
                > inline CString ToStr( System::String *strParam )
                > {
                > using System::Runtime ::InteropServic es::Marshal;
                > System::IntPtr ptr = Marshal::String ToHGlobalAnsi( strParam );
                > CString str = static_cast<LPC TSTR>( const_cast<void *>(static_cast< const
                > void*>( ptr ) ) );
                > Marshal::FreeHG lobal( ptr );
                > return str;
                > }
                >
                > ....
                >
                > html.td(AtlHtml Attrs("%s", ToStr(cpuName->ToString())) );
                >
                >
                > Hope that helps,
                >
                > Stu
                >
                >
                >
                > "Stephan Schaem" <sschaem@seriou smagic.com> wrote in message
                > news:e72V%23cdi DHA.2536@TK2MSF TNGP10.phx.gbl. ..
                > get this string when I press CTRL-F5 to run:
                >
                > ØB-
                >
                > I get this string when I press F5 to run:
                >
                > Mobile Intel(R) Celeron(R) CPU 1.50GHz
                >
                >
                > I started with a 100% C++ unmanaged program and
                > I wanted to display the processor name, and so I gave the .net framework a
                > try.
                >
                > So I injected this code in one of the .cpp file (nothing more, nothing[/color]
                less)[color=blue]
                >
                > #using <system.dll>
                > #using <System.Managem ent.dll>
                >
                > using namespace System;
                > using namespace System::Managem ent;
                >
                > void Function() {
                >
                > .....
                >
                > ManagementObjec tSearcher* query1 = new ManagementObjec tSearcher("SELE CT *
                > FROM Win32_processor ") ;
                > ManagementObjec tCollection* queryCollection 1 = query1->Get();
                > ManagementObjec tCollection::Ma nagementObjectE numerator* queryEnum1 =
                > queryCollection 1->GetEnumerator( );
                > queryEnum1->MoveNext();
                > ManagementBaseO bject* object = queryEnum1->get_Current( );
                > Object* cpuName = object->GetPropertyVal ue(L"Name");
                >
                > ....
                >
                > // Emit html with processor name
                > html.td(AtlHtml Attrs("%s", cpuName->ToString())) ;
                >
                > }
                >
                > Stephan
                >
                >[/color]


                Comment

                Working...