Copying Executables with Windows Programs etc

Started by
6 comments, last by masonium 22 years, 4 months ago
I just have a few questions about how to do certain tasks in a windows program. I investigated all of these in MSDN and came up with didly-squat. 1. Is there a way that you can make your Windows program copy itself into another folder? 2. How do you make a program run another program? 3. How, if possible, do you change the window procedure after creating the window? 4. How do you create lnk files from within a program?
Advertisement
Trying to build an installer? Might want to check out the Pimp software from nullsoft then.

Here are short answers to your questions.

1. Yes.
2. Use the CreateProcess or ShellExecute api''s.
3. Subclass the window.
4. Use the IShellLink COM interface.

quote:1. Is there a way that you can make your Windows program copy itself into another folder?

Yes.

Oh, you were expecting an explanation. Spawn/run/start another program which takes the name of your application module and a target directory as filename. That program could even be the command-line copy.

quote:2. How do you make a program run another program?

ShellExecute()
*spawn() family of functions

quote:3. How, if possible, do you change the window procedure after creating the window?

It might be possible through SetWindowLong(), but I sincerely doubt it. You might have to destroy and recreate the window...

quote:4. How do you create lnk files from within a program?

a.) What are lnk files?
b.) What are you really trying to do? There may be a better way...

[ GDNet Start Here | GDNet FAQ | MS RTFM | STL | Google ]
Thanks to Kylotan for the idea!
I found the ShellExecute function in MSDN. Now my question is, how would I right a program that does a command-line copy? I know how to use the copy function manually in DOS, but I don''t know how to do it from within a program. Also, is there anything I use besides ShellExecute, or just that?
Funnily enough: CopyFile() and CopyFileEx()

Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site

For link files: Look at the Win32 source behind libHFS. I put it under an extremely open license, so do whatever you want with it.
Remember, though, that code is in C, you''ll have to change it to have it work in C++ (due to the COM stuff being different in each). All of the vtable lines go through this process to become C++:
  /* Original */Fish->lpVtbl->Bob(Fish,1,2,3);// BecomesFish->Bob(1,2,3);  

Or you can simply use the static library I supplied for MSVC.

[Resist Windows XP''s Invasive Production Activation Technology!]
What .lib''s or headers do you need to use ShellExecute or ShellExecuteEx?
masonium. first you missed S1CA answer of using CopyFile() and CopyFileEx(). second msdn docs when explaining ANY api call or function will tell you the OS it needs, headerfiles it is defined in, and the libs you can link to.

This topic is closed to new replies.

Advertisement