52 lines
1.4 KiB
C++
52 lines
1.4 KiB
C++
#define INC_OLE2
|
|
#define _WIN32_DCOM
|
|
#include <stdio.h>
|
|
#include <conio.h>
|
|
#include <windows.h>
|
|
#include <initguid.h>
|
|
#include <objbase.h>
|
|
#include <common/string.hpp>
|
|
#include <proto/marshal.hpp>
|
|
#include <proto/cfactory.hpp>
|
|
#include <proto/guids.hpp>
|
|
|
|
extern BOOL RegisterServer(LPSTR pszExeName);
|
|
extern void UnregisterServer(void);
|
|
extern HANDLE hevtDone;
|
|
|
|
CClassFactory g_ClassFactory;
|
|
|
|
int __cdecl main(int argc,char **argv,char **envp)
|
|
{
|
|
HRESULT hr;
|
|
DWORD dwRegister;
|
|
|
|
if(argc>1)
|
|
{
|
|
if(!strcmp(argv[1],"-register"))
|
|
{
|
|
if(argc!=3){printf("usage is server -register [path to server] & proxy/stub");return 0;}
|
|
if(!RegisterServer(argv[2])){printf("failed to register server and proxy/stub");return 0;}
|
|
}
|
|
else if(!strcmp(argv[1],"-unregister"))
|
|
{
|
|
UnregisterServer();
|
|
printf("unregistered server & proxy/stub");
|
|
return 0;
|
|
}
|
|
}
|
|
hevtDone=::CreateEvent(NULL,FALSE,FALSE,NULL);
|
|
if(!hevtDone)return 1;
|
|
hr=CoInitializeEx(NULL,COINIT_MULTITHREADED);
|
|
if(FAILED(hr))return printf("CoInitializeEx() failed %08lx",hr),hr;
|
|
hr=::CoRegisterClassObject(CLSID_SimpleObject,&g_ClassFactory,CLSCTX_SERVER,REGCLS_SINGLEUSE,&dwRegister);
|
|
if(FAILED(hr))return printf("Failed to register class object"),hr;
|
|
printf("waiting...\n");
|
|
::WaitForSingleObject(hevtDone,INFINITE);
|
|
::CloseHandle(hevtDone);
|
|
::CoUninitialize();
|
|
printf("Press any key to exit\n");
|
|
char ch=_getch();
|
|
return 0;
|
|
}
|