|
楼主 |
发表于 2013-3-26 20:19
|
显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
原帖:http://blog.csdn.net/Modest/archive/2006/11/01/1361160.aspx
[vb] view plaincopy- Option Explicit
- Private Type UUID
- Data1 As Long
- Data2 As Integer
- Data3 As Integer
- Data4(7) As Byte
- End Type
- Private Declare Function CLSIDFromProgID Lib "ole32.dll" (ByVal lpszProgID As Long, pClsid As UUID) As Long
- Private Declare Sub ProgIDFromCLSID Lib "ole32.dll" (CLSID As UUID, lplpszProgID As Long)
- Private Declare Function CLSIDFromString Lib "ole32.dll" (ByVal lpszProgID As Long, pClsid As UUID) As Long
- Private Declare Function StringFromCLSID Lib "ole32.dll" (pClsid As UUID, lpszProgID As Long) As Long
- Private Declare Sub MoveMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (ByRef Destination As Any, ByRef Source As Any, ByVal Length As Long)
- Public Function CLSIDToProgID(ByVal CLSID As String) As String
- Dim UUID As UUID
- Dim ProgID As Long
- Dim StrOut As String * 255
- CLSIDFromString StrPtr(CLSID), UUID
- ProgIDFromCLSID UUID, ProgID
- If ProgID <> 0 Then
- StrFromPtrW ProgID, StrOut
- CLSIDToProgID = Left(StrOut, InStr(StrOut, vbNullChar) - 1)
- End If
- End Function
- Public Function ProgIDToCLSID(ByVal ProgID As String) As String
- Dim UUID As UUID
- Dim CLSID As Long
- Dim StrOut As String * 255
- CLSIDFromProgID StrPtr(ProgID), UUID
- StringFromCLSID UUID, CLSID
- If CLSID <> 0 Then
- StrFromPtrW CLSID, StrOut
- ProgIDToCLSID = Left(StrOut, InStr(StrOut, vbNullChar) - 1)
- End If
- End Function
- Private Sub StrFromPtrW(pOLESTR As Long, StrOut As String)
- Dim ByteArray(255) As Byte, i As Integer
- Dim intTemp As Integer, intCount As Integer
-
- intTemp = 1
- While intTemp <> 0
- MoveMemory intTemp, ByVal pOLESTR + i, 2
- ByteArray(intCount) = intTemp
- intCount = intCount + 1
- i = i + 2
- Wend
- MoveMemory ByVal StrOut, ByteArray(0), intCount
- End Sub
复制代码 |
|