add array of byte
#4
تفضل أخي
لا تعتمد على هاتين دالتين لإني كتبتهم الان و توجد بهم بعض الأخطاء
واعد كتابتهم بالدلفي
function amzStrLn(const Arr: array of string): Integer;
procedure amzStrMv(Dst: Pointer; const Src: array of string);
الدالة amzStrLn تقوم بحساب طول السلاسل النصية مع بعض مع إضافة بايت لكل سلسلة والذي يعني null terminted وهو نهاية السلسلة
اما amzStrMv تقوم بنسخ السلاسل ووضعهم بالترتيب لتسهيل عملية كتابتها

كود :
unit shared; interface uses  Windows; type  TSettings = record    Msg: array of string;    test1: array[0..32767] of Byte;    test2: array[0..32767] of Byte;    i: integer;  end;  PSettings = ^TSettings; const  RC_SETTINGS = 'CFG'; function WriteSettings(Filename: PChar; Settings: PSettings): Boolean; function ReadSettings(var Settings: PSettings): Boolean; implementation function amzStrLn(const Arr: array of string): Integer; {by Agmcz} asm  push esi  push ebx  push edx  push ecx  xor ecx, ecx  xor edx, edx  mov esi, [eax]  mov ebx, [eax - 4]  @@loop:  inc ecx  add edx, [esi - 4]  inc edx  mov esi, [eax + ecx * 4]  cmp ecx, ebx  jne @@loop  mov eax, edx  pop ecx  pop edx  pop ebx  pop esi end; procedure amzStrMv(Dst: Pointer; const Src: array of string); {by Agmcz} asm  push edi  push esi  push ecx  push ebx  xor ebx, ebx  xor ecx, ecx  @@loop:  lea edi,[eax]  mov esi,[edx + ebx * 4]  lea esi,[esi]  mov ecx, [esi-4]  inc ecx  add eax, ecx  rep movsb  inc ebx  cmp ebx, [edx - 4]  jne @@loop  pop ebx  pop ecx  pop esi  pop edi end; function WriteSettings(Filename: PChar; Settings: PSettings): Boolean; var  hResource: Thandle;  pBuffer: PByte;  Size, Len: DWORD; begin  Result := False;  hResource := BeginUpdateResource(Filename, False);  if hResource <> 0 then  begin    Size := 4 + amzStrLn(Settings^.Msg) + SizeOf(TSettings) - 4;    GetMem(pBuffer, Size);    Len := Length(Settings^.Msg);        CopyMemory(pBuffer, @Len, 4);    Inc(pBuffer, 4);    amzStrMv(pBuffer, Settings^.Msg);    Inc(pBuffer, amzStrLn(Settings^.Msg));    CopyMemory(pBuffer, @Settings^.test1, SizeOf(TSettings) - 4);    Inc(pBuffer, SizeOf(TSettings) - 4);    Dec(pBuffer, Size);    if UpdateResource(hResource, RT_RCDATA, RC_SETTINGS, 0, pBuffer, Size) then      Result := True;    EndUpdateResource(hResource, False);    FreeMem(pBuffer);  end; end; function ReadSettings(var Settings: PSettings): Boolean; var  hResInfo: HRSRC;  hRes: HGLOBAL;  I, Len: Integer;  pBuffer: PByte; begin  Result := False;  hResInfo := FindResource(hInstance, RC_SETTINGS, RT_RCDATA);  if hResInfo <> 0 then  begin    hRes := LoadResource(hInstance, hResInfo);    if hRes <> 0 then    begin      pBuffer := LockResource(hRes);      CopyMemory(@Len, pBuffer, 4);      Inc(pBuffer, 4);      New(Settings);      SetLength(Settings^.Msg, Len);      for I := 0 to Len - 1 do      begin        Settings^.Msg[I] := PChar(pBuffer);        Inc(pBuffer, Length(Settings^.Msg[I]) + 1);      end;      CopyMemory(@Settings^.test1, pBuffer, SizeOf(TSettings) - 4);      Result := True;    end;  end; end; end.
سبحان الله وبحمده سبحان الله العظيم
[-] كل من 1 user says قال شكرا ل Agmcz على المشاركة المفيدة
  • mohamed49
الرد


الردود في هذا الموضوع
add array of byte - بواسطة mohamed49 - 01-03-2017, 06:45 PM
RE: add array of byte - بواسطة Agmcz - 01-03-2017, 07:25 PM
RE: add array of byte - بواسطة mohamed49 - 01-03-2017, 07:26 PM
RE: add array of byte - بواسطة Agmcz - 03-03-2017, 02:44 AM
RE: add array of byte - بواسطة mohamed49 - 03-03-2017, 07:47 AM

التنقل السريع :


يقوم بقرائة الموضوع: بالاضافة الى ( 1 ) ضيف كريم