By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,480 Members | 1,164 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,480 IT Pros & Developers. It's quick & easy.

Please translate code in c++

P: n/a
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).ToLo wer(); 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!!

Aug 14 '07 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Hi,

"Alexander" <Al*******@discussions.microsoft.comwrote in message
news:46**********************************@microsof t.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.ShellWindows shellWindows = new
SHDocVw.ShellWindowsClass(); string filename; foreach
(SHDocVw.InternetExplorer ie in shellWindows){ filename =
Path.GetFileNameWithoutExtension(ie.FullName).ToLo wer(); 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!!

Aug 14 '07 #2

P: n/a
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
"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.ShellWindows shellWindows = new
SHDocVw.ShellWindowsClass(); string filename; foreach
(SHDocVw.InternetExplorer ie in shellWindows){ filename =
Path.GetFileNameWithoutExtension(ie.FullName).ToLo wer(); 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!!
Aug 14 '07 #3

P: n/a
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#. :-)
Aug 14 '07 #4

P: n/a
Note that the conversion I posted was for C++/CLI.
--
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
"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 '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#. :-)
Aug 14 '07 #5

P: n/a
are you sure you have referenced SHDocVw.dll?

--
Sheng Jiang
Microsoft MVP in VC++
"Alexander" <Al*******@discussions.microsoft.comwrote in message
news:28**********************************@microsof t.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
'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#. :-)

Aug 14 '07 #6

P: n/a
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?
Aug 14 '07 #7

P: n/a
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....
Aug 14 '07 #8

This discussion thread is closed

Replies have been disabled for this discussion.