+ void CreateDelegates()
+ {
+ DestroyDelegates();
+
+ if (!m_bDelegatesCreated)
+ {
+ msclr::interop::marshal_context ^ context = gcnew msclr::interop::marshal_context();
+
+ // create the delegate method for the log message callback
+ m_logMessageDelegate = gcnew CecLogMessageManagedDelegate(this, &CecCallbackMethods::CecLogMessageManaged);
+ m_logMessageGCHandle = System::Runtime::InteropServices::GCHandle::Alloc(m_logMessageDelegate);
+ g_logCB = static_cast<LOGCB>(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_logMessageDelegate).ToPointer());
+ g_cecCallbacks.CBCecLogMessage = CecLogMessageCB;
+
+ // create the delegate method for the keypress callback
+ m_keypressDelegate = gcnew CecKeyPressManagedDelegate(this, &CecCallbackMethods::CecKeyPressManaged);
+ m_keypressGCHandle = System::Runtime::InteropServices::GCHandle::Alloc(m_keypressDelegate);
+ g_keyCB = static_cast<KEYCB>(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_keypressDelegate).ToPointer());
+ g_cecCallbacks.CBCecKeyPress = CecKeyPressCB;
+
+ // create the delegate method for the command callback
+ m_commandDelegate = gcnew CecCommandManagedDelegate(this, &CecCallbackMethods::CecCommandManaged);
+ m_commandGCHandle = System::Runtime::InteropServices::GCHandle::Alloc(m_commandDelegate);
+ g_commandCB = static_cast<COMMANDCB>(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_commandDelegate).ToPointer());
+ g_cecCallbacks.CBCecCommand = CecCommandCB;
+
+ // create the delegate method for the configuration change callback
+ m_configDelegate = gcnew CecConfigManagedDelegate(this, &CecCallbackMethods::CecConfigManaged);
+ m_configGCHandle = System::Runtime::InteropServices::GCHandle::Alloc(m_configDelegate);
+ g_configCB = static_cast<CONFIGCB>(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_configDelegate).ToPointer());
+ g_cecCallbacks.CBCecConfigurationChanged = CecConfigCB;
+
+ // create the delegate method for the alert callback
+ m_alertDelegate = gcnew CecAlertManagedDelegate(this, &CecCallbackMethods::CecAlertManaged);
+ m_alertGCHandle = System::Runtime::InteropServices::GCHandle::Alloc(m_alertDelegate);
+ g_alertCB = static_cast<ALERTCB>(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_alertDelegate).ToPointer());
+ g_cecCallbacks.CBCecAlert = CecAlertCB;
+
+ // create the delegate method for the menu callback
+ m_menuDelegate = gcnew CecMenuManagedDelegate(this, &CecCallbackMethods::CecMenuManaged);
+ m_menuGCHandle = System::Runtime::InteropServices::GCHandle::Alloc(m_menuDelegate);
+ g_menuCB = static_cast<MENUCB>(System::Runtime::InteropServices::Marshal::GetFunctionPointerForDelegate(m_menuDelegate).ToPointer());
+ g_cecCallbacks.CBCecMenuStateChanged = CecMenuCB;
+
+ delete context;
+ m_bDelegatesCreated = true;
+ }
+ }
+