[ASK] Pengertian Sourcecode

Forum diskusi pemrograman VB6

[ASK] Pengertian Sourcecode

Postby sanutra » 19 Feb 2012, 16:17

Om-om mohon pencerahannya untuk sourcecode dibawah ini [-O<
Code: Select all
Private Static Sub GetWord(LongValue As Long, CryptBuffer() As Byte, Offset As Long)
    Dim bb(0 To 3) As Byte
    bb(3) = CryptBuffer(Offset)
    bb(2) = CryptBuffer(Offset + 1)
    bb(1) = CryptBuffer(Offset + 2)
    bb(0) = CryptBuffer(Offset + 3)
    Call CopyMem(LongValue, bb(0), 4)

Private Static Sub PutWord(LongValue As Long, CryptBuffer() As Byte, Offset As Long)
    Dim bb(0 To 3) As Byte
    Call CopyMem(bb(0), LongValue, 4)
    CryptBuffer(Offset) = bb(3)
    CryptBuffer(Offset + 1) = bb(2)
    CryptBuffer(Offset + 2) = bb(1)
    CryptBuffer(Offset + 3) = bb(0)
End Sub
sanutra
Prajurit Dua
Prajurit Dua
 
Posts: 6
Joined: 09 Feb 2012, 13:36
Memberi kopi: 6 cangkir
Mendapat kopi: 0 cangkir

Re: [ASK] Pengertian Sourcecode

Postby Gyus » 22 Feb 2012, 02:48

itu cuma coding fungsi manajemen memori (Array) aja boz... :-?? membaca/ambil trus edit setelah itu ditaruh lagi di memori :D
ImageImage
User avatar
Gyus
Global Moderator
Global Moderator
 
Posts: 1172
Joined: 19 Mar 2010, 20:33
Location: Jakarta Timur - Indonesia
Memberi kopi: 25 cangkir
Mendapat kopi: 84 cangkir

Re: [ASK] Pengertian Sourcecode

Postby Seruling » 22 Feb 2012, 13:16

Mari dibahas baris per baris...


Code: Select all
Private Static Sub GetWord(LongValue As Long, CryptBuffer() As Byte, Offset As Long)

Code: Select all
Private Static Sub PutWord(LongValue As Long, CryptBuffer() As Byte, Offset As Long)


Kalau saya pelajari, kedua sub di atas, maka saya berpendapat:
1. GetWord => bertujuan mengdapatkan nilai Word (4 byte) "LongValue" dari suatu alamat memory "Offset". Hasilnya ditampung di variabel "LongValue", sedangkan alamat memory yang dimaksud adalah "Offset". Variabel "CrypBuffer()" adalah variabel perantara.
2. PutWord => Kebalikannya, yaitu mengcopy nilai Word "LongValue" ke alamat memory "Offset".

Berikutnya:
Code: Select all
Call CopyMem(xxx, yyy, zzz)

Ini sesungguhnya adalah perintah WIndows API, dengan bentuk:
Code: Select all
[Private/Public] Declare Sub CopyMem Lib "kernel32" Alias "RtlMoveMemory"  (Tujuan as Any, Sumber as Any, ByVal Ukuran as Long)


Jadi sebetulnya GetWord dan PutWord dapat lebih disederhanakan lagi, nggak perlu memakai "Buffer", seperti ini:
Code: Select all
Private Declare Sub CopyMem Lib "kernel32" Alias "RtlMoveMemory"  (Tujuan as Any, Sumber as Any, ByVal Ukuran as Long)

Private Sub GetWord(LongValue As Long, Offset As Long)
    CopyMem LongValue, ByVal Offset, 4
End Sub

Private Sub PutWord(LongValue As Long, Offset As Long)
    CopyMem ByVal Offset, LongValue, 4
End Sub


Atau langsung saja memanggil "Sub CopyMem" tanpa harus membuat kode tambahan lagi yang isinya hanya mengganti syntax :lol:

CMIIW
=== Seruling ===
User avatar
Seruling
Kopral Dua
Kopral Dua
 
Posts: 688
Joined: 28 Jun 2010, 19:01
Location: Berhadapan dengan Acer Aspire
Memberi kopi: 34 cangkir
Mendapat kopi: 37 cangkir

Re: [ASK] Pengertian Sourcecode

Postby Gyus » 22 Feb 2012, 17:23

sudah lengkap tuh dibahas sama boz @Seruling :-bd
ImageImage
User avatar
Gyus
Global Moderator
Global Moderator
 
Posts: 1172
Joined: 19 Mar 2010, 20:33
Location: Jakarta Timur - Indonesia
Memberi kopi: 25 cangkir
Mendapat kopi: 84 cangkir


Return to Visual Basic 6.0

Who is online

Users browsing this forum: No registered users and 3 guests