Creating remote objects
Hi Erich,
Don't have an answer to the question, but I knocked up a little function to
return a ProgID from a CLSID. To run it, you just issue
sProgID = GetProgID("{00024500-0000-0000-C000-000000000046}")
which returns "Excel.Application.9"
or i n your instance, use
CreateObject(GetProgID("{00024500-0000-0000-C000-000000000046}")
,"remotemachine")
Option Explicit
'CLSID/GUID structure
Private Type GUID
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(7) As Byte
End Type
'API Declarations
Private Declare Function ProgIDFromCLSID Lib "ole32.dll" _
(pCLSID As GUID, _
lpszProgID As Long) As Long
Private Declare Function CLSIDFromString Lib "ole32.dll" _
(ByVal lpszProgID As Long, _
pCLSID As GUID) As Long
Private Declare Sub CopyMemory Lib "kernel32" _
Alias "RtlMoveMemory" _
(pDst As Any, _
pSrc As Any, _
ByVal ByteLen As Long)
Function GetProgID(CLSID As String)
Dim sProgID As String * 255
Dim pProgID As Long
Dim udtCLSID As GUID
Dim sCLSID As String * 255
Dim pCLSID As Long
Dim lngRet As Long
sCLSID = CLSID
'Convert the string back to CLSID
lngRet = CLSIDFromString(StrPtr(sCLSID), udtCLSID)
'Get a pointer to ProgID string. This is a Unicode string.
lngRet = ProgIDFromCLSID(udtCLSID, pProgID)
'Get the ProgID and display it.
StringFromPointer pProgID, sProgID
GetProgID = sProgID
End Function
'This function takes a pointer to a Unicode string, a string buffer
'and place the bytes in the Visual Basic string buffer.
Private Sub StringFromPointer(pOLESTR As Long, strOut As String)
Dim ByteArray(255) As Byte
Dim intTemp As Integer
Dim intCount As Integer
Dim i As Integer
intTemp = 1
'Walk the string and retrieve the first byte of each WORD.
While intTemp < 0
CopyMemory intTemp, ByVal pOLESTR + i, 2
ByteArray(intCount) = intTemp
intCount = intCount + 1
i = i + 2
Wend
'Copy the byte array to our string.
CopyMemory ByVal strOut, ByteArray(0), intCount
End Sub
--
HTH
Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
"Erich Neuwirth" wrote in message
...
I know how to create a DCOM object on a remote server using CreateObject
in VBA.
To do so, the object has to be registered on the client machine.
Then it can be created by using its name, e.g.
CreateObject("Excel.Worksheet","remotemachine")
Some other MS tools (Visual FoxPro for example)
have a procedure
CreateObjectEx
which allows to use the CLSID
(the strange thing like "{98de59a0-d175-11cd-a7bd-00006b827d94}")
instead of a name to create the remote object without a registry entry
on the local client machine.
Does anybody have a way of doing this in VBA?
The convenience is that then it is possible to install
a client in an Excel Addin accessing a remote server
without the need of running an installation program with
Administrator rights on the client.
|