我使用此代码创建了一个线程:
ToServer变量在Client.cpp的main函数中创建。 ToServer varaible有他的缓冲区。
CLI ^console = gcnew CLI(ToServer);
Thread ^consoleThread = gcnew Thread(gcnew ThreadStart(console, &CLI::Start));
consoleThread->Start();
当尝试在缓冲区发送前格式化数据时,我得到了此方法的错误。错误在线
head-> tag = htons(Globals :: CommandTag);
struct header{
USHORT tag;
ULONG lenght;
};
const unsigned short int Globals::CommandTag = 0;
在CLI中,我称之为:
void ToServerSocket::CommandList(int page){
this->head = (struct header*) this->buffer[0];
head->tag = htons(Globals::CommandTag);
head->lenght = htons(sizeof (listCommand) );
listCommand* list = (struct listCommand*) this->buffer[sizeof(header)];
list->command = htons(1);
list->page = htons(page);
this->Send(this->buffer, sizeof(head)+sizeof(listCommand));
}
如何从此线程访问父变量?
当我尝试更改ToServer
对象中的父变量时,我收到此错误:
尝试读取或写入受保护的内存