bueno señores, queria ver si alguien puede decirme si esta bien este codigo
me salta una advertencia(generalmente nunca le doy importancia) :
compila y funciona perfecto en xp, pero...
[Warning] Project1.dpr(38): Suspicious typecast of String to PWideChar
el codigo estaba pensado para una version superior a delphi 7
pero yo le cambie algunas partes para adaptarlo al ide 7
y necesito que fucione sin errores

Código: Seleccionar todo

program Project1;
 {source code from icode.org }
{$APPTYPE CONSOLE}
{$DEFINE CracksMan} //autor
uses
  Windows,
  ShellApi;

Procedure RestartWithParams();
Var
  param  : string;
begin
  Writeln('tipear parametros y  [Enter] para salir: ');
  Writeln('necesita ayuda?                               '#13#10 +
          '-a   :mostrar "hola mundo" MessageBox.'#13#10 +
          '-b   :mostrar creditos.                   '#13#10 +
          '-c   :mostrar algun argumento              '#13#10);
  Readln(Param);

  //IF (ShellExecute(0, nil, LPCWSTR(ParamStr(0)), LPCWSTR(Param), nil, SW_NORMAL) > 32) then
    IF (ShellExecute(0, nil, pchar(ParamStr(0)), pchar(Param), nil, SW_NORMAL) > 32) then
  Begin
    Halt(0);
  End Else Writeln('fallo para salir de Aplicacion.');
end;

Function Main(): integer;
Var
  Arg : LPCWSTR;
  Argc: integer;
Begin
  Argc := ParamCount();

  IF (Argc = ERROR) Then RestartWithParams();

  For Result := 1 to Argc do
  Begin
    Arg := LPCWSTR(paramstr(Result));
      // Arg := pwidechar(paramstr(Result));

    {   }IF (lstrcmpi(pansichar(Arg),'-a') = 0) then
    Begin
      MessageBox(0, 'hola mundo', 'muy ofuscado', 0);
    End

    Else IF (lstrcmpi(pansichar(Arg),'-b') = 0) then
    Begin
      Writeln('Example by Cracksman at ic0de.org');
    End

    Else IF (lstrcmpi(pansichar(Arg),'-c') = 0) then
    Begin
      Writeln('Argumento: ', Arg);
    End

    Else Writeln('Unknown Param: ', Arg);
  End;
  Result := Argc;
End;

Begin
  Main();

  Writeln('press [Enter] to Exit');
  Readln;
end. 
paresco malo ,pero soy bueno
Prueba así, el 'problema' es la confusión de manejar pwidechar y pansichar, por eso los warnings, con xe5 yo aun me estoy acostumbrando al cambio de tipos de datos en ese aspecto...

Cambiadas 3 cosas y no sé si algo más:

Arg : PChar;
Arg := PChar(paramstr(Result));
IF (lstrcmpi(PChar(Arg),'-a') = 0) then
program Project1;
 {source code from icode.org }
{$APPTYPE CONSOLE}
{$DEFINE CracksMan} //autor
uses
  Windows,
  ShellApi;

Procedure RestartWithParams();
Var
  param  : string;
begin
  Writeln('tipear parametros y  [Enter] para salir: ');
  Writeln('necesita ayuda?                               '#13#10 +
          '-a   :mostrar "hola mundo" MessageBox.'#13#10 +
          '-b   :mostrar creditos.                   '#13#10 +
          '-c   :mostrar algun argumento              '#13#10);
  Readln(Param);

  //IF (ShellExecute(0, nil, LPCWSTR(ParamStr(0)), LPCWSTR(Param), nil, SW_NORMAL) > 32) then
    IF (ShellExecute(0, nil, pchar(ParamStr(0)), pchar(Param), nil, SW_NORMAL) > 32) then
  Begin
    Halt(0);
  End Else Writeln('fallo para salir de Aplicacion.');
end;

Function Main(): integer;
Var
  Arg : PChar;
  Argc: integer;
Begin
  Argc := ParamCount();

  IF (Argc = ERROR) Then RestartWithParams();

  For Result := 1 to Argc do
  Begin
    Arg := PChar(paramstr(Result));
      // Arg := pwidechar(paramstr(Result));

    {   }IF (lstrcmpi(PChar(Arg),'-a') = 0) then
    Begin
      MessageBox(0, 'hola mundo', 'muy ofuscado', 0);
    End

    Else IF (lstrcmpi(pchar(Arg),'-b') = 0) then
    Begin
      Writeln('Example by Cracksman at ic0de.org');
    End

    Else IF (lstrcmpi(pchar(Arg),'-c') = 0) then
    Begin
      Writeln('Argumento: ', Arg);
    End

    Else Writeln('Unknown Param: ', Arg);
  End;
  Result := Argc;
End;

Begin
  Main();

  Writeln('press [Enter] to Exit');
  Readln;
end.
Sin Warnings y funcionando correctamente.
UDTools.net
GitHub: https://github.com/MetalUDT
gracias metal siempre ayudando.
despues que vi tu correccion dije "mira que facil era" yo hubiera
estado 1 dia para encontrar solucion a esos warnigs
gracias metalllllllllll
paresco malo ,pero soy bueno
otra duda con este codigo si tengo 4 parametros -a -b -c -d
y en -c tengo que pasar el nombre de un archivo ejemplo
c:\user>mi.exe -a -b -c [filename] -d
como puedo obtener ese string si cambiara el orden y no fuera necesario
el uso del parametro -d
ejemplo: c:\user>mi.exe -c [filename] -a -b

ya que pasaria de ser paramstr(4) a paramstr(2)
paresco malo ,pero soy bueno
Responder

Volver a “Delphi”