ãMEFã¯.NETã©ã¤ãã©ãªã§ãããããã¥ã¢ãªC++ã§ã¯ä½¿ããªããã©ãã»ã¼C++ããªC++/CLIãªãä½ã¨ããªãããããªããã¨ãMSDNã§è¦ã¤ããããã¥ã¡ã³ããææããã« MEFï¼ã¯ããã®ä¸æ©ãC++/CLIã§è¸ã¿åºãã¾ããã
DLLãCOMãããã¦MEF
ãre-buildãªãã«æ©è½æ¡å¼µããæ段ã¯ãã£ã¨ä»¥åããããã¾ããWindowsã§ã¯DLLãããªãã¿ã§ãããDLLã®ä¸ã«ã¯é¢æ°åãåãè¾¼ããã¨ãã§ããLoadLibrary()ã§DLLãèªã¿è¾¼ãã å¾GetProcAddress()ã«é¢æ°åãä¸ããã°ãå½è©²é¢æ°ã®ã¢ãã¬ã¹ãæã«å ¥ã/å¼ã³åºããã¨ãã§ãã¾ãããã ãæã«å ¥ãã®ã¯é¢æ°ã®ã¢ãã¬ã¹ã ãã§ãå¼æ°ãæ»ãå¤ã«é¢ããæ å ±ã¯ããããªãã®ã§æ±ºãæã¡ã«ããããããã¾ããããé¢æ°/å¤æ°ãã²ã¨ã¾ã¨ãã«ãããªãã¸ã§ã¯ãï¼ã¯ã©ã¹ï¼ãå®ç¾©ãã¦å¼ã³åºããã¨ãã§ãã¾ãããããã§ãªãã¸ã§ã¯ããå®ç¾©ãå¼ã³åºããCOMã®ç»å ´ã¨ãªãããã§ããããCOMã£ã¦ã·ãã¢ãã¯ä½ãå´ã使ãå´ãããªããããããã決ãã¦"ãæ軽"ã¨ã¯è¨ãé£ãã
ãMEFã«ããæ©è½æ¡å¼µã§ã¯ãæ¡å¼µãããæ©è½ãinterfaceã§å®ç¾©ãã¾ããæ©è½ãæä¾ããå´ã¯ãã®interfaceãå®è£ ããã¯ã©ã¹ãä½ã£ã¦Exportï¼å¤ã«åºã/å ¬éããï¼ãã対ãã¦æ©è½ãå©ç¨ããå´ã¯interfaceã®åãç¿ãç¨æãã¦ãããã«Importï¼åãè¾¼ãï¼ãã¾ããMEFã¯æä¾ï¼Exportï¼å´ã¨å©ç¨ï¼Importï¼å´ã¨ã®ä»²ä»ãè¡ãã両è ãçµã³ã¤ãã¦ããã¾ããExport/Importã¯ã¯ã©ã¹ãå¤æ°ã«ã¢ããªãã¥ã¼ãï¼[Export(ï½)]/[Import(ï½)]ãä»è¨ããã ããªã®ã§ãCOMã«æ¯ã¹ã¦å§åçã«ç°¡åã§ãã
ãè½æ¸ãã¯ãããããã«ãã¦ããµã³ãã«ããè¦ããã¾ãããã
äºé é»åï¼Windows Formã¢ããªã±ã¼ã·ã§ã³ã®ä½ãæ¹
ããµã³ãã«ã«ç¨æããã®ã¯ããããªå¤è¦³ã®é»åã¢ããªã±ã¼ã·ã§ã³ã
ãintå¤ã2ã¤å ¥åããæ¼ç®åãé¸ãã§ã=ããã¿ã³ãæ¼ãã¨çãã表示ãããããã¾ãã®ã·ã§ããã«é»åã¨å¼ã¶ã®ãæ¥ããããäºé é»åãWindows Formsã§ä½ãã¾ãããComboBoxã«åæãããæ¼ç®åãMEFã§è¿½å ãããã¨ããéèã§ãã
ãVisual Studio 2012以éãC++/CLIã«ããCLRãã©ã¼ã ã¢ããªã±ã¼ã·ã§ã³ã®ã²ãªåãããã¸ã§ã¯ããã³ãã¬ã¼ãããæ¶ãã¦ãã¾ãã¾ããããã©ãä½ããªããªã£ãããã§ã¯ããã¾ãããã¡ãã£ã¨å¯ãéã«ãªãã¾ããããã©ã¼ã ã¢ããªã±ã¼ã·ã§ã³ã®ä½ãæ¹ãç´¹ä»ãã¦ããã¾ãã
ãã¾ããããã¸ã§ã¯ããã³ãã¬ã¼ãã§ã¯ã空ã®CLRããã¸ã§ã¯ãããé¸æãã¾ããããã¸ã§ã¯ãåã¯"SimpleCalculator"ã¨ãã¾ãããã
ãã¤ãã«ã¡ãã¥ã¼ï¼ããã¸ã§ã¯ã/æ°ããé ç®ã®è¿½å ...ã§Windowsãã©ã¼ã ã追å ãã¾ãããã©ã¼ã åã¯"CalculatorForm"ã§ã
ãããã«ã¡ãã¥ã¼ï¼ããã¸ã§ã¯ã/æ°ããé ç®ã®è¿½å ...ã§C++ãã¡ã¤ã«ï¼.cppï¼ãååã"SimpleCalculator.cpp"ã¨ãã¦ã³ã¼ãã追å ãã¾ãããããã¢ããªã±ã¼ã·ã§ã³ã®å ¥ãå£ã§ããmain()ã§ãã
#include "CalculatorForm.h" using namespace System; [STAThread] int main(array<String^>^ args) { using namespace System::Windows::Forms; Application::EnableVisualStyles(); Application::SetCompatibleTextRenderingDefault(false); Application::Run(gcnew SimpleCalculator::CalculatorForm()); return 0; }
ãæ®ãã¯ããã¸ã§ã¯ãã»ããããã£ã®è¨å®ãæ§æããããã£/ãªã³ã«ã¼/ã·ã¹ãã /ãµãã·ã¹ãã ãWindows(/SUBSYSTEM:WINDOWS)ã«ãæ§æããããã£/ãªã³ã«ã¼/詳細è¨å®/ã¨ã³ããªãã¤ã³ããmainã¨ãã¾ãã
ãããã§ãã«ã/å®è¡ãã空ã£ã½ã®CalculatorFormãç¾ãããåºæ¥ä¸ããã2ã¤ã®TextBoxã¨ComboBoxãButtonããã¦å¤§ããªLabelãè²¼ãä»ããButton-Clickãã³ãã©ãç¨æãã¦é»åãã©ã¼ã ã®å®æã§ãã
ãæå¾ã«ããä¸ã¤ãMEFãæä¾ããã¢ã»ã³ããªï¼System.ComponentModel.Compositionã¸ã®åç §ã追å ãã¦ããã¾ãã