How to open a file through ShellExecute in parent directory?

For everyone, just starting with C++ or programming at all. Ask newbie questions in this forum!

Moderators: Darobat, RecursiveS, Dante Shamest, Bugdude, Wizard

Re: How to open a file through ShellExecute in parent directory?

Postby exomo » Thu Apr 26, 2012 2:27 am

Wide characters again. You need the L for wide character string literals, L"\\"
If you are working with wide chars you have to use them everywhere, you cannot mix wide strings with "normal" strings.
Who needs a signature anyway.
User avatar
exomo
 
Posts: 935
Joined: Fri Sep 26, 2003 12:30 pm
Location: germany->baden

Re: How to open a file through ShellExecute in parent directory?

Postby alienoiz » Thu Apr 26, 2012 6:31 am

exomo wrote:Of course this is possible. You can get the path of your application by using the GetModuleFileName() function: http://msdn.microsoft.com/en-us/library/windows/desktop/ms683197%28v=vs.85%29.aspx
From that filename you can remove the last part which is the actual filename to get the path, if want to have the parent directory just remove the last portion of the pathname again. Append the name of the file you want to run and give it to ShellExecute.



hi, are you there...sorry i dont know if we need to post as quote or as reply for you to receive email notification about the latest convo posts ..... i realy need your help...please if you are in the mood gimme a ring....Thank you!

Duarte V.
alienoiz
 
Posts: 38
Joined: Tue Apr 24, 2012 6:02 am

Re: How to open a file through ShellExecute in parent directory?

Postby alienoiz » Thu Apr 26, 2012 6:33 am

exomo wrote:Wide characters again. You need the L for wide character string literals, L"\\"
If you are working with wide chars you have to use them everywhere, you cannot mix wide strings with "normal" strings.



sorry..i dint saw this email notification...ive been attacked by hackers lately...forget my last post...i will try this now...thanks again
alienoiz
 
Posts: 38
Joined: Tue Apr 24, 2012 6:02 am

Re: How to open a file through ShellExecute in parent directory?

Postby alienoiz » Thu Apr 26, 2012 7:40 am

exomo wrote:Wide characters again. You need the L for wide character string literals, L"\\"
If you are working with wide chars you have to use them everywhere, you cannot mix wide strings with "normal" strings.



OK..the code is not giving me any error but it is also not openning my .exe file....
any idea?
Thank You!
alienoiz
 
Posts: 38
Joined: Tue Apr 24, 2012 6:02 am

Re: How to open a file through ShellExecute in parent directory?

Postby alienoiz » Thu Apr 26, 2012 8:24 am

exomo wrote:Wide characters again. You need the L for wide character string literals, L"\\"
If you are working with wide chars you have to use them everywhere, you cannot mix wide strings with "normal" strings.


maybe its because it cannot identify the GetModuleName for this "dll" file!

Image

see...this is the suposed dll file that is inserted in a project of another type of compiler...so when i set a value to this module it performs an action, but, if i use GetModuleFileName probably it wont recognize the main Project where im working but search for the "dll" file path....although if i set shellexecute with the full path to my external .exe file ...it opens!

can this be the problem???!!!!

maybe i shoud use a code to find the exe file before and then append it to shellexecute instead of using GetModuleFilename!
alienoiz
 
Posts: 38
Joined: Tue Apr 24, 2012 6:02 am

Re: How to open a file through ShellExecute in parent directory?

Postby exomo » Thu Apr 26, 2012 3:10 pm

Please use the edit function if you have something to add to you previous post. Don't make a new post for every new comment.

I have no idea how SynthEdit works. And I'm not really sure about what filename GetModuleFileName() returns when called from a dll.
Is it possible to have some output (like cout <<) in your dll? If yes just print the string you get as filename and cut from the end or append as needed.

Perhaps it is easier to just pass a relative filename like "..\\Test.exe" to ShellExecute. I really can't help you with this.
Who needs a signature anyway.
User avatar
exomo
 
Posts: 935
Joined: Fri Sep 26, 2003 12:30 pm
Location: germany->baden

Re: How to open a file through ShellExecute in parent directory?

Postby alienoiz » Thu Apr 26, 2012 3:20 pm

exomo wrote:Please use the edit function if you have something to add to you previous post. Don't make a new post for every new comment.

I have no idea how SynthEdit works. And I'm not really sure about what filename GetModuleFileName() returns when called from a dll.
Is it possible to have some output (like cout <<) in your dll? If yes just print the string you get as filename and cut from the end or append as needed.

Perhaps it is easier to just pass a relative filename like "..\\Test.exe" to ShellExecute. I really can't help you with this.



Thanks....im gonna try my luck with this....much thanks for your help!
alienoiz
 
Posts: 38
Joined: Tue Apr 24, 2012 6:02 am

Re: How to open a file through ShellExecute in parent directory?

Postby alienoiz » Thu Apr 26, 2012 5:32 pm

you might be helpfull again...i got this code...it works to open the file but how do i set a way to copy the selected directory into the shellexecute in order to do not open the browser for folder a second time?

Code: Select all
      BROWSEINFO bi = { 0 };
        bi.lpszTitle = (L"Browse for your folder! Should be the same where the VST is installed.");
        LPITEMIDLIST pidl = SHBrowseForFolder ( &bi );
      if ( pidl != 0 )
    {
        SHGetPathFromIDList ( pidl, path);

      SetCurrentDirectory ( path );
      hFind = FindFirstFile ( L"Test.exe", &FindFileData );
      
      int Open = (int)ShellExecuteW(NULL, L"open", FindFileData.cFileName, NULL, NULL, SW_SHOWNORMAL);
        IMalloc * imalloc = 0;
        if ( SUCCEEDED( SHGetMalloc ( &imalloc )) )
        {
            imalloc->Free ( pidl );
            imalloc->Release ( );
        }
   
   Open;



Thank you!
alienoiz
 
Posts: 38
Joined: Tue Apr 24, 2012 6:02 am

Previous

Return to For Beginners

Who is online

Users browsing this forum: No registered users and 4 guests