예제 #1
0
LPMONIKER COleServerItem::GetMoniker(OLEGETMONIKER nAssign)
{
	// get IOleObject interface for this item
	LPOLEOBJECT lpOleObject = GetOleObject();
	ASSERT(lpOleObject != NULL);

	// get moniker from OLE object
	LPMONIKER lpMoniker = NULL;
	lpOleObject->GetMoniker(nAssign, OLEWHICHMK_OBJFULL, &lpMoniker);
	return lpMoniker;
}
예제 #2
0
BOOL COleServerItem::GetLinkSourceData(LPSTGMEDIUM lpStgMedium)
{
	ASSERT_VALID(this);
	ASSERT(AfxIsValidAddress(lpStgMedium, sizeof(STGMEDIUM)));

	LPOLEOBJECT lpOleObject = GetOleObject();
	ASSERT(lpOleObject != NULL);

	// get moniker from ole object
	LPMONIKER lpMoniker;
	SCODE sc = lpOleObject->GetMoniker(OLEGETMONIKER_TEMPFORUSER,
		OLEWHICHMK_OBJFULL, &lpMoniker);
	if (sc != S_OK)
	{
		TRACE0("Warning: unable to get moniker for object.\n");
		return FALSE;
	}
	ASSERT(lpMoniker != NULL);

	// create a memory based stream to write the moniker to
	LPSTREAM lpStream;
	if (::CreateStreamOnHGlobal(NULL, TRUE, &lpStream) != S_OK)
	{
		lpMoniker->Release();
		AfxThrowMemoryException();
	}
	ASSERT(lpStream != NULL);

	// write the moniker to the stream, and add it to the clipboard
	sc = ::OleSaveToStream(lpMoniker, lpStream);
	lpMoniker->Release();
	if (sc != S_OK)
	{
		lpStream->Release();
		AfxThrowOleException(sc);
	}

	// write the class ID of the document to the stream as well
	COleLinkingDoc* pDoc = GetDocument();
	ASSERT(pDoc->m_pFactory != NULL);
	sc = WriteClassStm(lpStream, pDoc->m_pFactory->GetClassID());
	if (sc != S_OK)
	{
		lpStream->Release();
		AfxThrowOleException(sc);
	}

	// setup the STGMEDIUM
	lpStgMedium->tymed = TYMED_ISTREAM;
	lpStgMedium->pstm = lpStream;
	lpStgMedium->pUnkForRelease = NULL;
	return TRUE;
}
예제 #3
0
void COleServerItem::GetObjectDescriptorData(
	LPPOINT lpOffset, LPSIZE lpSize, LPSTGMEDIUM lpStgMedium)
{
	ASSERT_VALID(this);
	ASSERT(AfxIsValidAddress(lpStgMedium, sizeof(STGMEDIUM)));
	ASSERT(lpOffset == NULL ||
		AfxIsValidAddress(lpOffset, sizeof(POINT), FALSE));

	LPOLEOBJECT lpOleObject = GetOleObject();
	ASSERT(lpOleObject != NULL);

	// get the object descriptor for the IOleObject
	POINTL pointl = { 0, 0 };
	if (lpOffset != NULL)
	{
		CSize ptOffset(lpOffset->x, lpOffset->y);
#ifndef _MAC
		((CDC*)NULL)->DPtoHIMETRIC(&ptOffset);
#endif
		pointl.x = ptOffset.cx;
		pointl.y = ptOffset.cy;
	}
	SIZEL sizel;
	if (lpSize != NULL)
	{
		sizel.cx = lpSize->cx;
		sizel.cy = lpSize->cy;
#ifndef _MAC
		((CDC*)NULL)->DPtoHIMETRIC(&sizel);
#endif
	}
	else
	{
		sizel.cx = 0;
		sizel.cy = 0;
	}

	InterlockedIncrement(&m_dwRef);  // protect against destruction during this call
	HGLOBAL hGlobal = _AfxOleGetObjectDescriptorData(
		lpOleObject, NULL, DVASPECT_CONTENT, pointl, &sizel);
	InterlockedDecrement(&m_dwRef);

	if (hGlobal == NULL)
		AfxThrowMemoryException();

	// setup the STGMEDIUM
	lpStgMedium->tymed = TYMED_HGLOBAL;
	lpStgMedium->hGlobal = hGlobal;
	lpStgMedium->pUnkForRelease = NULL;
}
예제 #4
0
// invoked in the main thread
void CRScriptCore::DefineGlobalMethods(LPCSTR pObjName)
{
	static char methoddef[] = "def %s(*a)\r\n"
		                      "  %c%s.%s(*a)\r\n"
						 	  "end\r\n";
	static const int MAX_PROPNAME = 64;
	char* p = reinterpret_cast<LPSTR>(alloca(sizeof(methoddef) + strlen(pObjName) + MAX_PROPNAME * 2 + 8));
	int state;
    VALUE param[] = {
		GetOleObject(s_valueWin32OleEx, m_strGlobalObjectName.c_str()), 
	    rb_intern("ole_func_methods"), 
		0,
	};
    VALUE a = rb_protect((VALUE(*)(VALUE))funcall, (VALUE)param, &state);
	if (state)
	{	// maybe no typelib
		return;
	}
	ID name = rb_intern("name");
	for (int i = 0; i < RARRAY_LEN(a); i++)
	{
		VALUE o = rb_ary_entry(a, i);
		VALUE propname = rb_funcall(o, name, 0);
		char* prop = StringValueCStr(propname);
		if (strlen(prop) > MAX_PROPNAME) 
		{
			continue; // skip, the name is too long
		}
#define LOWER_PROP_NAME
#ifdef LOWER_PROP_NAME
		char method[65];
		strcpy(method, prop);
		method[0] = tolower(method[0]);
		int cb = sprintf(p, methoddef, method, prefix, pObjName, prop);
#else
		int cb = sprintf(p, methoddef, prop, prefix, pObjName, prop);
#endif
#if defined(__IRubyEngine_INTERFACE_DEFINED__)
                VALUE args[] = { rb_str_new(p, cb), rb_str_new("ActiveScriptRuby", 16), INT2NUM(1) };
                rb_obj_instance_eval(3, args, GetModuleValue());
#else
		rb_eval_string(p);
#endif
	}
}
예제 #5
0
VALUE CRScriptCore::GetOleObject(VALUE self, char* pName)
{
	USES_CONVERSION;
	return GetOleObject(self, A2W(pName));
}