开发者

RegisterActiveObject returns succeed on server but GetObject is not working on any clients?

开发者 https://www.devze.com 2023-04-01 18:35 出处:网络
I have been working 2 days on creating a simple exe COM server, I have test any thing in the web , but still not working!

I have been working 2 days on creating a simple exe COM server, I have test any thing in the web , but still not working! I create a simple object with ATL and register the interface with ATL RegisterClassObjects and RegisterActiveObjec开发者_StackOverflow中文版t, it returns succeed but any clients can't use GetObject method to get the object, but CreateObject works.

here is my project files: http://www.mediafire.com/?365arde4jyd5v3x

Can anybody help me? I really need it, it's a part of my project. Thanks.


I finally solved my problem with this code: ( CoRegisterClassObject still not works!)

HRESULT hr;
CYourObject *your = new CComObject<CYourObject>();
void *p = NULL;
your->QueryInterface(IID_IUnknown,&p);
IUnknown *var = (IUnknown*)p;
DWORD pdwRegister;


IRunningObjectTable *pROT;
IMoniker *pMon;
LPOLESTR monikerName;
hr = GetRunningObjectTable(NULL,&pROT);

hr = StringFromCLSID(CLSID_YourObject, &monikerName);

LPOLESTR delim = L"!"; // moniker delimiter (set to ! always)
hr = CreateItemMoniker(delim,monikerName,&pMon);

hr = pROT->Register(ROTFLAGS_REGISTRATIONKEEPSALIVE,var,pMon,&pdwRegister);
CLSID id;
hr = CLSIDFromProgID(L"MyAtlProject.YourObject",&id);


First of all, you need to check if you succeeded in putting your stuff onto ROT. Look for irotview (some old SDK?) or similar utility to make this sure (update - RotView gets you that).

Provided that the entry is there (othrewise you need to check error code for API calls which create the ROT entry), there are two likely options for the client to fail to access the entry:

  1. security - no permissions to access the entry; this should not be the case when at least you start both server and client under admin credentials and elevated privileges
  2. marshaling - you need to make sure that your interface can be marshaled; the easiest way is to derive it from IDispatch and register the type library; without marshaling COM will be unable to create proxy/stub pair for the interfaces.
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号