You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

GetMediaInfo.dpr 3.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. {*
  2. * DMDirc - Open Source IRC Client
  3. * Copyright (c) 2006-2017 DMDirc Developers
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a copy
  6. * of this software and associated documentation files (the "Software"), to deal
  7. * in the Software without restriction, including without limitation the rights
  8. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. * copies of the Software, and to permit persons to whom the Software is
  10. * furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be included in
  13. * all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  21. * SOFTWARE.
  22. *
  23. *
  24. * This application attempts to load a dll for media source information.
  25. * It can be run from the commandline like so:
  26. * - GetMediaInfo.exe winamp getArtist
  27. * and it will load the winamp dll and attempt to execute the function "artist"
  28. * Any output will be echoed to the command line with an exit code of 0.
  29. * An exit code of 1 means there was an error from the DLL
  30. * An exit code of 2 means there was an error before the DLL
  31. *
  32. * Methods are very simple:
  33. * Method: function (data: PChar): integer; stdcall;
  34. * A pchar of size 1024 is passed, resulting data should be written to this
  35. * pchar inside the dll.
  36. * The method should then return either 0 to indicate success, or 1 to indicate
  37. * an error. (This will be used as the exit code, and the contents of Data is
  38. * printed to stdout - any returned value > 1 will still give an exitcode of 1)
  39. *}
  40. program GetMediaInfo;
  41. {$MODE Delphi}
  42. uses Windows, sysutils;
  43. var
  44. I: Integer;
  45. Player: String;
  46. MethodName: String;
  47. DLL: HINST;
  48. Method: function (data: PChar): integer; stdcall;
  49. Data: PChar;
  50. begin
  51. // By default, assume fail.
  52. ExitCode := 2;
  53. if ParamCount > 1 then begin
  54. // Params
  55. Player := paramstr(1);
  56. MethodName := paramstr(2);
  57. // Load the DLL
  58. DLL := LoadLibrary(PChar(Player+'.dll'));
  59. if DLL <> HINST(0) then begin
  60. // DLL Exists and is loaded
  61. // Now the actual method we want!
  62. Method := GetProcAddress(DLL, PChar(MethodName));
  63. if @Method <> nil then begin
  64. try
  65. GetMem(Data, 1024);
  66. I := Method(Data);
  67. if I > 1 then I := 1;
  68. writeln(Data);
  69. ExitCode := I;
  70. finally
  71. FreeMem(Data);
  72. end;
  73. end
  74. else begin
  75. writeln('No Method ('+MethodName+') Found');
  76. end;
  77. end
  78. else begin
  79. writeln('No DLL ('+Player+'.dll) Found');
  80. end;
  81. end
  82. else begin
  83. writeln('Usage: GetMediaInfo.exe player function');
  84. writeln('Example: GetMediaInfo.exe winamp getArtist');
  85. end;
  86. end.