一般注册控件的时候,如果控件所在路径中有空格的最好使用短路径 。如果使用长路径一般会注册失败。
如
C:/Documents and Settings/Administrator/桌面/远程控制台/远程控制台/UNICOWS.DLL
短路径为
C:/DOCUME~1/ADMINI~1/桌面/远程控~1/远程控~1/UNICOWS.DLL
DWORD GetShortPathName( LPCTSTR lpszLongPath, LPTSTR lpszShortPath, DWORD cchBuffer );Parameters
-
lpszLongPath
-
[in] Pointer to a null-terminated path string. The function retrieves the short form of this path.
In the ANSI version of this function, the name is limited to MAX_PATH characters. To extend this limit to 32,767 wide characters, call the Unicode version of the function and prepend "//?/" to the path. For more information, see Naming a File.
Windows Me/98/95: This string must not exceed MAX_PATH characters.
lpszShortPath
- [out] Pointer to a buffer to receive the null-terminated short form of the path specified by lpszLongPath. cchBuffer
- [in] Size of the buffer pointed to by lpszShortPath, in TCHARs.
Return Values
If the function succeeds, the return value is the length, in TCHARs, of the string copied to lpszShortPath, not including the terminating null character.
If the lpszShortPath buffer is too small to contain the path, the return value is the size of the buffer, in TCHARs, required to hold the path. Therefore, if the return value is greater than cchBuffer, call the function again with a buffer that is large enough to hold the path.
If the function fails for any other reason, the return value is zero. To get extended error information, call GetLastError.
//注册控件
void TestDlg::OnBnClickedButton1(CString strShortName )
{
CString strReg="regsvr32.exe " ;
CString strPath="/s "+strShortName;
ShellExecute(NULL,"OPEN",strReg,strPath,NULL,SW_HIDE);
//return bResult ;
}
//注意/s是为了在注册时不显示注册对话框
//卸载控件
void TestDlg::OnBnClickedButton2(CString strShortName )
{
CString strReg="regsvr32.exe " ;
CString strPath="/u/s "+strShortName;
ShellExecute(NULL,"OPEN",strReg,strPath,NULL,SW_HIDE);
//return bResult ;
}