Re[2]: Ошибка при отладке в Visual C++: Stack is corrupt
От: MasterDimon  
Дата: 23.12.04 10:52
Оценка:
Здравствуйте, tarkil, Вы писали:
T>Код в студию. Без него гадать можно долго...

//
// Write data from the host into device 
//
void CLibUsbTestDlg::OnBnClickedWriteDevice()
{
  CDeviceStruct* hDev; 

  int bytesCount = 0;          // bytes counter
  CString newStr = ""; 
  char cTemp, cLowHalfByte;    // for manipulating with characters
    
  CEdit* editField;
  TCHAR               theStr[MAX_STRING_LENGTH]="";
  ULONG               error = ERROR_SUCCESS;
  char*               outPattern;
  char                currentSymbol;  // for construct current byte
  POSM_WDM_LIST_ITEM  ioItem;         // structure for store temporary input-output data

  this->UpdateData(TRUE);       // update control's variables values
  CListBox* listWnd = (CListBox*)GetDlgItem(IDC_DEV_LIST);  // Get DeviceList string pointer
  
  // Get pointer to DeviceInfo structure
  hDev = (CDeviceStruct*)(listWnd->GetItemDataPtr(listWnd->GetCurSel()));  
  this->currentDevice = hDev->usbDevInfo;                   // Get Current USB-device Info structure

  ioItem = (POSM_WDM_LIST_ITEM)malloc(sizeof(OSM_WDM_LIST_ITEM));
  outPattern = (char*)calloc(outputDataSize, 1);            // initialy I used malloc()
  ioItem->OutSize = outputDataSize * outputDataQuantity;    // Number of bytes * multiplicity

  if(ioItem->OutSize > 0)   // if Output data size was defined
  {
    // allocate memory for buffering output data
    ioItem->OutBuffer = (char*)calloc(outputDataSize, outputDataQuantity);  // initialy I used malloc()
    if (ioItem->OutBuffer == NULL)
    {
      MessageBox("Failed to create write buffer", "Error", MB_OK);
      error = ERROR_OUTOFMEMORY;
    }

    // Preparing for write data into bulk pipe
    // Pack pares of symbols in one byte and copy that bytes to buffer
    for (int i = 0; i < outputData.GetLength(); i++)
    {
      strcpy(&currentSymbol, "");
      cTemp = outputData.GetAt(i);              // Get odd symbol
      (void)_stscanf(&cTemp, _T("%x"), &currentSymbol);   // to copying ih hex format

      if (i < outputData.GetLength()-1)                   // if symbol not a last in string
      {
        currentSymbol<<=4;                                // set high half-byte
        cLowHalfByte = outputData.GetAt(++i);             // get even symbol
        (void)_stscanf(&cLowHalfByte, _T("%x"), &cTemp);
        
        currentSymbol^=(cTemp&=0x0F);            // ...and set low half-byte of current byte
        CopyMemory(ioItem->OutBuffer+bytesCount, &currentSymbol, sizeof(currentSymbol));
      }
      else  // symbol is last
        CopyMemory(ioItem->OutBuffer+bytesCount, &currentSymbol, sizeof(currentSymbol));
      bytesCount++;
    }
    bytesCount=0;

    // Write into USB device's pipe-1
    for (int i = 0; i < outputDataQuantity; i++)
      bytesCount += usb_bulk_write(hDev->usbDevHandle, 1, ioItem->OutBuffer, outputDataSize, timeoutValue);

    // Indicate bytes sent count
    editField = (CEdit*)GetDlgItem(IDC_BYTES_SENT_EDIT);
    editField->SetWindowText(newStr);
    newStr.Format("%d", bytesCount);
    AddString(editField, newStr);

    // Free the ioItem memory
    free(outPattern);
    free(ioItem->OutBuffer);
    free(ioItem);
  }
}


Ругань происходит при выходе из метода на переменную currentSymbol. Если объявить её как член класса — то на предыдущие: cTemp, cLowHalfByte.
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.