Starting an inproc server as a local server using a DLL Surrogate 
Author Message
 Starting an inproc server as a local server using a DLL Surrogate

Hi !

I need to create an object implemented in a DLL (inproc server) from VB6
So far, so good...
The problem arise from the fact that I would like to have this inproc server
started as a local server using a DLL surrogate (namely dllhost.exe).
When I try that from OLEVIEW, everything is OK.
But when I do the same from within VB6, using CreateObject, the server is
always started as an inproc server, never as .exe...
Do you know what I'm doing wrong ?
Thanks in advance for your help...

Stphane.



Fri, 27 Sep 2002 03:00:00 GMT  
 Starting an inproc server as a local server using a DLL Surrogate
For the client to instantiate a DLL that runs within the DLL Surrogate,  the
client must explicitly request a Local Server activation.

This means that if you were writing this client in C++ you would do the
following:

CreateInstance( CLSID_CoFoo, 0, CLSCTX_LOCAL_SERVER, ....);

Note that the client must place an explicit request for a local server
activation using CLSCTX_LOCAL_SERVER.

Now back to VB. When you perform an activation in VB (activation == object
instantiation), VB always uses CLSCTX_SERVER when it does the CreateInstance
on your behalf. This flag will default to InProc server activations.

Is there a VB workaround? I don't know of one, but I'm not much of a VB
coder (hopefully someone else in this news group can address this). What
I've done in the past is to create a custom moniker that allows me to
specify the CLSCTX flag and then use VB's GetObject to do the activation
(instead of CreateObject or new).

Peter Partch



Quote:
> Hi !

> I need to create an object implemented in a DLL (inproc server) from VB6
> So far, so good...
> The problem arise from the fact that I would like to have this inproc
server
> started as a local server using a DLL surrogate (namely dllhost.exe).
> When I try that from OLEVIEW, everything is OK.
> But when I do the same from within VB6, using CreateObject, the server is
> always started as an inproc server, never as .exe...
> Do you know what I'm doing wrong ?
> Thanks in advance for your help...

> Stphane.



Fri, 27 Sep 2002 03:00:00 GMT  
 Starting an inproc server as a local server using a DLL Surrogate

Quote:
>Is there a VB workaround? I don't know of one, but I'm not much of a VB
>coder (hopefully someone else in this news group can address this).

You can use CoCreateInstance to instantiate the object from VB instead
of CreateObject or New...

Mattias

__________________________________________________

     VB+ http://hem.spray.se/mattias.sjogren/
 Please send questions/replies to the newsgroups



Fri, 27 Sep 2002 03:00:00 GMT  
 Starting an inproc server as a local server using a DLL Surrogate
I think, Mattias, that a little bit more is required for this answer to
stick....

How does the VB coder deal with pointers, and GUID's? A sample of VB code
that calls CoCreateInstance might be nice.

Peter Partch


Quote:
> >Is there a VB workaround? I don't know of one, but I'm not much of a VB
> >coder (hopefully someone else in this news group can address this).

> You can use CoCreateInstance to instantiate the object from VB instead
> of CreateObject or New...

> Mattias

> __________________________________________________

>      VB+ http://hem.spray.se/mattias.sjogren/
>  Please send questions/replies to the newsgroups



Fri, 27 Sep 2002 03:00:00 GMT  
 Starting an inproc server as a local server using a DLL Surrogate
I finally succeeded in having it started as a local server: simply using
CreateObject the following way :
        CreateObject("MyLib.MyObject.1", "127.0.0.1")

Thanks.
Stphane



Quote:
> I think, Mattias, that a little bit more is required for this answer to
> stick....

> How does the VB coder deal with pointers, and GUID's? A sample of VB code
> that calls CoCreateInstance might be nice.

> Peter Partch



> > >Is there a VB workaround? I don't know of one, but I'm not much of a VB
> > >coder (hopefully someone else in this news group can address this).

> > You can use CoCreateInstance to instantiate the object from VB instead
> > of CreateObject or New...

> > Mattias

> > __________________________________________________

> >      VB+ http://hem.spray.se/mattias.sjogren/
> >  Please send questions/replies to the newsgroups



Sat, 28 Sep 2002 03:00:00 GMT  
 Starting an inproc server as a local server using a DLL Surrogate
This is an activation across machines, right?

This will not work if you need DLL Surrogate activation when the client and
server reside on the same box.

Peter Partch



Quote:
> I finally succeeded in having it started as a local server: simply using
> CreateObject the following way :
>         CreateObject("MyLib.MyObject.1", "127.0.0.1")

> Thanks.
> Stphane



> > I think, Mattias, that a little bit more is required for this answer to
> > stick....

> > How does the VB coder deal with pointers, and GUID's? A sample of VB
code
> > that calls CoCreateInstance might be nice.

> > Peter Partch


message

> > > >Is there a VB workaround? I don't know of one, but I'm not much of a
VB
> > > >coder (hopefully someone else in this news group can address this).

> > > You can use CoCreateInstance to instantiate the object from VB instead
> > > of CreateObject or New...

> > > Mattias

> > > __________________________________________________

> > >      VB+ http://hem.spray.se/mattias.sjogren/
> > >  Please send questions/replies to the newsgroups



Sat, 28 Sep 2002 03:00:00 GMT  
 Starting an inproc server as a local server using a DLL Surrogate
He cheated.

The common name for 127.0.0.1 is "localhost" which is the local machine.  I
would have assumed that it would have resolved it as Inproc anyway, but I
guess it's just enough to trick it to use the surrogate.

This may not always work though...for example Win2K might be able to figure
it out and use the Inproc version.

--
Reginald Blue                   | Opinions expressed here do not
Natural Language Understanding  | necessarily represent those of
Unisys Corporation              | my employer.
--------------------------------+-------------------------------

NL technology,speech application| My email address is wrong, you
development training, see:      | need to remove the obvious.
http://www.speechdepot.com/     +-------------------------------


Quote:
> This is an activation across machines, right?

> This will not work if you need DLL Surrogate activation when the client
and
> server reside on the same box.

> Peter Partch



> > I finally succeeded in having it started as a local server: simply using
> > CreateObject the following way :
> >         CreateObject("MyLib.MyObject.1", "127.0.0.1")



Sat, 28 Sep 2002 03:00:00 GMT  
 Starting an inproc server as a local server using a DLL Surrogate
Thanks, an oversight on my part.

Been awhile since I tried activation on local host using a host name.
CoCreateInstanceEx used to fail outright when attempting to name the local
machine....I guess MS has fixed this?

Peter Partch


Quote:
> He cheated.

> The common name for 127.0.0.1 is "localhost" which is the local machine.
I
> would have assumed that it would have resolved it as Inproc anyway, but I
> guess it's just enough to trick it to use the surrogate.

> This may not always work though...for example Win2K might be able to
figure
> it out and use the Inproc version.

> --
> Reginald Blue                   | Opinions expressed here do not
> Natural Language Understanding  | necessarily represent those of
> Unisys Corporation              | my employer.
> --------------------------------+-------------------------------

> NL technology,speech application| My email address is wrong, you
> development training, see:      | need to remove the obvious.
> http://www.speechdepot.com/     +-------------------------------



> > This is an activation across machines, right?

> > This will not work if you need DLL Surrogate activation when the client
> and
> > server reside on the same box.

> > Peter Partch



> > > I finally succeeded in having it started as a local server: simply
using
> > > CreateObject the following way :
> > >         CreateObject("MyLib.MyObject.1", "127.0.0.1")



Sat, 28 Sep 2002 03:00:00 GMT  
 Starting an inproc server as a local server using a DLL Surrogate
Damn!

CoCreateInstanceEx now works when specifying local host. This reminds me of
when MS fixed COM error objects (years ago it used to be that you could not
throw error objects across Apartment boundaries...then MS silently fixed the
problem)

Thanks for pointing this out.

Peter Partch


Quote:
> Thanks, an oversight on my part.

> Been awhile since I tried activation on local host using a host name.
> CoCreateInstanceEx used to fail outright when attempting to name the local
> machine....I guess MS has fixed this?

> Peter Partch



> > He cheated.

> > The common name for 127.0.0.1 is "localhost" which is the local machine.
> I
> > would have assumed that it would have resolved it as Inproc anyway, but
I
> > guess it's just enough to trick it to use the surrogate.

> > This may not always work though...for example Win2K might be able to
> figure
> > it out and use the Inproc version.

> > --
> > Reginald Blue                   | Opinions expressed here do not
> > Natural Language Understanding  | necessarily represent those of
> > Unisys Corporation              | my employer.
> > --------------------------------+-------------------------------

> > NL technology,speech application| My email address is wrong, you
> > development training, see:      | need to remove the obvious.
> > http://www.speechdepot.com/     +-------------------------------



> > > This is an activation across machines, right?

> > > This will not work if you need DLL Surrogate activation when the
client
> > and
> > > server reside on the same box.

> > > Peter Partch



> > > > I finally succeeded in having it started as a local server: simply
> using
> > > > CreateObject the following way :
> > > >         CreateObject("MyLib.MyObject.1", "127.0.0.1")



Sat, 28 Sep 2002 03:00:00 GMT  
 Starting an inproc server as a local server using a DLL Surrogate
Hi Peter,

Quote:
>How does the VB coder deal with pointers, and GUID's? A sample of VB code
>that calls CoCreateInstance might be nice.

Pointer stuff in VB can be a little tricky, but most things are
possible. This code works, but the localhost hack Stphane found out
is easier to use from VB.

' In Declarations section of module:

Const CLSCTX_LOCAL_SERVER = 4

Type GUID
  Data1 As Long
  Data2 As Integer
  Data3 As Integer
  Data4(0 To 7) As Byte
End Type

Private Declare Function CoCreateInstance Lib "ole32" ( _
  rclsid As GUID, _
  ByVal pUnkOuter As Object, _
  ByVal dwClsContext As Long, _
  riid As GUID, _
  ppv As Object) As Long

Private Declare Function CLSIDFromString Lib "ole32" ( _
  ByVal lpsz As Long, _
  pclsid As GUID) As Long

Declare Function CLSIDFromProgID Lib "ole32" ( _
  ByVal lpszProgID As Long, _
  pclsid As GUID) As Long

' calling code

Dim IID_IDispatch As GUID
Dim CLSID_CFoo As GUID
Dim foo As Object

Call CLSIDFromProgID(StrPtr("FooLib.CFoo"), CLSID_CFoo)
Call CLSIDFromString(StrPtr("{00020400-0000-0000-C000-000000000046}"),
IID_IDispatch)
Call CoCreateInstance(CLSID_CFoo, Nothing, CLSCTX_LOCAL_SERVER,
IID_IDispatch, foo)
If Not (foo Is Nothing) Then
  foo.SomeMethod
  Set foo = Nothing
End If

Mattias

__________________________________________________

     VB+ http://hem.spray.se/mattias.sjogren/
 Please send questions/replies to the newsgroups



Sat, 28 Sep 2002 03:00:00 GMT  
 Starting an inproc server as a local server using a DLL Surrogate
Are you using just CLSCTX_REMOTE_SERVER flag only?


Quote:
> Damn!

> CoCreateInstanceEx now works when specifying local host. This reminds me
of
> when MS fixed COM error objects (years ago it used to be that you could
not
> throw error objects across Apartment boundaries...then MS silently fixed
the
> problem)

> Thanks for pointing this out.

> Peter Partch



> > Thanks, an oversight on my part.

> > Been awhile since I tried activation on local host using a host name.
> > CoCreateInstanceEx used to fail outright when attempting to name the
local
> > machine....I guess MS has fixed this?

> > Peter Partch



> > > He cheated.

> > > The common name for 127.0.0.1 is "localhost" which is the local
machine.
> > I
> > > would have assumed that it would have resolved it as Inproc anyway,
but
> I
> > > guess it's just enough to trick it to use the surrogate.

> > > This may not always work though...for example Win2K might be able to
> > figure
> > > it out and use the Inproc version.

> > > --
> > > Reginald Blue                   | Opinions expressed here do not
> > > Natural Language Understanding  | necessarily represent those of
> > > Unisys Corporation              | my employer.
> > > --------------------------------+-------------------------------

> > > NL technology,speech application| My email address is wrong, you
> > > development training, see:      | need to remove the obvious.
> > > http://www.speechdepot.com/     +-------------------------------



> > > > This is an activation across machines, right?

> > > > This will not work if you need DLL Surrogate activation when the
> client
> > > and
> > > > server reside on the same box.

> > > > Peter Partch



> > > > > I finally succeeded in having it started as a local server: simply
> > using
> > > > > CreateObject the following way :
> > > > >         CreateObject("MyLib.MyObject.1", "127.0.0.1")



Sun, 29 Sep 2002 03:00:00 GMT  
 
 [ 11 post ] 

 Relevant Pages 

1. Inproc Server loading Java HotSpot DLL

2. OLE Inproc Server in MFC extension DLL

3. Lifetime of EXE COM server that uses DLL COM server

4. Local Com Server and CGI in NT Server

5. Local Server OK BUT Local Service FAILED

6. In Proc Server crashes, when hosted in COM+ surrogate all is fine

7. Basic questions about CLSCTX enum, inproc and out-of-proc servers

8. registering ATL inproc server

9. InProc Server (Marshalling problem)

10. problem with CreateThread in the InProc server.

11. Registering in the ROT an ActiveX object implemented in an inproc server

12. Remote Debugging An Inproc Server

 

 
Powered by phpBB® Forum Software