carlosmoralesm
06-01-2005, 01:17:58
como puedo hacer que un exe reciba parametros externos
esto es que cuando lo llamo me pide escribir el parametro
pero quiero que funcione de la siguiente forma
myprogram.exe /1 /4,017,16
o
myprogram.exe -1 -4,017,16
esto es para pasarle directo los parametros y no utilizar el
comando scanf
#include <time.h>
#include <stdio.h>
#include <string.h>
#include <windows.h>
#include "MyBlasterUtil.h"
#define MAX_TOKEN_LEN 128
char blaststr[20000];
void main (int argc, char**argv)
{
int devNum;
char keyName[MAX_TOKEN_LEN];
unsignedchar outstr[1024];
char hexstr[1024];
char charstr[10];
unsignedint i, j;
int size;
printf("Version 1.0\n");
printf("Type in 1 for code library keys or 0 to learn\n");
scanf("%d", &devNum);
if (devNum)
{
while(1) {
printf("UEI type values are:\n0=TV, 1=Cable, 2=Video Accessory, 3=Satellite, 4=VCR, 5=Laser Disk,\n6=DVD, 7=Tuner/Amp, 8=Amp/Misc. Audio, 9=CD, 10=Home Control\n");
printf("There are thousands of UEI code values representing different manufacturers.\nConsult mytvstore.com/support.html for a list of them\n");printf("UEI key values vary by device\n");
printf("As an example, the sequence 4,162,16 represents VCR,Panasonic,POWER.\n");
printf("Input \'ueitype,ueicode,key,key...\'\n");
scanf("%s", keyName);
printf("\n");
Emit(keyName);
}
return;
}
else
{
for (j=0; j<3; j++)
{
printf("press and hold custom key to learn (5 seconds)\n");
if (LearnDeviceKey(&size, outstr, j+1) == 0) {
printf("outstr=");
hexstr[0] = '\0';
for (i=0; i<(unsignedint)size; i++)
{
sprintf(charstr, "%.2X", outstr[i]);
printf(charstr);strcat(hexstr, charstr);
}
printf("\n");
}
while (1)
{
printf("type next to record the next key or any other word to output the last learned key\n");
scanf("%s", keyName);
if (!stricmp(keyName, "NEXT")) break;
EmitLearned(hexstr);
}
}
return;
}
}
Gracias de Antemano
Carlosmm
esto es que cuando lo llamo me pide escribir el parametro
pero quiero que funcione de la siguiente forma
myprogram.exe /1 /4,017,16
o
myprogram.exe -1 -4,017,16
esto es para pasarle directo los parametros y no utilizar el
comando scanf
#include <time.h>
#include <stdio.h>
#include <string.h>
#include <windows.h>
#include "MyBlasterUtil.h"
#define MAX_TOKEN_LEN 128
char blaststr[20000];
void main (int argc, char**argv)
{
int devNum;
char keyName[MAX_TOKEN_LEN];
unsignedchar outstr[1024];
char hexstr[1024];
char charstr[10];
unsignedint i, j;
int size;
printf("Version 1.0\n");
printf("Type in 1 for code library keys or 0 to learn\n");
scanf("%d", &devNum);
if (devNum)
{
while(1) {
printf("UEI type values are:\n0=TV, 1=Cable, 2=Video Accessory, 3=Satellite, 4=VCR, 5=Laser Disk,\n6=DVD, 7=Tuner/Amp, 8=Amp/Misc. Audio, 9=CD, 10=Home Control\n");
printf("There are thousands of UEI code values representing different manufacturers.\nConsult mytvstore.com/support.html for a list of them\n");printf("UEI key values vary by device\n");
printf("As an example, the sequence 4,162,16 represents VCR,Panasonic,POWER.\n");
printf("Input \'ueitype,ueicode,key,key...\'\n");
scanf("%s", keyName);
printf("\n");
Emit(keyName);
}
return;
}
else
{
for (j=0; j<3; j++)
{
printf("press and hold custom key to learn (5 seconds)\n");
if (LearnDeviceKey(&size, outstr, j+1) == 0) {
printf("outstr=");
hexstr[0] = '\0';
for (i=0; i<(unsignedint)size; i++)
{
sprintf(charstr, "%.2X", outstr[i]);
printf(charstr);strcat(hexstr, charstr);
}
printf("\n");
}
while (1)
{
printf("type next to record the next key or any other word to output the last learned key\n");
scanf("%s", keyName);
if (!stricmp(keyName, "NEXT")) break;
EmitLearned(hexstr);
}
}
return;
}
}
Gracias de Antemano
Carlosmm