// not UNIX
#include "stdafx.h"
#include "Strawberry.h"

#include "dispdrv.h"
#include <string.h>

#include <atlconv.h>
#include <afxpriv2.h>


////////////////////////////////////////////////////////////////////
//
int OpenServer(LPTSTR name, void** lpDisp) 
{
   CLSID clsid;
   wchar_t *olestrName;
   int size;
   HRESULT hr;
   LPUNKNOWN lpunk;
   
   size=my_strlen(name);
   olestrName=(wchar_t*) CoTaskMemAlloc((size+1)*2);
#ifdef UNICODE
   my_strcpy(name, olestrName);
#else
   mbstowcs(olestrName,name,size);
#endif
   
  hr=CLSIDFromString(olestrName, &clsid);
  hr=CoCreateInstance(clsid, NULL, CLSCTX_ALL | CLSCTX_REMOTE_SERVER, IID_IUnknown, (void**) &lpunk); 
  hr=OleRun(lpunk);
  hr=lpunk->QueryInterface(IID_IDispatch, lpDisp);
  CoTaskMemFree(olestrName);
 return 0;  
}

int OpenServer2(LPTSTR name, void** lpDisp) 
{
  CLSID clsid;
  OLECHAR olestrName[255];
  int i;
  LPUNKNOWN lpunk;
  
  for (i=0;name[i];i++) olestrName[i]=name[i];
  olestrName[i]=0;
  
  if(CLSIDFromString(olestrName, &clsid)!=NOERROR)
    return(0);
  if(CoCreateInstance(clsid, NULL, CLSCTX_ALL | CLSCTX_REMOTE_SERVER, IID_IUnknown, (void**) &lpunk)!=S_OK) 
    return(0);
  if(OleRun(lpunk)!=S_OK)
    return(0);
  if(lpunk->QueryInterface(IID_IDispatch, lpDisp)==E_NOINTERFACE)
    return(0);
  lpunk->Release();

  return 1;  
}
