int ValidateCStyle(void *ptr, int type){ //Validate each element while(1){ //the buffer is at right place of memory int result = ValidatePtr(ptr, type, PROT_READ); if(result == -1) return -1; //if the element inside is char then the original will be a char[] and will end with '\0' if(type == sizeof(char)){ if(*((char *)ptr) == '\0') return 0; ptr = ((char *)ptr) + 1; //if the element inside is char pointer Then the origianl one will be a pointer to an array og pointer(char**) End with NULL }else if(type == sizeof(char *)){ if(*((char **)ptr) == NULL) return 0; ptr = ((char **)ptr) + 1; } } }
bool SNM_GetSetObjectState(void* _obj, WDL_FastString* _state, bool _setnewvalue, bool _minstate) { bool ok = false; if (_state && g_script_strs.Find(_state)>=0 && (ValidatePtr(_obj, "MediaTrack*") || ValidatePtr(_obj, "MediaItem*") || ValidatePtr(_obj, "TrackEnvelope*"))) { int fxstate = SNM_PreObjectState(_setnewvalue ? _state : NULL, _minstate); char* p = GetSetObjectState(_obj, _setnewvalue ? _state->Get() : NULL); if (_setnewvalue) { ok = (p==NULL); } else if (p) { _state->Set(p); FreeHeapPtr((void*)p); ok = true; } SNM_PostObjectState(fxstate); } return ok; }
SimpleExampleWindow::SimpleExampleWindow(HWND parent, std::string title) : MRPWindow(parent,title) { m_last_project_change_count = GetProjectStateChangeCount(nullptr); m_but1 = std::make_shared<WinButton>(this, "Get take name"); m_but1->GenericNotifyCallback = [this](GenericNotifications) { if (CountSelectedMediaItems(nullptr) > 0) { MediaItem* item = GetSelectedMediaItem(nullptr, 0); MediaItem_Take* take = GetActiveTake(item); if (take != nullptr) { char buf[2048]; GetSetMediaItemTakeInfo_String(take, "P_NAME", buf, false); m_edit1->setText(buf); } } }; add_control(m_but1); m_but2 = std::make_shared<WinButton>(this, "Set take name"); m_but2->GenericNotifyCallback = [this](GenericNotifications) { if (CountSelectedMediaItems(nullptr) > 0) { MediaItem* item = GetSelectedMediaItem(nullptr, 0); MediaItem_Take* take = GetActiveTake(item); if (take != nullptr) { GetSetMediaItemTakeInfo_String(take, "P_NAME", (char*)m_edit1->getText().c_str(), true); UpdateArrange(); } } }; add_control(m_but2); m_but3 = std::make_shared<WinButton>(this, "Refresh item list"); m_but3->GenericNotifyCallback = [this](GenericNotifications) { populate_listbox(); }; add_control(m_but3); m_but4 = std::make_shared<WinButton>(this, "Remove selected listbox item foffoffooo"); m_but4->GenericNotifyCallback = [this](GenericNotifications) { int selindex = m_listbox1->getSelectedIndex(); if (selindex >= 0) { m_listbox1->removeItem(selindex); m_itemmap.erase(m_listbox1->userIDfromIndex(selindex)); } }; add_control(m_but4); m_edit1 = std::make_shared<WinLineEdit>(this, "No take name yet"); add_control(m_edit1); m_listbox1 = std::make_shared<WinListBox>(this); m_listbox1->SelectedChangedCallback = [this](int index) mutable { if (index >= 0) { std::string temp = m_listbox1->getItemText(index); readbg() << "you chose " << temp << " from the listbox\n"; int user_id = m_listbox1->userIDfromIndex(index); MediaItem* itemfromlist = m_itemmap[user_id]; if (ValidatePtr((void*)itemfromlist, "MediaItem*") == true) { m_edit1->setText(std::string("You chose item with mem address " + std::to_string((uint64_t)itemfromlist) + " from the listbox")); } else m_edit1->setText(("You chose an item from listbox that's no longer valid!")); } else readbg() << "you managed to choose no item from the listbox\n"; }; add_control(m_listbox1); add_control(m_listbox1); m_checkbox1 = std::make_shared<WinCheckBox>(this,"The check box"); add_control(m_checkbox1); m_checkbox1->GenericNotifyCallback = [this](GenericNotifications reason) { if (reason == GenericNotifications::Checked) readbg() << "check box was checked\n"; else readbg() << "check box was unchecked\n"; }; m_label1 = std::make_shared<WinLabel>(this, "Ok, will all this text be shown by default...? I wonder..."); add_control(m_label1); m_label1->setTopLeftPosition(150, 60); m_rectcontrol1 = std::make_shared<RectangleTestControl>(this); add_control(m_rectcontrol1); setSize(900, 650); }