0

I'm getting an error where it says I'm trying to use a null pointer. Then when I click ignore another error saying I tried to read or write protected memory. Any idea how to fix?

private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {


 using namespace System::Runtime::InteropServices;
using namespace System;
using namespace System::Text;

System::String ^ zs = textBox1->Text;
char* str2 = (char*)(void*)Marshal::StringToHGlobalAnsi(zs);
bob.SendData(str2);

Sleep(2000);

char er[50];
memcpy(er,"-",50);
bob.RecvData(er,50);

string string1(er, 50);

System::String ^swq;
MarshalString(swq, string1);
label2->Text = "Hi";


			 }
2
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by jencas
0

More code:

Recive Data:

bool Socket::RecvData( char *buffer, int size )
{
	int i = recv( mySocket, buffer, size, 0 );
	buffer[i] = '\0';
	return true;
}

Marshall Function:

void MarshalString ( String ^ s, string& os ) {
   using namespace Runtime::InteropServices;
   const char* chars = 
	  (const char*)(Marshal::StringToHGlobalAnsi(s)).ToPointer();
   os = chars;
   Marshal::FreeHGlobal(IntPtr((void*)chars));
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.