Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to register a dll from visual basic application.

Posted on 2001-09-04
9
Medium Priority
?
30,608 Views
Last Modified: 2013-11-25
i created a simple project using visual basic 6.0 .
Here i want to register a dll (given the path of dll). I am trying to use
regsvr32 "C:\ABC\ABCDLL.dll"
but it's not working. I am looking in the msdn help but not getting any hint. Any help will be appreciated.
0
Comment
Question by:nkunapaneni
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 8

Expert Comment

by:Dave_Greene
ID: 6454458
Try

Shell regsvr32.exe "C:\ABC\ABCDLL.dll"
0
 
LVL 18

Accepted Solution

by:
bobbit31 earned 400 total points
ID: 6454466
Try this:

Public Declare Function GetProcAddress _
  Lib "kernel32" _
  (ByVal hModule As Long, _
   ByVal lpProcName As String) _
  As Long

Public Declare Function LoadLibrary _
   Lib "kernel32" Alias "LoadLibraryA" _
   (ByVal lpLibFileName As String) As Long

Public Declare Function CreateThread Lib "kernel32" _
(lpThreadAttributes As Long, ByVal dwStackSize As Long, _
lpStartAddress As Long, lpParameter As Any, ByVal dwCreationFlags As Long, _
lpThreadId As Long) As Long

Public Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds
As Long) As Long
Public Declare Function GetExitCodeThread Lib "kernel32" (ByVal hThread As Long, lpExitCode As Long)
As Long
Public Declare Sub ExitThread Lib "kernel32" (ByVal dwExitCode As Long)
Public Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Public Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As Long) As Long

Function VBRegSvr32(ByVal sServerPath As String, _
                                          Optional fRegister = True) As Boolean
Dim hMod As Long            ' module handle
Dim lpfn As Long            ' reg/unreg function address
Dim lpThreadId As Long      ' dummy var that get's filled
Dim hThread As Long         ' thread handle
Dim fSuccess As Boolean     ' if things worked
Dim dwExitCode As Long      ' thread's exit code if it doesn't finish

   Screen.MousePointer = vbHourglass

   ' Load the server into memeory
   hMod = LoadLibrary(sServerPath)
       
   ' Get the specified function's address and our msgbox string.
   If fRegister Then
       lpfn = GetProcAddress(hMod, "DllRegisterServer")
   Else
       lpfn = GetProcAddress(hMod, "DllUnregisterServer")
   End If
     
   ' If we got a function address...
   If lpfn Then
       ' Create an alive thread and execute the function.
       hThread = CreateThread(ByVal 0, 0, ByVal lpfn, ByVal 0, 0, lpThreadId)
         
       ' If we got the thread handle...
       If hThread Then
           ' Wait 10 secs for the thread to finish (the function may take a while...)
           fSuccess = (WaitForSingleObject(hThread, 10000) = WAIT_OBJECT_0)
           
           ' If it didn't finish in 5 seconds...
           If Not fSuccess Then
               ' Something unlikely happened, lose the thread.
               Call GetExitCodeThread(hThread, dwExitCode)
               Call ExitThread(dwExitCode)
           End If
     
       ' Lose the thread handle
       Call CloseHandle(hThread)
       End If   ' hThread
   End If   ' lpfn
     
   ' Free server if we loaded it.
   If hMod Then Call FreeLibrary(hMod)
     
   Screen.MousePointer = vbDefault
     
   If fSuccess Then
       VBRegSvr32 = True
   Else
       MsgBox ("Error: " & sServerPath)
       VBRegSvr32 = False
   End If
   
End Function
0
 
LVL 18

Expert Comment

by:bobbit31
ID: 6454467
you would obviously then do:

VBRegSvr32 "C:\ABC\ABCDLL.dll" to register

and

VBRegSvr32 "C:\ABC\ABCDLL.dll", false to unregister
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 38

Expert Comment

by:PaulHews
ID: 6454741
Bobbit, where did you find that code?  It is identical to something I posted a long time ago, but I have no idea where I found it.
0
 
LVL 101

Expert Comment

by:mlmcc
ID: 6455561
listening
0
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 6455602
<me too..>
0
 
LVL 18

Expert Comment

by:bobbit31
ID: 6457181
i don't know, i found it somewhere too.  It was a post from someone on ee so it could've been from your post ;)
0
 

Expert Comment

by:KRITGuy
ID: 10802483
Thank you for posting.  I needed this.

Cheers,
Kevin
0
 

Expert Comment

by:roycarson
ID: 11003562
What is the  WAIT_OBJECT_0      value in the above code? It looks just what I need.
Cheers Roy
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question