Thread Problem
-
Hi, I've a global variable char*tptr. The routines for writing and reading are shown below. The problem is that when I want to write some value example tptr= "HELLO"; The response to "HELLO" is "MORNING" however tptr only returns "MORNI" from the ThreadEzusbRead function and then followed by some memory errors messages. Any suggestions much appreciated Kind Regards Caoimh void ThreadEzusbWrite(HANDLE hDeviceWrite) { unsigned long nbyte; BOOLEAN bResult = FALSE; BULK_TRANSFER_CONTROL bulkControl; bulkControl.pipeNum = 0; DWORD IOCTL = IOCTL_EZUSB_BULK_WRITE; bResult = DeviceIoControl( hDeviceWrite, IOCTL, &bulkControl, sizeof(BULK_TRANSFER_CONTROL), tptr, 30, &nbyte, NULL ); if(WriteEvent) SetEvent(WriteEvent); } void ThreadEzusbRead(HANDLE hDeviceRead) { unsigned long nbyte; BOOLEAN bResult = FALSE; BULK_TRANSFER_CONTROL bulkControl; bulkControl.pipeNum = 2; DWORD IOCTL = IOCTL_EZUSB_BULK_READ; bResult = DeviceIoControl( hDeviceRead, IOCTL, &bulkControl, sizeof(BULK_TRANSFER_CONTROL), tptr, 30, &nbyte, NULL ); if(ReadEvent) SetEvent(ReadEvent); }
-
Hi, I've a global variable char*tptr. The routines for writing and reading are shown below. The problem is that when I want to write some value example tptr= "HELLO"; The response to "HELLO" is "MORNING" however tptr only returns "MORNI" from the ThreadEzusbRead function and then followed by some memory errors messages. Any suggestions much appreciated Kind Regards Caoimh void ThreadEzusbWrite(HANDLE hDeviceWrite) { unsigned long nbyte; BOOLEAN bResult = FALSE; BULK_TRANSFER_CONTROL bulkControl; bulkControl.pipeNum = 0; DWORD IOCTL = IOCTL_EZUSB_BULK_WRITE; bResult = DeviceIoControl( hDeviceWrite, IOCTL, &bulkControl, sizeof(BULK_TRANSFER_CONTROL), tptr, 30, &nbyte, NULL ); if(WriteEvent) SetEvent(WriteEvent); } void ThreadEzusbRead(HANDLE hDeviceRead) { unsigned long nbyte; BOOLEAN bResult = FALSE; BULK_TRANSFER_CONTROL bulkControl; bulkControl.pipeNum = 2; DWORD IOCTL = IOCTL_EZUSB_BULK_READ; bResult = DeviceIoControl( hDeviceRead, IOCTL, &bulkControl, sizeof(BULK_TRANSFER_CONTROL), tptr, 30, &nbyte, NULL ); if(ReadEvent) SetEvent(ReadEvent); }
-
Hi, I've a global variable char*tptr. The routines for writing and reading are shown below. The problem is that when I want to write some value example tptr= "HELLO"; The response to "HELLO" is "MORNING" however tptr only returns "MORNI" from the ThreadEzusbRead function and then followed by some memory errors messages. Any suggestions much appreciated Kind Regards Caoimh void ThreadEzusbWrite(HANDLE hDeviceWrite) { unsigned long nbyte; BOOLEAN bResult = FALSE; BULK_TRANSFER_CONTROL bulkControl; bulkControl.pipeNum = 0; DWORD IOCTL = IOCTL_EZUSB_BULK_WRITE; bResult = DeviceIoControl( hDeviceWrite, IOCTL, &bulkControl, sizeof(BULK_TRANSFER_CONTROL), tptr, 30, &nbyte, NULL ); if(WriteEvent) SetEvent(WriteEvent); } void ThreadEzusbRead(HANDLE hDeviceRead) { unsigned long nbyte; BOOLEAN bResult = FALSE; BULK_TRANSFER_CONTROL bulkControl; bulkControl.pipeNum = 2; DWORD IOCTL = IOCTL_EZUSB_BULK_READ; bResult = DeviceIoControl( hDeviceRead, IOCTL, &bulkControl, sizeof(BULK_TRANSFER_CONTROL), tptr, 30, &nbyte, NULL ); if(ReadEvent) SetEvent(ReadEvent); }
Why are you using a global char*? Global variables are bad because they cause unneeded program interdependency and needless coupling between modules. Consider spawning your thread with a const pointer to the calling thread, and encapsulate Get()/Set() fcns for the member data. And don't use char*! If you're using MFC, use CString, or std::string if you're not. You are truncating your data in the char* b'cos you aren't properly handling the size of the "string". ~Nitron.
ññòòïðïðB A
start -
Why are you using a global char*? Global variables are bad because they cause unneeded program interdependency and needless coupling between modules. Consider spawning your thread with a const pointer to the calling thread, and encapsulate Get()/Set() fcns for the member data. And don't use char*! If you're using MFC, use CString, or std::string if you're not. You are truncating your data in the char* b'cos you aren't properly handling the size of the "string". ~Nitron.
ññòòïðïðB A
start