2 Replies - 466 Views - Last Post: 17 July 2017 - 03:50 PM

#1 hexagod  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 242
  • Joined: 29-October 16

Any Way to Use a String^ Inside ShellExecute() for FilePath?

Posted 13 July 2017 - 12:54 PM

Hey all,
Anyone know if it's possible to use a String^ or even a std::string inside ShellExecute()?


Here is the syntax I've been using. I'm trying to fill the part that says "C:\\XXXX\\" with a String^

ShellExecute(NULL, NULL, L"C:\\XXXX\\", NULL, NULL, SW_SHOWDEFAULT);



Idears? :blink:

Is This A Good Question/Topic? 0
  • +

Replies To: Any Way to Use a String^ Inside ShellExecute() for FilePath?

#2 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 5824
  • View blog
  • Posts: 19,831
  • Joined: 05-May 12

Re: Any Way to Use a String^ Inside ShellExecute() for FilePath?

Posted 14 July 2017 - 07:16 PM

If you are using a std::string, simply use its c_str() method.

If you are using a String^, you will to marshal it from the managed heap into the unmanaged heap and pass that unmanaged memory block.

Why not just is the managed Process::Start() method instead?

I really, really suggest that you move over to using C#. So far I've not seen anything in your past posts that would require using C++. You would have a much better support structure in terms of finding help, and you would be doing so much more less typing and spending less time waiting for builds to complete.

The only time you should fall back to C++ CLI is there is something requires ultra high performance or if you need to interact with an unmanaged API that has a crazy marshalling story. In does cases, you use C++ CLI's IJW to interact with the unmanaged API or code, and have that asswbly expose a simpler facade to your C# code.
Was This Post Helpful? 1
  • +
  • -

#3 hexagod  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 242
  • Joined: 29-October 16

Re: Any Way to Use a String^ Inside ShellExecute() for FilePath?

Posted 17 July 2017 - 03:50 PM

Thanks Skydiver! The reason that I wasn't using Process::Start() is because ShellExecute() is super simple for what I'm doing.

I also like that ShellExecute() works the exact same way as double clicking on things. This is nice for when I switch programs used for certain filetypes and also very convenient for opening directories.

The reason that I need a String^ inside of ShellExecute is that I am trying to use it to open network locations which change depending on which job I'm working on.

for example: I need to view a directory @ remote location \\xxx.xxx.xxx.xxx\ <--- which will be entered in a textbox

PS: Skydiver, that is a very nice array of hexagons you've got there for a profile pic. I am sad that I can't get one more rep point.. I just want 6 and I'll be good lol
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1