|
#include "StdAfx.h"
#include "MSDNDocIntegrationSampleDotNetServerImpl.h"
#using <mscorlib.dll>
using namespace System;
using namespace System::Reflection;
CMSDNDocIntegrationSampleDotNetServerImpl::CMSDNDocIntegrationSampleDotNetServerImpl(void)
{
}
CMSDNDocIntegrationSampleDotNetServerImpl::~CMSDNDocIntegrationSampleDotNetServerImpl(void)
{
}
//��DotNetExtImpl::InitInstance�н����÷���ConnectMainFrame�Զ�̬��������������ڣ�
HRESULT CMSDNDocIntegrationSampleDotNetServerImpl::ConnectMainFrame(CString strMainFrameID)
{
try
{
//�õ������ڳ���
String* strLib = g_pDotNetExtImpl->m_strLib;
//���������ڳ���
Assembly* m_pDotNetAppAssembly = Assembly::Load(strLib);
//�õ������ڶ����������Ϣ��
Type* m_pDotNetAppType = m_pDotNetAppAssembly->GetType(g_pDotNetExtImpl->m_strMainFrameID,true,true);
//�õ����������ڶ������Ҫ��ִ̬�еķ�����Ϣ��
MethodInfo* mi = m_pDotNetAppType->GetMethod(S"ActiveMainFrame");
Object* m_pDotNetAppServer = NULL;
//���������ڶ���ʵ����
m_pDotNetAppServer = Activator::CreateInstance(m_pDotNetAppType);
//��ȷ���������ڶ���ķ���"ActiveMainFrame"֮������Ϣ��
String* p[] = new String*[1];
CString str = _T("");
str.Format(_T("%d"),g_pDotNetExtImpl);
p[0] = str;
//��ִ̬�������ڶ���ķ���"ActiveMainFrame"��
mi->Invoke(m_pDotNetAppServer,p);
}
catch (Exception* exp)
{
//CMSDNDocIntegrationSampleApp::InitInstance
CString strInfo = exp->Message;
strInfo = _T("Ӧ�ó��������ļ�����!\r\n");
strInfo += _T("����Ӧ�ó��������ļ�����ϸ��Ϣ��\r\n��ο�CMSDNDocIntegrationSampleApp::InitInstance�е�ע�ͣ�");
AfxMessageBox(strInfo);
}
return S_OK;
}
//������TangramLittle��MFC������Ҫһ���µ��ĵ�ģ��ʱ��������
//����AttachDocTemplate,����ĵ��ù�����ο�DotNetExtImpl::OnFileNew()
//�Լ�CDocument* DotNetExtImpl::OpenDocumentFile(LPCTSTR lpszFileName)��ʵ�֡�
void CMSDNDocIntegrationSampleDotNetServerImpl::AttachDocTemplate()
{
if(g_pDotNetExtImpl)
{
//�õ���ǰ��Ҫ���ӵ��ĵ�ģ������������ID��
CString m_strWinCtrlID = g_pDotNetExtImpl->m_strCurDocTemplateID;
//����ģ���ֵ䣬���ж���g_pDotNetExtImpl->m_strCurDocTemplateIDΪ��ֵ
//���ĵ�ģ���ֵ�g_pDotNetExtImpl->m_DocTemplateCnnDictionary�����ʧ��
//������
if(!g_pDotNetExtImpl->m_DocTemplateCnnDictionary.Lookup(LPCTSTR(m_strWinCtrlID),(CObject*&)g_pDotNetExtImpl->m_pCurDocTemplate))
{
//��g_pDotNetExtImpl->m_strCurDocTemplateID���
//�ĵ�ģ��������ID��
int nPos = m_strWinCtrlID.Find(_T("#"));
String* m_strLib = m_strWinCtrlID.Left(nPos);
CString strObj = m_strWinCtrlID.Mid(nPos+1);
try
{
//�����ĵ�ģ��������
Assembly* a = Assembly::Load(m_strLib);
//�õ��ĵ�ģ������������Ϣ��
Type* t = a->GetType(strObj,true,true);
//�����ĵ�ģ������һ��ʵ����
Object* m_pDotNetDocumentServer = Activator::CreateInstance(t);
//�����ĵ�ģ������"ActiveDocTemplate"��������Ϣ
//��ִ̬���ĵ�ģ������"ActiveDocTemplate"������
MethodInfo* mi = t->GetMethod(S"ActiveDocTemplate");
String* p[] = new String*[1];
CString str = _T("");
str.Format(_T("%d"),g_pDotNetExtImpl);
p[0] = str;
mi->Invoke(m_pDotNetDocumentServer,p);
}
catch (Exception* exp)
{
CString strInfo = exp->Message;
AfxMessageBox(strInfo);
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here