• Advertisement
Sign in to follow this  

CLR and LPCSTR's

This topic is 3655 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Well, I've crawled the internet for hours but I apparently have a uniquely unsolvable case. I'm using windows forms (The CLR monstrosity) to build a gui to edit files for a game. The problem is that my game is entirely coded in Native C++ with windows API and DirectX, which means heavy use of LPCSTR instead of std::strings. I can convert around easily enough, but when I try to change the pointer (set it to a new char array after delete[] ing it) CLR tells me to stop:
Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

Last Call:
 	msvcr90d.dll!102d31ea() 	

I'm not using Unicode (simply because ASCII is more convenient right now) or anything fancy, here's the code that's tossing this error at me:
source[this->Itembehavioractions->SelectedIndex].parameter.l_para = CLRTools::ToCharPtr(this->Itemactionparameter->Text);

Functions and Classes:
char* ToCharPtr(String ^s)
	{
		pin_ptr<const wchar_t> wch = PtrToStringChars(s);
	// Conversion to char* :
	// Can just convert wchar_t* to char* using one of the 
	// conversion functions such as: 
	// WideCharToMultiByte()
	// wcstombs_s()
	// ... etc
   size_t convertedChars = 0;
   size_t  sizeInBytes = ((s->Length + 1) * 2);
   errno_t err = 0;
   char    *ch = new char[sizeInBytes];

   err = wcstombs_s(&convertedChars, 
                    ch, sizeInBytes,
                    wch, sizeInBytes);
   return ch;
	}

struct Action
{
	int id; //id for the action
	char format;
	union
	{
	float f_para; //parameter for the action
	int i_para;
	LPCSTR l_para;
	}parameter;
};
Here is most of the rest of it (just form1.h)
#pragma once
#include < stdio.h >
#include < stdlib.h >
#include < vcclr.h >
#include "CoreClasses.h"

namespace ChroniclesEditor {

	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;
	namespace CLRTools{
	void ToSTDstring ( String ^ s, std::string& os ) {
   using namespace Runtime::InteropServices;
   const char* chars = 
      (const char*)(Marshal::StringToHGlobalAnsi(s)).ToPointer();
   os = chars;
   Marshal::FreeHGlobal(IntPtr((void*)chars));
}

	System::String ^MarshalString (std::string& os ) {
		System::String ^ s;
    s = gcnew String(os.c_str());
	return s;
}
	char ParseFormat(int form)
	{
		if(form = 0)
			return 'f';
		if(form = 1)
			return 'i';
		if(form = 2)
			return 's';
	}
	char* ToCharPtr(String ^s)
	{
		pin_ptr<const wchar_t> wch = PtrToStringChars(s);
	// Conversion to char* :
	// Can just convert wchar_t* to char* using one of the 
	// conversion functions such as: 
	// WideCharToMultiByte()
	// wcstombs_s()
	// ... etc
   size_t convertedChars = 0;
   size_t  sizeInBytes = ((s->Length + 1) * 2);
   errno_t err = 0;
   char    *ch = new char[sizeInBytes];

   err = wcstombs_s(&convertedChars, 
                    ch, sizeInBytes,
                    wch, sizeInBytes);
   return ch;
	}
	}


	CORE::Chronicles::SCENE Data;
	void WriteToAction(CORE::Chronicles::Action &act, int c, char f, void *para)
	{
		act.id = c;
		act.format = f;
		switch(f)
		{
		case 'f':
			act.parameter.f_para = *((float*)para);
			break;
		case 'i':
			act.parameter.i_para = *((int*)para);
			break;
		case 's':
			strcpy((char*)act.parameter.l_para, (char*) para); //DANGEROUS
			break;
		}
	}

	System::String ^ActionToString(CORE::Chronicles::Action &act)
	{
		System::String ^STR;
		STR = gcnew System::String("");
		switch(act.format)
		{
		case 'f':
			STR = System::Convert::ToString(act.parameter.f_para);
			break;
		case 'i':
			STR = System::Convert::ToString(act.parameter.i_para);
			break;
		case 's':
			std::string str;
			str = act.parameter.l_para;
			STR = CLRTools::MarshalString(str);
			break;
		}
		return STR;
	}

	CORE::Chronicles::Action *source;
			 
	
	/// <summary>
	/// Summary for Form1
	///
	/// WARNING: If you change the name of this class, you will need to change the
	///          'Resource File Name' property for the managed resource compiler tool
	///          associated with all .resx files this class depends on.  Otherwise,
	///          the designers will not be able to interact properly with localized
	///          resources associated with this form.
	/// </summary>
	public ref class Form1 : public System::Windows::Forms::Form
	{
	public:
		Form1(void)
		{
			InitializeComponent();
			//
			//TODO: Add the constructor code here
			//
		}

	protected:
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		~Form1()
		{
			if (components)
			{
				delete components;
			}
		}
	private: System::Windows::Forms::TabControl^  Tabs;
	private: System::Windows::Forms::TabPage^  ItemTab;
	protected: 

	protected: 

	private: System::Windows::Forms::TabPage^  tabPage2;
	private: System::Windows::Forms::Button^  LoadItems;
	private: System::Windows::Forms::OpenFileDialog^  OpenItem;
	private: System::Windows::Forms::ListBox^  Itemlist;
	private: System::Windows::Forms::ListBox^  Itemtype;
	private: System::Windows::Forms::Label^  label1;
	private: System::Windows::Forms::TextBox^  Itemdesc;
	private: System::Windows::Forms::TextBox^  Itemname;
	private: System::Windows::Forms::TextBox^  Itemvalue;
	private: System::Windows::Forms::Label^  label2;
	private: System::Windows::Forms::Label^  label5;
	private: System::Windows::Forms::Label^  label4;
	private: System::Windows::Forms::Label^  label3;
	private: System::Windows::Forms::ListBox^  Itembehavior;
	private: System::Windows::Forms::ListBox^  Itembehavioractions;


	private: System::Windows::Forms::Label^  label6;
	private: System::Windows::Forms::Label^  label7;
	private: System::Windows::Forms::ListBox^  Itemactioncodelist;
	private: System::Windows::Forms::Label^  label8;
	private: System::Windows::Forms::Label^  label9;
	private: System::Windows::Forms::ListBox^  Itemactionformat;
	private: System::Windows::Forms::TextBox^  Itemactionparameter;







	private:
		/// <summary>
		/// Required designer variable.
		/// </summary>
		System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		void InitializeComponent(void)
		{
			this->Tabs = (gcnew System::Windows::Forms::TabControl());
			this->ItemTab = (gcnew System::Windows::Forms::TabPage());
			this->label9 = (gcnew System::Windows::Forms::Label());
			this->Itemactionformat = (gcnew System::Windows::Forms::ListBox());
			this->Itemactionparameter = (gcnew System::Windows::Forms::TextBox());
			this->label8 = (gcnew System::Windows::Forms::Label());
			this->Itemactioncodelist = (gcnew System::Windows::Forms::ListBox());
			this->label7 = (gcnew System::Windows::Forms::Label());
			this->Itembehavioractions = (gcnew System::Windows::Forms::ListBox());
			this->label6 = (gcnew System::Windows::Forms::Label());
			this->Itembehavior = (gcnew System::Windows::Forms::ListBox());
			this->label5 = (gcnew System::Windows::Forms::Label());
			this->label4 = (gcnew System::Windows::Forms::Label());
			this->label3 = (gcnew System::Windows::Forms::Label());
			this->label2 = (gcnew System::Windows::Forms::Label());
			this->Itemvalue = (gcnew System::Windows::Forms::TextBox());
			this->Itemdesc = (gcnew System::Windows::Forms::TextBox());
			this->Itemname = (gcnew System::Windows::Forms::TextBox());
			this->Itemtype = (gcnew System::Windows::Forms::ListBox());
			this->label1 = (gcnew System::Windows::Forms::Label());
			this->Itemlist = (gcnew System::Windows::Forms::ListBox());
			this->LoadItems = (gcnew System::Windows::Forms::Button());
			this->tabPage2 = (gcnew System::Windows::Forms::TabPage());
			this->OpenItem = (gcnew System::Windows::Forms::OpenFileDialog());
			this->Tabs->SuspendLayout();
			this->ItemTab->SuspendLayout();
			this->SuspendLayout();
			// 
			// Tabs
			// 
			this->Tabs->Controls->Add(this->ItemTab);
			this->Tabs->Controls->Add(this->tabPage2);
			this->Tabs->Location = System::Drawing::Point(0, 0);
			this->Tabs->Name = L"Tabs";
			this->Tabs->SelectedIndex = 0;
			this->Tabs->Size = System::Drawing::Size(577, 333);
			this->Tabs->TabIndex = 0;
			// 
			// ItemTab
			// 
			this->ItemTab->Controls->Add(this->label9);
			this->ItemTab->Controls->Add(this->Itemactionformat);
			this->ItemTab->Controls->Add(this->Itemactionparameter);
			this->ItemTab->Controls->Add(this->label8);
			this->ItemTab->Controls->Add(this->Itemactioncodelist);
			this->ItemTab->Controls->Add(this->label7);
			this->ItemTab->Controls->Add(this->Itembehavioractions);
			this->ItemTab->Controls->Add(this->label6);
			this->ItemTab->Controls->Add(this->Itembehavior);
			this->ItemTab->Controls->Add(this->label5);
			this->ItemTab->Controls->Add(this->label4);
			this->ItemTab->Controls->Add(this->label3);
			this->ItemTab->Controls->Add(this->label2);
			this->ItemTab->Controls->Add(this->Itemvalue);
			this->ItemTab->Controls->Add(this->Itemdesc);
			this->ItemTab->Controls->Add(this->Itemname);
			this->ItemTab->Controls->Add(this->Itemtype);
			this->ItemTab->Controls->Add(this->label1);
			this->ItemTab->Controls->Add(this->Itemlist);
			this->ItemTab->Controls->Add(this->LoadItems);
			this->ItemTab->Location = System::Drawing::Point(4, 22);
			this->ItemTab->Name = L"ItemTab";
			this->ItemTab->Padding = System::Windows::Forms::Padding(3);
			this->ItemTab->Size = System::Drawing::Size(569, 307);
			this->ItemTab->TabIndex = 0;
			this->ItemTab->Text = L"Item Tab";
			this->ItemTab->UseVisualStyleBackColor = true;
			// 
			// label9
			// 
			this->label9->AutoSize = true;
			this->label9->Location = System::Drawing::Point(317, 219);
			this->label9->Name = L"label9";
			this->label9->Size = System::Drawing::Size(55, 13);
			this->label9->TabIndex = 19;
			this->label9->Text = L"Parameter";
			// 
			// Itemactionformat
			// 
			this->Itemactionformat->FormattingEnabled = true;
			this->Itemactionformat->Items->AddRange(gcnew cli::array< System::Object^  >(3) {L"Float", L"Integer", L"String"});
			this->Itemactionformat->Location = System::Drawing::Point(260, 218);
			this->Itemactionformat->Name = L"Itemactionformat";
			this->Itemactionformat->Size = System::Drawing::Size(50, 43);
			this->Itemactionformat->TabIndex = 18;
			this->Itemactionformat->Leave += gcnew System::EventHandler(this, &Form1::Itemactionformat_Leave);
			// 
			// Itemactionparameter
			// 
			this->Itemactionparameter->Location = System::Drawing::Point(316, 241);
			this->Itemactionparameter->Name = L"Itemactionparameter";
			this->Itemactionparameter->Size = System::Drawing::Size(100, 20);
			this->Itemactionparameter->TabIndex = 17;
			this->Itemactionparameter->Leave += gcnew System::EventHandler(this, &Form1::Itemactionparameter_Leave);
			// 
			// label8
			// 
			this->label8->AutoSize = true;
			this->label8->Location = System::Drawing::Point(418, 7);
			this->label8->Name = L"label8";
			this->label8->Size = System::Drawing::Size(42, 13);
			this->label8->TabIndex = 16;
			this->label8->Text = L"Actions";
			// 
			// Itemactioncodelist
			// 
			this->Itemactioncodelist->FormattingEnabled = true;
			this->Itemactioncodelist->Items->AddRange(gcnew cli::array< System::Object^  >(73) {L"i_none", L"i_movex", L"i_movey,", L"i_movez,", 
				L"i_rotate,", L"i_face,", L"i_scalex,", L"i_scaley,", L"i_animate, ", L"i_msg, ", L"i_addhp,", L"i_remhp,", L"i_addmhp,", L"i_remmhp, ", 
				L"i_addm, ", L"i_remm,", L"i_addmm, ", L"i_remmm, ", L"i_addexp,", L"i_addmight,", L"i_remmight,", L"i_addfin,", L"i_remfin,", 
				L"i_addint,", L"i_remint,", L"i_addwil,", L"i_remwil,", L"i_addess,", L"i_remess,", L"i_addcor,", L"i_remcor,", L"i_addbonushp,", 
				L"i_rembonushp,", L"i_addbonusmhp, ", L"i_rembonusmhp, ", L"i_addbonusm, ", L"i_rembonusm,", L"i_addbonusmm, ", L"i_rembonusmm, ", 
				L"i_addbonusmight,", L"i_rembonusmight,", L"i_addbonusfin,", L"i_rembonusfin,", L"i_addbonusint,", L"i_rembonusint,", L"i_addbonuswil,", 
				L"i_rembonuswil,", L"i_addbonusess,", L"i_rembonusess,", L"i_addbonuscor,", L"i_rembonuscor,", L"i_addgold,", L"i_remgold,", 
				L"i_addarmor,", L"i_remarmor,", L"i_addattack,", L"i_remattack,", L"i_additem,", L"i_remitem,", L"i_unequip,", L"i_equip,", L"i_create, ", 
				L"i_delete, ", L"i_act, ", L"i_send, ", L"i_changemap, ", L"i_script,", L"i_playsound,", L"i_effect,", L"i_costmagic,", L"i_costhealth, ", 
				L"i_costgold,  ", L"i_costitem "});
			this->Itemactioncodelist->Location = System::Drawing::Point(421, 23);
			this->Itemactioncodelist->Name = L"Itemactioncodelist";
			this->Itemactioncodelist->Size = System::Drawing::Size(140, 277);
			this->Itemactioncodelist->TabIndex = 15;
			this->Itemactioncodelist->SelectedIndexChanged += gcnew System::EventHandler(this, &Form1::Itemactioncodelist_SelectedIndexChanged);
			// 
			// label7
			// 
			this->label7->AutoSize = true;
			this->label7->Location = System::Drawing::Point(286, 98);
			this->label7->Name = L"label7";
			this->label7->Size = System::Drawing::Size(87, 13);
			this->label7->TabIndex = 14;
			this->label7->Text = L"Behavior Actions";
			// 
			// Itembehavioractions
			// 
			this->Itembehavioractions->FormattingEnabled = true;
			this->Itembehavioractions->Location = System::Drawing::Point(286, 117);
			this->Itembehavioractions->Name = L"Itembehavioractions";
			this->Itembehavioractions->Size = System::Drawing::Size(120, 95);
			this->Itembehavioractions->TabIndex = 13;
			this->Itembehavioractions->SelectedIndexChanged += gcnew System::EventHandler(this, &Form1::Itembehavioractions_SelectedIndexChanged);
			// 
			// label6
			// 
			this->label6->AutoSize = true;
			this->label6->Location = System::Drawing::Point(283, 32);
			this->label6->Name = L"label6";
			this->label6->Size = System::Drawing::Size(76, 13);
			this->label6->TabIndex = 12;
			this->label6->Text = L"Behavior Type";
			// 
			// Itembehavior
			// 
			this->Itembehavior->FormattingEnabled = true;
			this->Itembehavior->Items->AddRange(gcnew cli::array< System::Object^  >(3) {L"Equip Behavior", L"Use Behavior", L"Remove Behavior"});
			this->Itembehavior->Location = System::Drawing::Point(286, 49);
			this->Itembehavior->Name = L"Itembehavior";
			this->Itembehavior->Size = System::Drawing::Size(93, 43);
			this->Itembehavior->TabIndex = 11;
			this->Itembehavior->SelectedIndexChanged += gcnew System::EventHandler(this, &Form1::Itembehavior_SelectedIndexChanged);
			// 
			// label5
			// 
			this->label5->AutoSize = true;
			this->label5->Location = System::Drawing::Point(134, 157);
			this->label5->Name = L"label5";
			this->label5->Size = System::Drawing::Size(83, 13);
			this->label5->TabIndex = 10;
			this->label5->Text = L"Item Description";
			// 
			// label4
			// 
			this->label4->AutoSize = true;
			this->label4->Location = System::Drawing::Point(134, 82);
			this->label4->Name = L"label4";
			this->label4->Size = System::Drawing::Size(57, 13);
			this->label4->TabIndex = 9;
			this->label4->Text = L"Item Value";
			// 
			// label3
			// 
			this->label3->AutoSize = true;
			this->label3->Location = System::Drawing::Point(134, 32);
			this->label3->Name = L"label3";
			this->label3->Size = System::Drawing::Size(58, 13);
			this->label3->TabIndex = 8;
			this->label3->Text = L"Item Name";
			// 
			// label2
			// 
			this->label2->AutoSize = true;
			this->label2->Location = System::Drawing::Point(9, 157);
			this->label2->Name = L"label2";
			this->label2->Size = System::Drawing::Size(54, 13);
			this->label2->TabIndex = 7;
			this->label2->Text = L"Item Type";
			// 
			// Itemvalue
			// 
			this->Itemvalue->Location = System::Drawing::Point(134, 98);
			this->Itemvalue->Name = L"Itemvalue";
			this->Itemvalue->Size = System::Drawing::Size(120, 20);
			this->Itemvalue->TabIndex = 6;
			this->Itemvalue->Leave += gcnew System::EventHandler(this, &Form1::Itemvalue_Leave);
			// 
			// Itemdesc
			// 
			this->Itemdesc->Location = System::Drawing::Point(134, 176);
			this->Itemdesc->Multiline = true;
			this->Itemdesc->Name = L"Itemdesc";
			this->Itemdesc->Size = System::Drawing::Size(120, 95);
			this->Itemdesc->TabIndex = 5;
			this->Itemdesc->Leave += gcnew System::EventHandler(this, &Form1::Itemdesc_Leave);
			// 
			// Itemname
			// 
			this->Itemname->Location = System::Drawing::Point(134, 50);
			this->Itemname->Name = L"Itemname";
			this->Itemname->Size = System::Drawing::Size(120, 20);
			this->Itemname->TabIndex = 4;
			this->Itemname->TextChanged += gcnew System::EventHandler(this, &Form1::Itemname_TextChanged);
			this->Itemname->Leave += gcnew System::EventHandler(this, &Form1::Itemname_Leave);
			// 
			// Itemtype
			// 
			this->Itemtype->FormattingEnabled = true;
			this->Itemtype->Items->AddRange(gcnew cli::array< System::Object^  >(18) {L"it_none", L"it_head", L"it_rhand", L"it_lhand ", 
				L"it_bhands", L"it_chest", L"it_rglove", L"it_lglove", L"it_boots", L"it_legs", L"it_pack", L"it_neck", L"it_ring", L"it_food", 
				L"it_magic", L"it_trade", L"it_acc", L"it_other"});
			this->Itemtype->Location = System::Drawing::Point(8, 176);
			this->Itemtype->Name = L"Itemtype";
			this->Itemtype->Size = System::Drawing::Size(120, 95);
			this->Itemtype->TabIndex = 3;
			this->Itemtype->SelectedIndexChanged += gcnew System::EventHandler(this, &Form1::Itemtype_SelectedIndexChanged);
			// 
			// label1
			// 
			this->label1->AutoSize = true;
			this->label1->Location = System::Drawing::Point(9, 33);
			this->label1->Name = L"label1";
			this->label1->Size = System::Drawing::Size(32, 13);
			this->label1->TabIndex = 2;
			this->label1->Text = L"Items";
			// 
			// Itemlist
			// 
			this->Itemlist->FormattingEnabled = true;
			this->Itemlist->Location = System::Drawing::Point(8, 49);
			this->Itemlist->Name = L"Itemlist";
			this->Itemlist->Size = System::Drawing::Size(120, 95);
			this->Itemlist->TabIndex = 1;
			this->Itemlist->SelectedIndexChanged += gcnew System::EventHandler(this, &Form1::Itemlist_SelectedIndexChanged);
			// 
			// LoadItems
			// 
			this->LoadItems->Location = System::Drawing::Point(6, 3);
			this->LoadItems->Name = L"LoadItems";
			this->LoadItems->Size = System::Drawing::Size(75, 23);
			this->LoadItems->TabIndex = 0;
			this->LoadItems->Text = L"Load";
			this->LoadItems->UseVisualStyleBackColor = true;
			this->LoadItems->Click += gcnew System::EventHandler(this, &Form1::LoadItems_Click);
			// 
			// tabPage2
			// 
			this->tabPage2->Location = System::Drawing::Point(4, 22);
			this->tabPage2->Name = L"tabPage2";
			this->tabPage2->Padding = System::Windows::Forms::Padding(3);
			this->tabPage2->Size = System::Drawing::Size(569, 307);
			this->tabPage2->TabIndex = 1;
			this->tabPage2->Text = L"tabPage2";
			this->tabPage2->UseVisualStyleBackColor = true;
			// 
			// OpenItem
			// 
			this->OpenItem->DefaultExt = L"idb";
			this->OpenItem->Filter = L"Item Files|*.idb";
			this->OpenItem->FileOk += gcnew System::ComponentModel::CancelEventHandler(this, &Form1::OpenItem_FileOk);
			// 
			// Form1
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->ClientSize = System::Drawing::Size(577, 332);
			this->Controls->Add(this->Tabs);
			this->Name = L"Form1";
			this->Text = L"Form1";
			this->Tabs->ResumeLayout(false);
			this->ItemTab->ResumeLayout(false);
			this->ItemTab->PerformLayout();
			this->ResumeLayout(false);

		}
#pragma endregion
	private: System::Void LoadItems_Click(System::Object^  sender, System::EventArgs^  e) {
				 this->OpenItem->ShowDialog();
			 }
private: System::Void OpenItem_FileOk(System::Object^  sender, System::ComponentModel::CancelEventArgs^  e) 
		 {
			 std::string str;
			 CLRTools::ToSTDstring(this->OpenItem->FileName, str);
			 //Now we have an string, we open our file with it
			 Data.collection.LoadItems(str.c_str()); //Load in the items
			 //Load out the item names to the box
			 //System::String ^Sstr;
			 //Sstr = gcnew System::String("");
			 this->Itemlist->Items->Clear();

			 for(int i = 0; i < Data.collection.item_count; i++)
			 {
				 this->Itemlist->Items->Add(System::Convert::ToString(i));
			 }	 
		 }
private: System::Void Itemlist_SelectedIndexChanged(System::Object^  sender, System::EventArgs^  e) {
			 this->Itemtype->SelectedIndex = System::Convert::ToInt32(Data.collection.items[this->Itemlist->SelectedIndex].type);
			 this->Itemvalue->Text = System::Convert::ToString(Data.collection.items[this->Itemlist->SelectedIndex].m_value);
			 std::string str;
			 str = Data.collection.items[this->Itemlist->SelectedIndex].m_name;
			 this->Itemname->Text = CLRTools::MarshalString(str);
			 str = Data.collection.items[this->Itemlist->SelectedIndex].m_description;
			 this->Itemdesc->Text = CLRTools::MarshalString(str);
			 this->Itembehavioractions->Items->Clear();
			 
		 }
private: System::Void Itemtype_SelectedIndexChanged(System::Object^  sender, System::EventArgs^  e) {
			 //Write back
			 //Write the data back into the index
			 Data.collection.items[this->Itemlist->SelectedIndex].type = (short) System::Convert::ToInt32(this->Itemtype->SelectedIndex);
		 }
private: System::Void Itemname_TextChanged(System::Object^  sender, System::EventArgs^  e) {
			//Wait		 
		 }
private: System::Void Itemname_Leave(System::Object^  sender, System::EventArgs^  e) {
			 //Write back the data
			 std::string str;
			 CLRTools::ToSTDstring(this->Itemname->Text, str);
			 delete [] Data.collection.items[this->Itemlist->SelectedIndex].m_name;
			 Data.collection.items[this->Itemlist->SelectedIndex].m_name = new char[str.length()];
			 strcpy((char*)Data.collection.items[this->Itemlist->SelectedIndex].m_name, str.c_str());
			 //done
		 }
private: System::Void Itemdesc_Leave(System::Object^  sender, System::EventArgs^  e) {
			  //Write back the data
			 std::string str;
			 CLRTools::ToSTDstring(this->Itemname->Text, str);
			 delete [] Data.collection.items[this->Itemlist->SelectedIndex].m_description;
			 Data.collection.items[this->Itemlist->SelectedIndex].m_description = new char[str.length()];
			 strcpy((char*)Data.collection.items[this->Itemlist->SelectedIndex].m_description, str.c_str());
			 //done

		 }
private: System::Void Itemvalue_Leave(System::Object^  sender, System::EventArgs^  e) {
			 Data.collection.items[this->Itemlist->SelectedIndex].m_value = (float) System::Convert::ToDouble(this->Itemvalue->Text);
		 }
private: System::Void Itembehavior_SelectedIndexChanged(System::Object^  sender, System::EventArgs^  e) {
			 //We need to convert the action names into strings to add into the box
			 this->Itembehavioractions->Items->Clear();
			 switch(this->Itembehavior->SelectedIndex)
			 {
			 case 0:
				 //Enumerate list with equipped index
				 for(int i = 0; i < Data.collection.items[this->Itemlist->SelectedIndex].equip_count; i++)
				 {
					 this->Itembehavioractions->Items->Add(System::Convert::ToString(i));
				 }
				 break;
			 case 1:
				  for(int i = 0; i < Data.collection.items[this->Itemlist->SelectedIndex].use_count; i++)
				 {
					 this->Itembehavioractions->Items->Add(System::Convert::ToString(i));
				 }
				 break;
			 case 2:
				  for(int i = 0; i < Data.collection.items[this->Itemlist->SelectedIndex].remove_count; i++)
				 {
					 this->Itembehavioractions->Items->Add(System::Convert::ToString(i));
				 }
				 break;
			 }

		 }
private: System::Void Itembehavioractions_SelectedIndexChanged(System::Object^  sender, System::EventArgs^  e) {
			 //unsigned long count;
			 switch(this->Itembehavior->SelectedIndex)
			 {
			 case 0:
				 source = Data.collection.items[this->Itemlist->SelectedIndex].equip;
				 //count = Data.collection.items[this->Itemlist->SelectedIndex].equip_count;
				 break;
			 case 1:
				 source = Data.collection.items[this->Itemlist->SelectedIndex].use;
				 //count = Data.collection.items[this->Itemlist->SelectedIndex].use_count;
				 break;
			 case 2:
				 source = Data.collection.items[this->Itemlist->SelectedIndex].remove;
				 //count = Data.collection.items[this->Itemlist->SelectedIndex].remove_count;
				 break;
			 }
			 //Perform our actions
			 this->Itemactioncodelist->SelectedIndex = source[this->Itembehavioractions->SelectedIndex].id;
			 switch(source[this->Itembehavioractions->SelectedIndex].format)
			 {
			 case 'f':
				 this->Itemactionformat->SelectedIndex = 0;
				 break;
			 case 'i':
				 this->Itemactionformat->SelectedIndex = 1;
				 break;
			 case 's':
				 this->Itemactionformat->SelectedIndex = 2;
				 break;
			 }
			 this->Itemactionparameter->Text = ActionToString(source[this->Itembehavioractions->SelectedIndex]);
			 
		 }
private: System::Void Itemactionformat_Leave(System::Object^  sender, System::EventArgs^  e) {
			 //Write back data
			 char t;
			 switch(this->Itemactionformat->SelectedIndex)
			 {
			 case 0:
				 t = 'f';
				 break;
			 case 1:
				 t = 'i';
				 break;
			 case 2:
				 t = 's';
				 break;
			 }
			 source[this->Itembehavioractions->SelectedIndex].format = t;
			 
			 
		 }
private: System::Void Itemactionparameter_Leave(System::Object^  sender, System::EventArgs^  e) {
			 //Write back the parameter using source
			 switch(this->Itemactionformat->SelectedIndex)
			 {
			 case 0:
				 source[this->Itembehavioractions->SelectedIndex].parameter.f_para = (float)System::Convert::ToDecimal(this->Itemactionparameter->Text);
				 break;
			 case 1:
				 source[this->Itembehavioractions->SelectedIndex].parameter.i_para = System::Convert::ToInt32(this->Itemactionparameter->Text);
				 break;
			 case 2:
			//	 std::string str;
			 //CLRTools::ToSTDstring(this->Itemactionparameter->Text, str);
			 delete [] source[this->Itembehavioractions->SelectedIndex].parameter.l_para;
			 source[this->Itembehavioractions->SelectedIndex].parameter.l_para = CLRTools::ToCharPtr(this->Itemactionparameter->Text);
			 break;
			 }
		 }
private: System::Void Itemactioncodelist_SelectedIndexChanged(System::Object^  sender, System::EventArgs^  e) {
			 //Write back data
			 source[this->Itembehavioractions->SelectedIndex].id = this->Itemactioncodelist->SelectedIndex;
		 }
};
}




Compiles fine and everything... [Edited by - Plasmarobo on February 16, 2008 7:44:15 PM]

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement