Subversion Repositories userdetect2

Rev

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