Langsung ke konten utama

Cara Register File dengan Visual Basic

Dalam membangun sebuah Aplikasi pastilah sangat dibutuhkan file - file pendukung supaya aplikasinya kelihatan lebih profesional seperti file Ocx , file Dll dan lain sebagainya. Topik kali ini masih seputar Tutorial Visual Basic yaitu mengenai Cara Register File pendukung tersebut lewat coding dengan Visual Basic karena banyak kasus file - file tersebut tidak akan berjalan sebelum didaftarkan atau diregister ke Sistem.

Sebagai contoh mungkin sobat - sobat pernah mengalami aplikasinya tidak dapat dijalankan atau istilahnya runtime error setelah di Instalkan kekomputer lain karena file pendukung tidak diregister, nah bagai mana caranya supaya langsung diregister melalui coding bagi yang tertarik silahkan ikuti langkah - langkah berikut

'Letakan Coding dibawah ini pada Module Project
Private Declare Function LoadLibraryRegister Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long
Private Declare Function CreateThreadForRegister Lib "kernel32" Alias "CreateThread" (lpThreadAttributes As Any, ByVal dwStackSize As Long, ByVal lpStartAddress As Long, ByVal lParameter As Long, ByVal dwCreationFlags As Long, lpThreadID As Long) As Long
Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Private Declare Function GetProcAddressRegister Lib "kernel32" Alias "GetProcAddress" (ByVal hModule As Long, ByVal lpProcName As String) As Long
Private Declare Function FreeLibraryRegister Lib "kernel32" Alias "FreeLibrary" (ByVal hLibModule As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function GetExitCodeThread Lib "kernel32" (ByVal hThread As Long, lpExitCode As Long) As Long
Private Declare Sub ExitThread Lib "kernel32" (ByVal dwExitCode As Long)

Public Function RegServer(ByVal FileName As String) As Boolean
RegServer = RegSvr32(FileName, False)
End Function

Public Function UnRegServer(ByVal FileName As String) As Boolean
UnRegServer = RegSvr32(FileName, True)
End Function

Private Function RegSvr32(ByVal FileName As String, bUnReg As Boolean) As Boolean

Dim lLib As Long
Dim lProcAddress As Long
Dim lThreadID As Long
Dim lSuccess As Long
Dim lExitCode As Long
Dim lThread As Long
Dim bAns As Boolean
Dim sPurpose As String

sPurpose = IIf(bUnReg, "DllUnregisterServer", _
"DllRegisterServer")

If Dir(FileName) = "" Then Exit Function

lLib = LoadLibraryRegister(FileName)
If lLib = 0 Then Exit Function

lProcAddress = GetProcAddressRegister(lLib, sPurpose)

If lProcAddress = 0 Then
FreeLibraryRegister lLib
Exit Function
Else
lThread = CreateThreadForRegister(ByVal 0&, 0&, ByVal lProcAddress, ByVal 0&, 0&, lThread)
If lThread Then
lSuccess = (WaitForSingleObject(lThread, 10000) = 0)
If Not lSuccess Then
Call GetExitCodeThread(lThread, lExitCode)
Call ExitThread(lExitCode)
bAns = False
Exit Function
Else
bAns = True
End If
CloseHandle lThread
FreeLibraryRegister lLib
End If
End If
RegSvr32 = bAns
End Function

'Contoh Penerapan Fungsi-fungsi Register diatas
Public Function Sub RegisterFile() as Boolean
Dim FileSys1 As String

FileSys1 = "C:\Windows\System32\vbaListView6.ocx"
If Dir(FileSys1) <> "" Then
RegisterFile = RegServer(FileSys1)
end if
End Function

Sekarang masukan fungsi RegisterFile tersebut kedalam Start up Program misal di Sub Main Coding seperti dibawah ini

Sub Main()
call RegisterFile
End Sub


Cukup dulu pembahasan tentang Cara Register File mudah-mudahan ada mamfaat nya bagi sobat-sobat, kalau ada kesempatan akan kita lanjutkan tentang pembahasan yang lain yang pasti masih seputar Tutorial Visual Basic selamat mencoba dan terima kasih.

Komentar

Postingan populer dari blog ini

BlackBerry Buka Pendaftaran BBM untuk iOS dan Android

         Rencana BlackBerry membuka layanan pesan singkat andalannya untuk umum sudah diumumkan beberapa waktu lalu di acara BlackBerry Live 2013 di Orlando, Amerika Serikat. Saat itu CEO BlackBerry Thorsten Heins menyebutkan bahwa BlackBerry Messenger (BBM) akan segera hadir di perangkat iOS dan Android. Meskipun sudah diumumkan secara resmi, layanan BBM untuk perangkat non-BlackBerry tak langsung hadir. Perusahaan asal Kanada itu baru akan menyajikan layanan andalannya tersebut mulai bulan Juni atau Juli mendatang. Bagi pengguna perangkat berbasis iOS maupun Android yang sudah tak sabar mencicipi BBM bisa mendaftarkan diri langsung di situs resmi BlackBerry. Dengan mendaftarkan alamat email di situs BlackBerry, Anda berkesempatan menjadi salah satu orang pertama yang menikmati layanan BBM di perangkat iOS ata...

Killing me inside awake lirik

LIRIK LAGU KILLING ME INSIDE WITH AWAKE Take my heart and carry me now And don't let me out to get a terrible day I cant feel my hearth and the blood That youre sharing me is killing me And i just want to wake up and say What is like to be loved to be killed to be dying? That the feeling here inside my heart I want you back to me i need you now I want you back to me i need you now I cut my vain, i'm waiting in pain And with the blood shattered all over the blade I got to say, the way that you are counting me Its scaring me But baby i just came here to say What is like to be loved to be killed to be dying? That the feeling here inside my heart I want u back to me i need want you now What is like to be loved To be killed to be dying? DIstressed Out between you bit me No more danger makes me feel Just like dying now Cut out my finger and pull the trigger Right on my disaster I felt its like i want to celebrate the day Just like the kids with their lollypop Just like i have the dag...