Login  

Blog Stats

News

隨筆分類

文章分類

每月文章

優質好站連結


強力鎯頭 の VB 部落

您好 ! 歡迎蒞臨 Power Hammer 的 VB 部落 ! 網誌內容主要為 VB .Net C# WMI 等相關資訊 , 提供網友參考

如何 登錄註冊 Actvie X DLL , OCX , EXE (OLE) 元件

 

關於ActiveX動態連結程式庫DLLActiveX控制項OCXActiveX執行檔EXE

及物件連結與嵌入OLE 控制項 ( Object Linking and Embedding )

皆需要登錄註冊後方可使用,在此介紹幾種元件註冊方法 :

 

1.       使用 RegSvr32.exe 工具 ( 命令列 DOS 模式下註冊工具 )

 

語法 :

regsvr32 [/u] [/s] [/n] [/i[:cmdline]] dllname

 

參數 :

/u : Unregisters server.

/s : Specifies regsvr32 to run silently and to not display any message boxes.

/n : Specifies not to call DllRegisterServer. You must use this option with /i.

/i:cmdline : Calls DllInstall passing it an optional [cmdline]. When used with /u, it calls dll uninstall.

dllname : Specifies the name of the dll file that will be registered.

/? : Displays help at the command prompt.

 

:

   RegSvr32 C:\123.dll      註冊

   RegSvr32 /u C:\123.dll  反註冊

 

RegSvr32.exe的依存檔案 :

Kernel32.dllUser32.dllOle32.dllWindows NT相關OS平台中Msvcrt.dllAdvapi32.dll檔案。

Regsvr32.exe 會將您嘗試登錄或解除登錄的檔案,連同所有相依檔案一起載入。

如果必要的檔案遺失或損壞了,程序可能無法成功。

 

(可用Depends.exe 來查看依存檔案;該工具有附在 M$ Windows XX Resource Kit 支援工具或其他開發工具中。

 

 

================================================================

 

 

2.       呼叫 API DLLSelfRegister ( 使用 vb6stkit.dll )

 

宣告

Private Declare Function DLLSelfRegister Lib "vb6stkit.dll" _

(ByVal lpDllName As String) As Integer

 

使用

ReturnCode = DLLSelfRegister("元件完整路徑加檔名,:C:\123.dllC:\123.ocx")

 

回傳值 :

                     0        -         OK

                     2        -         無法初始化 OLE 來註冊檔案

                     3        -         註冊檔案時,LoadLibrary() 函數執行失敗!

                     4        -         在檔案中無法找到 DllRegisterServer() 的進入點!

                     5        -         檔案中之 DllRegisterServer() 函數執行失敗!

                     Else   -         註冊檔案時,發生無法預期的錯誤!

 

 

================================================================

 

 

3.       呼叫 API DllRegisterServer

 

宣告

Private Declare Function DllRegisterServer Lib "元件完整路徑加檔名,:C:\123.dllC:\123.ocx " () As Long

 

使用

If DllRegisterServer = &H0 Then

MsgBox "註冊成功 !"

Else

MsgBox "註冊失敗 !"

End If

 

PS: 此方法有先天限制 , 一次只能宣告一個 , 因此也只能註冊一個元件

 

 

================================================================

 

 

4.       呼叫API LoadLibrary GetProcAddressCallWindowProc

 

宣告

Private Declare Function FreeLibrary Lib "kernel32" _

    (ByVal hLibModule As Long) As Long

Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" _

    (ByVal lpLibFileName As String) As Long

Private Declare Function GetProcAddress Lib "kernel32" _

    (ByVal hModule As Long, ByVal lpProcName As String) As Long

Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" _

    (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal Msg As Any, _

    ByVal wParam As Any, ByVal lParam As Any) As Long

 

撰寫函數

Public Function Register(strFile As String, blnRegister As Boolean) As Boolean

    Dim lngLB As Long, lngPA As Long, lngHwnd As Long

    lngHwnd = Screen.ActiveForm.hWnd

    lngLB = LoadLibrary(strFile)

    If lngLB > 0 Then

        lngPA = GetProcAddress(lngLB, IIf(blnRegister, "DllRegisterServer", "DllUnregisterServer"))

        If lngPA > 0 Then Register = CallWindowProc(lngPA, lngHwnd, ByVal 0&, ByVal 0&, ByVal 0&) = &H0

    End If

    FreeLibrary lngLB

End Function

 

參數說明 :

strFile : 元件檔名

blnRegister : 布林值 , True 為登錄註冊元件 , False 為反註冊元件 !

回傳值 : 布林值, True為登錄註冊成功 , False 則為失敗 !

 

使用

If Register("元件完整路徑加檔名,:C:\123.dllC:\123.ocx ", True)  Then

MsgBox "成功 !"

Else

MsgBox "失敗 !"

End If

 

 

================================================================

 

5.       呼叫API LoadLibrary GetProcAddressCreateThreadWaitForSingleObject

 

宣告

Private Declare Function FreeLibrary Lib "kernel32" _

(ByVal hLibModule As Long) As Long

Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" _

(ByVal lpLibFileName As String) As Long

Private Declare Function GetProcAddress Lib "kernel32" _

(ByVal hModule As Long, ByVal lpProcName As String) As Long

Private Declare Function CreateThread Lib "kernel32" _

(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 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 Register(strFile As String, blnRegister As Boolean) As Boolean

    Dim lngLB As Long, lngPA As Long, lngThread As Long, lngExitCode As Long

    lngLB = LoadLibrary(strFile)

    If lngLB > 0 Then

        lngPA = GetProcAddress(lngLB, IIf(blnRegister, "DllRegisterServer", "DllUnregisterServer"))

        If lngPA > 0 Then

            lngThread = CreateThread(ByVal 0&, 0&, ByVal lngPA, ByVal 0&, 0&, lngThread)

            If lngThread Then

                Register = (WaitForSingleObject(lngThread, 5000) = 0)

                If Not Register Then

                    GetExitCodeThread lngThread, lngExitCode

                    ExitThread lngExitCode

                End If

                CloseHandle lngThread

            End If

        End If

    End If

    FreeLibrary lngLB

End Function

 

參數說明 :

strFile : 元件檔名

blnRegister : 布林值 , True 為登錄註冊元件 , False 為反註冊元件 !

回傳值 : 布林值, True為登錄註冊成功 , False 則為失敗 !

 

使用

If Register("元件完整路徑加檔名,:C:\123.dllC:\123.ocx ", True)  Then

MsgBox "成功 !"

Else

MsgBox "失敗 !"

End If

 

 

================================================================

 

 

6.       關於 ActiveX EXE

登錄註冊 : 只要執行該 EXE執行檔 , 即完成註冊

反註冊 : 執行該 EXE 執行檔 , 後面加 /UNREGSERVER 參數即可

 

posted on Thursday, April 06, 2006 3:54 PM

What People Are Saying About This Post...

# re: 關於 ActiveX (OLE) 元件登錄註冊 12/11/2006 12:23 PM 窃听器
OK~

# re: 關於 ActiveX (OLE) 元件登錄註冊 12/14/2006 3:35 PM 硬盘数据恢复
GOOD

# ASP 如何读取 Word 档案内容并显示于网页 12/15/2007 2:13 PM 唐太宗
ASP 如何?取 Word ?案?容并?示于网?

# re: 關於 ActiveX (OLE) 元件登錄註冊 3/28/2008 7:12 PM maslo
51231D321DS2312SD3

# coach outlet online 1/16/2012 8:43 AM coach outlet online
coach outlet online

is the eldest, voice of reason, and authority of the Left 4 Dead 2 team, playing a similar role to Bill in Left 4 Dead.
coach outlet

can provide the coach exactly the same is expected in a retail store. It can help you find bags of various colors, shapes and designs, which prove once again that the coach is actually a selection for the housekeeper.

# louis vuitton uk 1/16/2012 9:28 AM louis vuitton uk
You're going to buy new cheap
louis vuitton uk

and that is really good value.Typically the efficiency, combined with beauty, not to mention adjusted price get this to a victor.Now there are now a multitude of available as well as many creative options.
louis vuitton

Store Online Handbags can also bring great accuracy as well as practical applicability and fashionable.

# coach outlet online 1/16/2012 10:58 AM coach outlet online
I got to know it from my elder sister who owns enviable luxury Coach bags.
coach outlet online

Store is established to be your home shopping paradise.Though handbags are basically an accessory item of girls, there are many modern handbags and wallets for males too as it has become the ultimate fashion accessory at
coach factory outlet

.
http://www.coachoutletonlinecoachusa.com


# coach outlet 1/16/2012 10:58 AM coach outlet
coach outlet

has a zippered closure and buckles for extra security. Shiny brass hardware, rounded leather handle, and an interior pocket. It also includes a limited edition Hawaii luggage tag and lock.
coach outlet store online

generally variety within the buying price of $120.00 in order to $450.00, however they perform possess little purses as well as scarfs which are below $100.00.
http://www.coachoutletonlinestoretime.com

# louis vuitton sale 1/16/2012 11:04 AM louis vuitton sale
I often visit the store online which includes a huge variety louis vuitton sale.I really like these products inside as it values for money.In the web times, even if you are a noble person on louis vuitton outlet, or to real action to prove himself, has been integrated into a new era.If in a foreign country to join the twitter, it is best to join army of micro-Bo; http://www.louisvuittonoutletsaletime.com

# coach factory outlet 1/16/2012 11:04 AM coach factory outlet
In particular, products from coach factory outlet with leather design are fashionable, handmade,leading the wave of American pop.It with simple,durable and unique style to win consumers.coach factory online provides people many coach goods. If you wish to snatch the coach handbag, then this best method is made for that you like for coach discount. http://www.coachfactoryoutlettime.net

# coach factory outlet 1/16/2012 1:48 PM coach factory outlet
As long as you open our coach factory outlet webpage, you will view various Coach New Arrivals which are the most popular also the most fashionable in this year.You can find all kinds of coach bags whatever you chose which one in coach factory outlet online will never be out of fashion. Not only they have many nice and design styles, but also made from the finest leather and fabric.
http://www.coachfactoryoutletonlinemall.com

# louis vuitton uk 1/16/2012 1:49 PM louis vuitton uk
If you have enough leisure time, you may go to the mall or go to the Louis Vuitton franchised store to have a good look at varieties of louis vuitton uk the diverse styles and rich colors of the purses with low cost will surely impress you a lot!louis vuitton Store Online Handbags can also bring great accuracy as well as practical applicability and fashionable.
http://www.louisvuitton-like.org.uk

# coach outlet store 1/16/2012 2:40 PM coach outlet store
Different style bags from Coach Outlet Store are always eloquent statement outside a woman's attitude towards life and career. Thus, women's bag, must exchange the use of occasions, so they are not the same as showing different spatial and temporal rhythm of beauty. Here you can find the latest products in different kinds of coach outlet store online making best materials.They are leisure practical products in the new generations.

http://www.coachoutletstoreonlinehome.com

# coach outlet online 1/16/2012 2:40 PM coach outlet online
Lots of women like which usually amount normally include a Coach Outlet Online ,it provides coziness to many girls that don't even think it is a great bushel of great interest directly to them. Designs of this season give you the unlimited cool feelings in this cool summer. The new designs of Coach products in the coach outlet enrich our daily life.

http://www.coachoutletonlinehome.com

What do you have to say?

Title:
Name:
Url:
驗證碼  
Comments: