Please translate code in c++

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?QWxleGFuZGVy?=

    Please translate code in c++

    Hi!
    I want to learn C# in the near future. But for now, I would be more than
    happy if someone could translate this short c# source code into c++. (I
    searched the web for c++ equivalents but after one hour i am too frustrated,
    and so i hope you can help me)



    using System.IO; ... SHDocVw.ShellWi ndows shellWindows = new
    SHDocVw.ShellWi ndowsClass(); string filename; foreach
    (SHDocVw.Intern etExplorer ie in shellWindows){ filename =
    Path.GetFileNam eWithoutExtensi on(ie.FullName) .ToLower(); if
    (filename.Equal s("iexplore") ) Console.WriteLi ne("Web Site : {0}",
    ie.LocationURL) ; if (filename.Equal s("explorer") )
    Console.WriteLi ne("Hard Drive : {0}", ie.LocationURL) ; }



    Here's the start of the c++ code:
    #include <windows.h>
    #using <mscorlib.dll >

    #include <iostream>
    #include <string>

    using namespace System;
    using namespace System::IO;
    using namespace System::Collect ions;

    void main()
    {
    ....
    }

    Thank you very very much!!

  • Ignacio Machin \( .NET/ C# MVP \)

    #2
    Re: Please translate code in c++

    Hi,

    "Alexander" <Alexander@disc ussions.microso ft.comwrote in message
    news:460ED8FD-E94D-456C-A028-A22BC6AAC152@mi crosoft.com...
    Hi!
    I want to learn C# in the near future. But for now, I would be more than
    happy if someone could translate this short c# source code into c++. (I
    searched the web for c++ equivalents but after one hour i am too
    frustrated,
    and so i hope you can help me)
    First of all you should learn to proper format code in an email, the chunk
    of C# code below is unreadable
    >
    >
    >
    using System.IO; ... SHDocVw.ShellWi ndows shellWindows = new
    SHDocVw.ShellWi ndowsClass(); string filename; foreach
    (SHDocVw.Intern etExplorer ie in shellWindows){ filename =
    Path.GetFileNam eWithoutExtensi on(ie.FullName) .ToLower(); if
    (filename.Equal s("iexplore") ) Console.WriteLi ne("Web Site : {0}",
    ie.LocationURL) ; if (filename.Equal s("explorer") )
    Console.WriteLi ne("Hard Drive : {0}", ie.LocationURL) ; }
    >
    >
    >
    Here's the start of the c++ code:
    #include <windows.h>
    #using <mscorlib.dll >
    >
    #include <iostream>
    #include <string>
    >
    using namespace System;
    using namespace System::IO;
    using namespace System::Collect ions;
    >
    void main()
    {
    ...
    }
    >
    Thank you very very much!!
    >

    Comment

    • =?Utf-8?B?RGF2aWQgQW50b24=?=

      #3
      RE: Please translate code in c++

      The C++/CLI equivalent is:
      using namespace System::IO;

      private ref class TestClass
      {
      private:
      void TestMethod()
      {
      SHDocVw::ShellW indows ^shellWindows = gcnew SHDocVw::ShellW indowsClass();
      System::String ^filename;
      for each (SHDocVw::Inter netExplorer ^ie in shellWindows)
      {
      filename = Path::GetFileNa meWithoutExtens ion(ie->FullName)->ToLower();
      if (filename->Equals("iexplo re"))
      Console::WriteL ine("Web Site : {0}", ie->LocationURL) ;
      if (filename->Equals("explor er"))
      Console::WriteL ine("Hard Drive : {0}", ie->LocationURL) ;
      }
      }
      };

      In the future, don't post unformatted code.
      --
      David Anton
      Source code converters: Convert between C#, C++, Java, and VB with the most accurate and reliable source code converters

      Convert between VB, C#, and C++
      Instant C#
      Instant VB
      Instant C++
      C++ to C# Converter
      C++ to VB Converter


      "Alexander" wrote:
      Hi!
      I want to learn C# in the near future. But for now, I would be more than
      happy if someone could translate this short c# source code into c++. (I
      searched the web for c++ equivalents but after one hour i am too frustrated,
      and so i hope you can help me)
      >
      >
      >
      using System.IO; ... SHDocVw.ShellWi ndows shellWindows = new
      SHDocVw.ShellWi ndowsClass(); string filename; foreach
      (SHDocVw.Intern etExplorer ie in shellWindows){ filename =
      Path.GetFileNam eWithoutExtensi on(ie.FullName) .ToLower(); if
      (filename.Equal s("iexplore") ) Console.WriteLi ne("Web Site : {0}",
      ie.LocationURL) ; if (filename.Equal s("explorer") )
      Console.WriteLi ne("Hard Drive : {0}", ie.LocationURL) ; }
      >
      >
      >
      Here's the start of the c++ code:
      #include <windows.h>
      #using <mscorlib.dll >
      >
      #include <iostream>
      #include <string>
      >
      using namespace System;
      using namespace System::IO;
      using namespace System::Collect ions;
      >
      void main()
      {
      ...
      }
      >
      Thank you very very much!!
      >

      Comment

      • =?Utf-8?B?QWxleGFuZGVy?=

        #4
        RE: Please translate code in c++

        Thank you very much, David. Well, I formatted the code, and then I pasted it
        into the web form. May be I have to format it in the web form next time...

        But it still does not work. I get many errors:
        ..\main.cpp(14) : error C2653: 'SHDocVw' : is not a class or namespace name
        ..\main.cpp(14) : error C2065: 'ShellWindows' : undeclared identifier
        ..\main.cpp(14) : error C2065: 'shellWindows' : undeclared identifier
        ..\main.cpp(14) : error C2653: 'SHDocVw' : is not a class or namespace name
        ..\main.cpp(14) : error C2061: syntax error : identifier 'ShellWindowsCl ass'
        ..\main.cpp(16) : error C2653: 'SHDocVw' : is not a class or namespace name
        ..\main.cpp(16) : error C2143: syntax error : missing 'in' before '^'
        ..\main.cpp(16) : error C2065: 'ie' : undeclared identifier
        ..\main.cpp(16) : error C3192: syntax error : '^' is not a prefix operator
        (did you mean '*'?)
        ..\main.cpp(16) : error C2146: syntax error : missing ')' before identifier
        'in'
        ..\main.cpp(16) : error C2065: 'in' : undeclared identifier
        ..\main.cpp(16) : error C2146: syntax error : missing ';' before identifier
        'shellWindows'
        ..\main.cpp(16) : error C2059: syntax error : ')'
        ..\main.cpp(17) : error C2143: syntax error : missing ';' before '{'
        ..\main.cpp(18) : error C2227: left of '->FullName' must point to
        class/struct/union/generic type
        type is ''unknown-type''
        ..\main.cpp(18) : error C2227: left of '->ToLower' must point to
        class/struct/union/generic type
        ..\main.cpp(20) : error C2227: left of '->LocationURL' must point to
        class/struct/union/generic type
        type is ''unknown-type''
        ..\main.cpp(22) : error C2227: left of '->LocationURL' must point to
        class/struct/union/generic type
        type is ''unknown-type''

        I hope you can help me once again. And P.S.: I went to my local library and
        lend some books about C#. :-)

        Comment

        • =?Utf-8?B?RGF2aWQgQW50b24=?=

          #5
          RE: Please translate code in c++

          Note that the conversion I posted was for C++/CLI.
          --
          David Anton
          Source code converters: Convert between C#, C++, Java, and VB with the most accurate and reliable source code converters

          Convert between VB, C#, and C++
          Instant C#
          Instant VB
          Instant C++
          C++ to C# Converter
          C++ to VB Converter


          "Alexander" wrote:
          Thank you very much, David. Well, I formatted the code, and then I pasted it
          into the web form. May be I have to format it in the web form next time...
          >
          But it still does not work. I get many errors:
          .\main.cpp(14) : error C2653: 'SHDocVw' : is not a class or namespace name
          .\main.cpp(14) : error C2065: 'ShellWindows' : undeclared identifier
          .\main.cpp(14) : error C2065: 'shellWindows' : undeclared identifier
          .\main.cpp(14) : error C2653: 'SHDocVw' : is not a class or namespace name
          .\main.cpp(14) : error C2061: syntax error : identifier 'ShellWindowsCl ass'
          .\main.cpp(16) : error C2653: 'SHDocVw' : is not a class or namespace name
          .\main.cpp(16) : error C2143: syntax error : missing 'in' before '^'
          .\main.cpp(16) : error C2065: 'ie' : undeclared identifier
          .\main.cpp(16) : error C3192: syntax error : '^' is not a prefix operator
          (did you mean '*'?)
          .\main.cpp(16) : error C2146: syntax error : missing ')' before identifier
          'in'
          .\main.cpp(16) : error C2065: 'in' : undeclared identifier
          .\main.cpp(16) : error C2146: syntax error : missing ';' before identifier
          'shellWindows'
          .\main.cpp(16) : error C2059: syntax error : ')'
          .\main.cpp(17) : error C2143: syntax error : missing ';' before '{'
          .\main.cpp(18) : error C2227: left of '->FullName' must point to
          class/struct/union/generic type
          type is ''unknown-type''
          .\main.cpp(18) : error C2227: left of '->ToLower' must point to
          class/struct/union/generic type
          .\main.cpp(20) : error C2227: left of '->LocationURL' must point to
          class/struct/union/generic type
          type is ''unknown-type''
          .\main.cpp(22) : error C2227: left of '->LocationURL' must point to
          class/struct/union/generic type
          type is ''unknown-type''
          >
          I hope you can help me once again. And P.S.: I went to my local library and
          lend some books about C#. :-)

          Comment

          • Sheng Jiang[MVP]

            #6
            Re: Please translate code in c++

            are you sure you have referenced SHDocVw.dll?

            --
            Sheng Jiang
            Microsoft MVP in VC++
            "Alexander" <Alexander@disc ussions.microso ft.comwrote in message
            news:2805F8ED-A28B-45F9-82B6-212D1E5C7699@mi crosoft.com...
            Thank you very much, David. Well, I formatted the code, and then I pasted
            it
            into the web form. May be I have to format it in the web form next time...
            >
            But it still does not work. I get many errors:
            .\main.cpp(14) : error C2653: 'SHDocVw' : is not a class or namespace name
            .\main.cpp(14) : error C2065: 'ShellWindows' : undeclared identifier
            .\main.cpp(14) : error C2065: 'shellWindows' : undeclared identifier
            .\main.cpp(14) : error C2653: 'SHDocVw' : is not a class or namespace name
            .\main.cpp(14) : error C2061: syntax error : identifier
            'ShellWindowsCl ass'
            .\main.cpp(16) : error C2653: 'SHDocVw' : is not a class or namespace name
            .\main.cpp(16) : error C2143: syntax error : missing 'in' before '^'
            .\main.cpp(16) : error C2065: 'ie' : undeclared identifier
            .\main.cpp(16) : error C3192: syntax error : '^' is not a prefix operator
            (did you mean '*'?)
            .\main.cpp(16) : error C2146: syntax error : missing ')' before identifier
            'in'
            .\main.cpp(16) : error C2065: 'in' : undeclared identifier
            .\main.cpp(16) : error C2146: syntax error : missing ';' before identifier
            'shellWindows'
            .\main.cpp(16) : error C2059: syntax error : ')'
            .\main.cpp(17) : error C2143: syntax error : missing ';' before '{'
            .\main.cpp(18) : error C2227: left of '->FullName' must point to
            class/struct/union/generic type
            type is ''unknown-type''
            .\main.cpp(18) : error C2227: left of '->ToLower' must point to
            class/struct/union/generic type
            .\main.cpp(20) : error C2227: left of '->LocationURL' must point to
            class/struct/union/generic type
            type is ''unknown-type''
            .\main.cpp(22) : error C2227: left of '->LocationURL' must point to
            class/struct/union/generic type
            type is ''unknown-type''
            >
            I hope you can help me once again. And P.S.: I went to my local library
            and
            lend some books about C#. :-)

            Comment

            • =?Utf-8?B?QWxleGFuZGVy?=

              #7
              Re: Please translate code in c++

              Hi! First I tried #using <ShDocVW.dll> , but it did not work, but now I added
              a reference to it, and it works just fine. Thank you very much again for your
              help! I really appreciate it.

              Well, I am new to .NET and this was the first reference I made. Are there
              any books on .NET and C# or C++ and how I access IE/Explorer/Windows Media
              Player etc.. ?

              One last question. Is there a quick way how I can determine which of the
              Explorer windows is the top most window? My program shall have no window, and
              if I press for example F5 it shall take the path of the Explorer window which
              is activated, (e.g. because I have some files selected in it, ... it is just
              the top most window). Is there a way to only get the top most window?

              Comment

              • =?Utf-8?B?QWxleGFuZGVy?=

                #8
                Re: Please translate code in c++

                Hi! I have solved it this way:
                HWND dest = GetForegroundWi ndow();
                and
                if(ie->HWND == (int)dest)
                my have no good feeling converting HWND to int....

                Comment

                Working...