Subversion Repositories delphiutils

Rev

Rev 69 | Go to most recent revision | Blame | Last modification | View Log | RSS feed

  1. library LAN_MAC;
  2.  
  3. uses
  4.   Windows,
  5.   SysUtils,
  6.   Classes,
  7.   UD2_PluginIntf in '..\UD2_PluginIntf.pas',
  8.   UD2_PluginUtils in '..\UD2_PluginUtils.pas',
  9.   NetworkUtils in 'NetworkUtils.pas';
  10.  
  11. {$R *.res}
  12.  
  13. const
  14.   PLUGIN_GUID: TGUID = '{8E1AA598-67A6-4128-BB9F-7E624647F584}';
  15.  
  16. function PluginIdentifier: TGUID; cdecl;
  17. begin
  18.   result := PLUGIN_GUID;
  19. end;
  20.  
  21. function IdentificationStringW(lpIdentifier: LPWSTR; cchSize: DWORD): UD2_STATUS; cdecl;
  22. var
  23.   sl, sl2: TStringList;
  24.   i: integer;
  25.   ip, mac: string;
  26.   ec: DWORD;
  27. begin
  28.   sl := TStringList.Create;
  29.   sl2 := TStringList.Create;
  30.   try
  31.     ec := GetLocalMACAddressList(sl2);
  32.     if ec = ERROR_NOT_SUPPORTED then
  33.     begin
  34.       result := UD2_STATUS_NOTAVAIL_OS_NOT_SUPPORTED;
  35.       Exit;
  36.     end
  37.     else if ec <> ERROR_SUCCESS then
  38.     begin
  39.       result := UD2_STATUS_NOTAVAIL_API_CALL_FAILURE;
  40.       Exit;
  41.     end;
  42.  
  43.     // This procedure should not find any more MAC addresses...
  44.     GetLocalIPAddressList(sl);
  45.     for i := 0 to sl.Count-1 do
  46.     begin
  47.       ip := sl.Strings[i];
  48.       ec := GetMACAddress(ip, mac);
  49.       if ec = ERROR_NOT_SUPPORTED then
  50.       begin
  51.         result := UD2_STATUS_NOTAVAIL_OS_NOT_SUPPORTED;
  52.         Exit;
  53.       end
  54.       else if (ec = S_OK) and
  55.               (mac <> '') and
  56.               (sl2.IndexOf(mac) = -1) then
  57.       begin
  58.         sl2.add(mac);
  59.       end;
  60.     end;
  61.     result := UD2_WriteStringListToPointerW(lpIdentifier, cchSize, sl2);
  62.   finally
  63.     sl.Free;
  64.     sl2.Free;
  65.   end;
  66. end;
  67.  
  68. function PluginNameW(lpPluginName: LPWSTR; cchSize: DWORD; wLangID: LANGID): UD2_STATUS; cdecl;
  69. var
  70.   stPluginName: WideString;
  71.   primaryLangID: Byte;
  72. begin
  73.   primaryLangID := wLangID and $00FF;
  74.   if primaryLangID = LANG_GERMAN then
  75.     stPluginName := 'MAC-Adressen'
  76.   else
  77.     stPluginName := 'MAC addresses';
  78.   result := UD2_WritePascalStringToPointerW(lpPluginName, cchSize, stPluginName);
  79. end;
  80.  
  81. function PluginVendorW(lpPluginVendor: LPWSTR; cchSize: DWORD; wLangID: LANGID): UD2_STATUS; cdecl;
  82. begin
  83.   result := UD2_WritePascalStringToPointerW(lpPluginVendor, cchSize, 'ViaThinkSoft');
  84. end;
  85.  
  86. function PluginVersionW(lpPluginVersion: LPWSTR; cchSize: DWORD; wLangID: LANGID): UD2_STATUS; cdecl;
  87. begin
  88.   result := UD2_WritePascalStringToPointerW(lpPluginVersion, cchSize, '1.0');
  89. end;
  90.  
  91. function IdentificationMethodNameW(lpIdentificationMethodName: LPWSTR; cchSize: DWORD): UD2_STATUS; cdecl;
  92. var
  93.   stIdentificationMethodName: WideString;
  94. begin
  95.   stIdentificationMethodName := 'LAN_MAC';
  96.   result := UD2_WritePascalStringToPointerW(lpIdentificationMethodName, cchSize, stIdentificationMethodName);
  97. end;
  98.  
  99. function CheckLicense(lpReserved: LPVOID): UD2_STATUS; cdecl;
  100. begin
  101.   result := UD2_STATUS_OK_LICENSED;
  102. end;
  103.  
  104. function DescribeOwnStatusCodeW(lpErrorDescription: LPWSTR; cchSize: DWORD; statusCode: UD2_STATUS; wLangID: LANGID): BOOL; cdecl;
  105. begin
  106.   // This function does not use non-generic status codes
  107.   result := FALSE;
  108. end;
  109.  
  110. exports
  111.   PluginInterfaceID         name mnPluginInterfaceID,
  112.   PluginIdentifier          name mnPluginIdentifier,
  113.   PluginNameW               name mnPluginNameW,
  114.   PluginVendorW             name mnPluginVendorW,
  115.   PluginVersionW            name mnPluginVersionW,
  116.   IdentificationMethodNameW name mnIdentificationMethodNameW,
  117.   IdentificationStringW     name mnIdentificationStringW,
  118.   CheckLicense              name mnCheckLicense,
  119.   DescribeOwnStatusCodeW    name mnDescribeOwnStatusCodeW;
  120.  
  121. end.
  122.