View Full Version : C++ question, how to get directory info...
Corey
07-22-2004, 02:45 AM
OK so I'm creating a basic free add-on for AMS so people can add optional command line functionality to their apps. It's a small .exe which people can include (beside their autorun.exe) with their project that, when called, simply creates a .lua file at system root which contains the first command line parameter and then launches the autorun.exe (which detects/deletes that .lua file at startup) hidden. It's a learning excercise, but it could be cool for people to create multi-state or modal AMS apps, i.e. "Presentation Mode" or "Admin Mode", etc. according to command line switches. I remember someone asked for this a while back...
Anyhow OK so here's what I got so far, but I can't figure out how to use GetWindowsDirectory or even if that's what I should be doing. If anyone can help me figure out how to create the amsCmd.lua file automatically at %SYSTEMROOT% instead of c:\ that would be great. Thanks. :)
#include <iostream>
#include <windows.h>
#include <shellapi.h>
#include <fstream.h>
int main(int argc, char* argv[]) {
ofstream myCode ("c:\\amsCmd.lua");
if (myCode.is_open())
{
myCode << "amsCmd=\"";
myCode << argv[1];
myCode << "\";";
myCode.close();
}
ShellExecute(0, "open", "autorun.exe", NULL, NULL, SW_HIDE);
return 0;
}
Corey Milner
Creative Director, Indigo Rose Software (http://www.indigorose.com)
Corey
07-22-2004, 03:17 AM
Oh yeah. Here's two more cool things that I would appreciate if someone could show me:
1. How to make it loop through all parameters passed and write them to amsCmd.lua as a table instead of just writing the first one as a variable (as I have it).
2. Any possible ways to make this tinier in file size. The tinier the better.
Thanks, that should make for a nifty little command line wrapper add-on for AMS projects! Perfect for people who are building utilities, document viewers, or advanced media players, etc... :yes
Corey Milner
Creative Director, Indigo Rose Software (http://www.indigorose.com)
#include <iostream>
#include <windows.h>
#include <shellapi.h>
#include <fstream.h>
int main(int argc, char **argv)
{
ofstream myCode ("c:\\amsCmd.lua");
if (myCode.is_open())
{
for(int i=1; i<argc, i++)
{
myCode << "amsCmd=\"" + argv[i] + "\";\n";
}
myCode.close();
}
ShellExecute(0, "open", "autorun.exe", NULL, NULL, SW_HIDE);
return 0;
}
OK so I'm creating a basic free add-on for AMS so people can add optional command line functionality to their apps. It's a small .exe which people can include (beside their autorun.exe) with their project that, when called, simply creates a .lua file at system root which contains the first command line parameter and then launches the autorun.exe (which detects/deletes that .lua file at startup) hidden. It's a learning excercise, but it could be cool for people to create multi-state or modal AMS apps, i.e. "Presentation Mode" or "Admin Mode", etc. according to command line switches. I remember someone asked for this a while back...
Anyhow OK so here's what I got so far, but I can't figure out how to use GetWindowsDirectory or even if that's what I should be doing. If anyone can help me figure out how to create the amsCmd.lua file automatically at %SYSTEMROOT% instead of c:\ that would be great. Thanks. :)
[code]
TJ_Tigger
07-22-2004, 08:23 AM
#include <iostream>
#include <windows.h>
#include <shellapi.h>
#include <fstream.h>
int main(int argc, char **argv)
{
ofstream myCode ("c:\\amsCmd.lua");
if (myCode.is_open())
{
for(int i=1; i<argc, i++)
{
myCode << "amsCmd=\"" + argv[i] + "\";\n";
}
myCode.close();
}
ShellExecute(0, "open", "autorun.exe", NULL, NULL, SW_HIDE);
return 0;
}
It's all geek to me. :)
Brett
07-22-2004, 09:23 AM
Corey, what would be the difference between using your app over the built-in _CommandLineArgs table in AMS50?
To use GetWindowsDirectory:
char szFolderName[MAX_PATH];
GetWindowsDirectory(szFolderName,MAX_PATH);
// Now you have the windows folder in szFolderName
I was wondering the same thing, but assumed it was for the learning experience.
Corey, what would be the difference between using your app over the built-in _CommandLineArgs table in AMS50?
To use GetWindowsDirectory:
char szFolderName[MAX_PATH];
GetWindowsDirectory(szFolderName,MAX_PATH);
// Now you have the windows folder in szFolderName
Corey
07-22-2004, 12:28 PM
Yeah, the only way I can learn is by making stuff. I didn't think there was a way to automatically run an app completely hidden when _CommandLineArgs is present, so I thought this might do that.
Tigg. Me 2. :yes
Corey Milner
Creative Director, Indigo Rose Software (http://www.indigorose.com)
vBulletin® v3.7.3, Copyright ©2000-2009, Jelsoft Enterprises Ltd.