Re: Getting object from ROT
- From: Kevin LZJ <KevinLZJ@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 18 May 2006 21:45:01 -0700
Thanks! Alexander
Your reply gives useful information. However, to get flexibility programmly,
I find a new method using Monikor. In server machine, server application
registers its COM objects to local ROT, and in client machine, we use the
object's monikor name to get object interface, of course, we must set bind
option using BIND_OPTS2 to set server information so that the binding can be
sent to the server machine. This is the code segment :
HRESULT hr=S_OK;
IBindCtx* pBC=NULL;
hr=CreateBindCtx(NULL, &pBC);
if (SUCCEEDED(hr))
{
BIND_OPTS2 bind;
bind.cbStruct=sizeof(bind);
pBC->GetBindOptions(&bind);
CoTaskMemFree(bind.pServerInfo); // Free memory in case it's non NULL.
bind.pServerInfo=&srvinfo;
pBC->SetBindOptions(&bind);
// Use the bind context.
pBC->Release();
}
"Alexander Nickolov" wrote:
ROT is designed to be used on the same machine only. Fortunately,.
you don't need ROT. DCOM has all the tools for the job. You
need to change the server's identity to be a specific user account,
NOT the default of run as activator (launching user). Then all
objects created in the server will come from a single instance
running under that user account. If you need a singleton object
(and you shouldn't) you can use a singleton class object.
--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD
email: agnickolov@xxxxxxxx
MVP VC FAQ: http://www.mvps.org/vcfaq
=====================================
"Kevin LZJ" <KevinLZJ@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:2B452633-D080-47DA-9BD7-BC6F924FB1C6@xxxxxxxxxxxxxxxx
Hi, Rhett,
Could you pls tell me how to get an object from ROT in another machine
?
Suppose this situation:
There is a sever application running in a Win2000 Server machine, and
for some reason, we need only one instance running at any time. In a batch
of
client machines, client applications need to get object interfaces from
the
server to operate. If one client app need to get object interfaces, we
need
to make sure that it get interfaces from current running objects in the
server machine.
Thanks !
Kevin
"Rhett Gong [MSFT]" wrote:
Thanks for your feedback.
The hash value and pid of display name ("!VisualStudio.DTE.7.1:<PID>) are
different in ROT, we can use it to distiguish each DTE instance. And
after
succeeded in calling GetObject, we get an instance for a DTE object, then
we can also query its properties to distiguish it from others, such as
Solution Property, mode ....
More properties, methods and events of DTE can be found at:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vsintro7/ht
ml/vxmscdteobjectpropertiesmethodsevents.asp
And, can this be done from C# instead of C++?Certainly, it can be done from C#. Take documents property for example,
it
does provides C# implementation as documented following:
public Documents Documents {get;}
With C#, you may try following code to get the DTE object, and then
comparing the pid from displayname or retrieving property values to
differentiate them.
//--------------------------
using System;
using System.Runtime.InteropServices;
using EnvDTE;
namespace RunningObject
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
[DllImport("ole32.dll")]
public static extern int GetRunningObjectTable(int reserved, out
UCOMIRunningObjectTable prot);
[DllImport("ole32.dll")]
public static extern int CreateBindCtx(int reserved, out UCOMIBindCtx
ppbc);
[STAThread]
static object GetMSDEVFromGIT(string strProgID)
{
UCOMIRunningObjectTable prot;
UCOMIEnumMoniker pMonkEnum;
try
{
GetRunningObjectTable(0,out prot);
prot.EnumRunning(out pMonkEnum);
pMonkEnum.Reset(); // Churn through enumeration.
int fetched;
UCOMIMoniker []pmon = new UCOMIMoniker[1];
while(pMonkEnum.Next(1, pmon, out fetched) == 0)
{
UCOMIBindCtx pCtx;
CreateBindCtx(0, out pCtx);
string str;
pmon[0].GetDisplayName(pCtx,null,out str);
if(str == strProgID)
{
object objReturnObject;
prot.GetObject(pmon[0],out objReturnObject);
object ide = (object)objReturnObject;
return ide;
}
}
}
catch
{
return null;
} return null;
}
// End CodeSample
Please let me know if my answer helps you resolve the problem.
Thanks,
Rhett Gong [MSFT]
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties and confers no
rights.
- References:
- RE: Getting object from ROT
- From: Kevin LZJ
- Re: Getting object from ROT
- From: Alexander Nickolov
- RE: Getting object from ROT
- Prev by Date: Re: Getting object from ROT
- Next by Date: OT: dll path
- Previous by thread: Re: Getting object from ROT
- Next by thread: OT: dll path
- Index(es):
Relevant Pages
|