Exemplo n.º 1
0
static variant_t CreateClrType(const String& assemblyName, const String& typeName)
{
	boost::call_once(l_OnceFlag, &InitializeClr);

	try {
		mscorlib::_ObjectHandlePtr pObjectHandle;
		pObjectHandle = l_AppDomain->CreateInstanceFrom(assemblyName.CStr(), typeName.CStr());

		return pObjectHandle->Unwrap();
	} catch (_com_error& error) {
		BOOST_THROW_EXCEPTION(std::runtime_error("Could not load .NET type: " + String(error.Description())));
	}
}
Exemplo n.º 2
0
VARIANT Functions::InvokeMember2(mscorlib::_AppDomainPtr pDefaultDomain, BSTR dll, BSTR Typename, BSTR Method, int Numargs, ...)
{
	VARIANT returnValue;

	try
	{
		va_list vl;
		va_start(vl,Numargs);
		SAFEARRAY* psa = SafeArrayCreateVector(VT_VARIANT, 0, Numargs / 2);

		for (int i = 0; i < Numargs; i+=2)
		{
			int typeName = va_arg(vl, int);
			switch(typeName)
			{
			case 0:
				{
					BSTR wstr = SysAllocString(va_arg(vl, wchar_t*));
					VARIANT val;
					val.vt = VT_BSTR;
					val.bstrVal = wstr;
					LONG index[1] = { i / 2 };

					SafeArrayPutElement(psa, index, &val);

					SysFreeString(wstr);
					break;
				}
			case 1:
				{
					int intval = va_arg(vl, int);
					VARIANT val;
					val.vt = VT_INT;
					val.intVal = intval;
					LONG index[1] = { i / 2 };

					SafeArrayPutElement(psa, index, &val);
					break;
				}
			}
		}

		mscorlib::_ObjectPtr pObject; 
		mscorlib::_ObjectHandlePtr pObjectHandle; 

		pObjectHandle = pDefaultDomain->CreateInstanceFrom(dll, Typename);
		variant_t vtobj = pObjectHandle->Unwrap();
		vtobj.pdispVal->QueryInterface(__uuidof(mscorlib::_Object),(void**)&pObject); 

		mscorlib::_TypePtr pType = pObject->GetType();

		returnValue = pType->InvokeMember_3(Method,
			mscorlib::BindingFlags_InvokeMethod,
			NULL,
			vtobj,
			psa);

		SafeArrayDestroy(psa);
		vtobj.Clear();
		pType->Release();
		pObject->Release();
	}
	catch(_com_error& error) {
		_tprintf(TEXT("ERROR: %s\n"),(_TCHAR*)error.Description());
	}

	return returnValue;
}