Please translate code in c++

G

Guest

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.ShellWindows shellWindows = new
SHDocVw.ShellWindowsClass(); string filename; foreach
(SHDocVw.InternetExplorer ie in shellWindows){ filename =
Path.GetFileNameWithoutExtension(ie.FullName).ToLower(); if
(filename.Equals("iexplore")) Console.WriteLine("Web Site : {0}",
ie.LocationURL); if (filename.Equals("explorer"))
Console.WriteLine("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::Collections;

void main()
{
....
}

Thank you very very much!!
 
I

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

Hi,

Alexander said:
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
 
G

Guest

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

private ref class TestClass
{
private:
void TestMethod()
{
SHDocVw::ShellWindows ^shellWindows = gcnew SHDocVw::ShellWindowsClass();
System::String ^filename;
for each (SHDocVw::InternetExplorer ^ie in shellWindows)
{
filename = Path::GetFileNameWithoutExtension(ie->FullName)->ToLower();
if (filename->Equals("iexplore"))
Console::WriteLine("Web Site : {0}", ie->LocationURL);
if (filename->Equals("explorer"))
Console::WriteLine("Hard Drive : {0}", ie->LocationURL);
}
}
};

In the future, don't post unformatted code.
--
David Anton
http://www.tangiblesoftwaresolutions.com
Convert between VB, C#, and C++
Instant C#
Instant VB
Instant C++
C++ to C# Converter
C++ to VB Converter
 
G

Guest

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 'ShellWindowsClass'
..\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#. :)
 
G

Guest

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?
 
G

Guest

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top