Thng tin: Lm th? no regsvr32.exe Regsvr32.exe ng k? v Unregisters COM DLLs

D?ch tiu ? D?ch tiu ?
ID c?a bi: 207132 - Xem s?n ph?m m bi ny p d?ng vo.
Bung t?t c? | Thu g?n t?t c?

? Trang ny

TM T?T

Bi vi?t ny m t? cch chng tr?nh regsvr32.exe RegSvr32.exe ng k? v unregisters m?t m h?nh ?i t?ng thnh ph?n (COM) th vi?n lin k?t ?ng (DLL). B?n c th? s? d?ng thng tin ny ? kh?c ph?c l?i x?y ra khi b?n c? g?ng s? d?ng chng tr?nh regsvr32.exe RegSvr32.exe v?i DLL COM c?a b?n.

THNG TIN THM

Regsvr32.exe RegSvr32.exe g?i ch?c nng Win32 sau y theo th? t? ny:
  • OleInitialize
  • LoadLibrary n?p DLL
  • EFS ho?c DllUnregisterServer
  • FreeLibrary
  • OleUninitialize
Thng th?ng, regsvr32.exe RegSvr32.exe khng thnh cng v? cc LoadLibrary, EFS, ho?c DllUnregisterServer ch?c nng l?i.LoadLibrary c th? khng n?u khng ph?i l t?p DLL trong ?ng d?n ? ch? ?nh, ho?c n?u ?ng d?n ? ch? ?nh l khng chnh xc. LoadLibrary c?ng c th? th?t b?i n?u m?t trong cc ph? thu?c c?a DLL m b?n ang c? g?ng ? t?i khng ?c p ?ng; ni cch khc, n?u m?t ph? thu?c DLL khng c ho?c khng ph?i l ?ng d?n ? ch? ?nh.

CHU Y: B?n c th? s? d?ng cng c? Depends.exe ? ki?m tra xem c ho?c khng c t?t c? cc ph? thu?c c?a DLL c?a b?n ?c p ?ng. Depends.exe ?c bao g?m v?i Microsoft n?n t?ng ph?n m?m pht tri?n Kit (SDK), m tu v?i Microsoft Visual Studio.

DLL c?a b?n ph?i th?c hi?n EFS v DllUnregisterServer, m ch?a logic l c?n thi?t ? thm ho?c xa cc m?c ng k? yu c?u cho cc thnh ph?n COM. Regsvr32.exe RegSvr32.exe t?m th?y i?m nh?p c?nh cho cc ch?c nng ny, v cc cu?c g?i chng m?t cch thch h?p.

CHU Y: N?u b?n s? d?ng thu?t s? Microsoft ho?t ?ng m?u th vi?n (ATL) ? t?o ra cc DLL COM, thu?t s? t?o ra m? c?n thi?t cho EFS v DllUnregisterServer.

N?u b?n s? d?ng Microsoft Visual C++, xem m?u n?n t?ng SDK lc \Platform SDK\Samples\Com\Fundamentals\Async\Server.

V d?-by-step

M?u sau y m t? cc ch?c nng ng k? b?n c th? s? d?ng ? ng k? v unregister DLL COM c?a b?n.

B?n c?ng c th? vi?t m? ring c?a b?n ? lm nh?ng g? regsvr32.exe RegSvr32.exe no. i?u ny s? gip ? xc ?nh, c l?p v kh?c ph?c l?i d? dng hn.

? t?o ra m?t ?ng d?ng Win32 m b?n c th? s? d?ng ? ng k? ho?c unregister DLL COM c?a b?n, th?c hi?n theo cc b?c sau:
  1. Trong Visual C++, t?o ra m?t ?ng d?ng Win32 m?i tn l ng k?. Ch?p nh?n t?t c? cc gi tr? m?c ?nh.
  2. T?o m?t t?p tin .cpp m?i tn l Register.cpp, v thm n vo d? n.
  3. Dn o?n m? sau trong Register.cpp:
    #include <tchar.h>
    #include <afxole.h>
    #include <stdlib.h>
    
    #define FAIL_ARGS    1
    #define FAIL_OLE     2
    #define FAIL_LOAD    3
    #define FAIL_ENTRY   4
    #define FAIL_REG     5 
    
    static char szAppName[] = "Register";
    static char szUsage[] = "\n\nUsage: Register [/u] dllname";
    static char szDllRegSvr[] = "DllRegisterServer";
    static char szDllUnregSvr[] = "DllUnregisterServer"; 
    
    int PASCAL WinMain(
    		   HINSTANCE hInstance, 
    		   HINSTANCE hPrev, 
    		   LPSTR pszCmdLine, 
    		   int nCmdShow)
    {   
    	int iReturn = 0;       
    	HRESULT (FAR STDAPICALLTYPE * lpDllEntryPoint)(void);  
    	static TCHAR szMsgBuffer[_MAX_PATH*4];         
    	BOOL bVisualC = FALSE; 
    	BOOL bSilent = FALSE;  
    	BOOL bUnregister = FALSE;      
    	LPSTR pszDllEntryPoint = szDllRegSvr;  
    	LPSTR pszDllName = NULL;
    	char szCmdLineCopy[_MAX_PATH]; 
    	strcpy(szCmdLineCopy, pszCmdLine);             
    	LPSTR pszTmp = szCmdLineCopy;  
    	LPSTR pszTok;          
    	
    	while ((pszTok = strtok(pszTmp, " \t")) != NULL)       
    	{                                
    		pszTmp = NULL; 
    		
    		if ((pszTok[0] == '-') || (pszTok[0] == '/'))
    		{      
    			switch (pszTok[1])     
    			{      
    			case 'v':      
    			case 'V':
    				bVisualC = TRUE;
    				break;         
    			case 's':      
    			case 'S':
    				bSilent = TRUE;
    				break;         
    			case 'u':      
    			case 'U':
    				bUnregister = TRUE;
    				pszDllEntryPoint = szDllUnregSvr;
    				break;         
    			default:
    				wsprintf(szMsgBuffer, 
    					"Unrecognized flag: %s%s", 
    					pszTok, 
    					(LPCSTR)szUsage);
    				if (!bSilent)  
    					MessageBox(NULL, 
    					   szMsgBuffer, 
    					   szAppName, 
    					   MB_TASKMODAL | MB_ICONEXCLAMATION);
    				return FAIL_ARGS;      
    			}
    		}
    		else
    		{      
    			if (pszDllName == NULL)
    				pszDllName = pszTok;   
    			else   
    			{
    				wsprintf(szMsgBuffer, 
    					"Extra argument on command line: %s%s", 
    					pszTok, 
    					(LPCSTR)szUsage);
    				if (!bSilent)  
    					MessageBox(NULL, 
    					   szMsgBuffer, 
    					   szAppName, 
    					   MB_TASKMODAL | MB_ICONEXCLAMATION);
    				return FAIL_ARGS;      
    			}
    		}      
    	}      
    	
    	if (pszDllName == NULL)        
    	{
    		if (!bSilent)
    		{      
    			if (bVisualC)  
    			{
    				MessageBox(NULL, 
    				"This command is only valid when "
    				"an OLE Custom Control project is open.", 
    				bUnregister ? 
    				"Unregister Control" : "Register Control",
    				MB_TASKMODAL | MB_ICONEXCLAMATION);
    			}
    			else   
    			{
    				wsprintf(szMsgBuffer, 
    					_T("No DLL name specified%s"), 
    					(LPCSTR)szUsage);
    				MessageBox(NULL, 
    					szMsgBuffer, 
    					szAppName, 
    					MB_TASKMODAL | MB_ICONEXCLAMATION);
    			}
    		}
    		return FAIL_ARGS;      
    	}
    	
    	if (FAILED(OleInitialize(NULL)))       
    	{
    		if (!bSilent)  
    			MessageBox(NULL, 
    				"OleInitialize failed.", 
    				szAppName, 
    				MB_TASKMODAL | MB_ICONINFORMATION);
    		return FAIL_OLE;       
    	}              
    	
    	HINSTANCE hLib = LoadLibrary(pszDllName);      
    	
    	if (hLib < (HINSTANCE)HINSTANCE_ERROR) 
    	{
    		wsprintf(szMsgBuffer, 
    			"LoadLibary(\"%s\") failed.", 
    			pszDllName);
    		MessageBox(NULL, 
    			szMsgBuffer, 
    			szAppName, 
    			MB_TASKMODAL | MB_ICONEXCLAMATION);
    		iReturn = FAIL_LOAD;
    		goto CleanupOle;       
    	}
    	
    	(FARPROC&)lpDllEntryPoint = GetProcAddress(hLib, pszDllEntryPoint);
    	
    	if (lpDllEntryPoint == NULL)   
    	{
    #ifdef _WIN32
    		int nLen = strlen(pszDllName);
    		if ((nLen > 4) && 
    			(stricmp(pszDllName + nLen - 4, ".dll") != 0)  && 
    			(stricmp(pszDllName + nLen - 4, ".ocx") != 0))
    		{      
    			wsprintf(szMsgBuffer, 
    			"%s was loaded, but the %s entry point "
    			"was not found. %s does not appear to be "
    			"an .DLL or .OCX file.", 
    			pszDllName, 
    			pszDllEntryPoint, 
    			pszDllName);
    		}
    		else
    		{      
    			wsprintf(szMsgBuffer, 
    			"%s was loaded, but the %s entry point "
    			"was not found. %s may not be exported, "
    			"or a corrupt version may be in memory.  "
    			"Consider using PView to detect and remove it.",
    			pszDllName, 
    			pszDllEntryPoint, 
    			pszDllEntryPoint);
    		}
    #else
    		wsprintf(szMsgBuffer, 
    		"%s was loaded, but the %s entry point "
    		"was not found. %s may not be exported, "
    		"or a corrupt version may be in memory.  "
    		"Consider using WPS to detect and remove it.",
    		pszDllName, 
    		pszDllEntryPoint, 
    		pszDllEntryPoint);
    #endif
    		
    		if (!bSilent)  
    			MessageBox(NULL, 
    				szMsgBuffer, 
    				szAppName, 
    				MB_TASKMODAL | MB_ICONEXCLAMATION);
    		iReturn = FAIL_ENTRY;
    		
    		goto CleanupLibrary;   
    	}
    	
    	if (FAILED((*lpDllEntryPoint)()))      
    	{
    		wsprintf(szMsgBuffer, 
    			"%s in %s failed.", 
    			pszDllEntryPoint, 
    			pszDllName);
    		
    		if (!bSilent)  
    			MessageBox(NULL, 
    				szMsgBuffer, 
    				szAppName, 
    				MB_TASKMODAL | MB_ICONEXCLAMATION);
    		iReturn = FAIL_REG;
    		
    		goto CleanupLibrary;   
    	}      
    	
    	wsprintf(szMsgBuffer,
    		"%s in %s succeeded.", 
    		pszDllEntryPoint, 
    		pszDllName);     
    	
    	if (! bSilent)
    		MessageBox(NULL, 
    			szMsgBuffer, 
    			szAppName, 
    			MB_TASKMODAL | MB_ICONINFORMATION); 
    CleanupLibrary:     
    	FreeLibrary(hLib); 
    	
    CleanupOle: 
    	OleUninitialize();     
    	
    	return iReturn;
    }
    					
  4. Xy d?ng cc ?ng d?ng, v s? d?ng n ? ng k? ho?c unregister DLL COM c?a b?n.

THAM KH?O

? bi?t thm chi ti?t, b?m vo nh?ng con s? bi vi?t d?i y ? xem cc bi vi?t trong c s? ki?n th?c Microsoft:
140346 C th? c l? do cho vi?c khng ng k? i?u khi?n OLE
141824 Thng tin: T? xa OLE t? ?ng ha l?i ph? bi?n
146219 HOWTO: ng k? i?u khi?n ActiveX (.ocx) b?ng tay
185599 Kh?c ph?c: OleAut32.dll l t? khng ng

Thu?c tnh

ID c?a bi: 207132 - L?n xem xt sau cng: 28 Thang Chin 2011 - Xem xt l?i: 3.0
p d?ng
  • Microsoft Windows 2000 Server
  • Microsoft Windows 2000 Advanced Server
  • Microsoft Windows 2000 Professional Edition
  • Microsoft Windows 95
  • Microsoft Windows NT Server 4.0 Standard Edition
  • Microsoft Windows NT Workstation 4.0 Developer Edition
T? kha:
kbinfo kbmt KB207132 KbMtvi
My d?ch
QUAN TRONG: Bi vi?t ny ?c d?ch b?ng ph?n m?m d?ch my c?a Microsoft ch? khng ph?i do con ng?i d?ch. Microsoft cung c?p cc bi vi?t do con ng?i d?ch v c? cc bi vi?t do my d?ch ? b?n c th? truy c?p vo t?t c? cc bi vi?t trong C s? Ki?n th?c c?a chng ti b?ng ngn ng? c?a b?n. Tuy nhin, bi vi?t do my d?ch khng ph?i lc no c?ng hon h?o. Lo?i bi vi?t ny c th? ch?a cc sai st v? t? v?ng, c php ho?c ng? php, gi?ng nh m?t ng?i n?c ngoi c th? m?c sai st khi ni ngn ng? c?a b?n. Microsoft khng ch?u trch nhi?m v? b?t k? s? thi?u chnh xc, sai st ho?c thi?t h?i no do vi?c d?ch sai n?i dung ho?c do ho?t ?ng s? d?ng c?a khch hng gy ra. Microsoft c?ng th?ng xuyn c?p nh?t ph?n m?m d?ch my ny.
Nh?p chu?t vo y ? xem b?n ti?ng Anh c?a bi vi?t ny:207132

Cung cp Phan hi

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com