Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Thread Problem

Thread Problem

Scheduled Pinned Locked Moved C / C++ / MFC
performancehelptutorial
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Caoimh
    wrote on last edited by
    #1

    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); }

    C N 2 Replies Last reply
    0
    • C Caoimh

      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); }

      C Offline
      C Offline
      Caoimh
      wrote on last edited by
      #2

      Please Take A Look

      1 Reply Last reply
      0
      • C Caoimh

        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); }

        N Offline
        N Offline
        Nitron
        wrote on last edited by
        #3

        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

        C 1 Reply Last reply
        0
        • N Nitron

          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

          C Offline
          C Offline
          Caoimh
          wrote on last edited by
          #4

          Thanks for replying to the message. Sorted the problem last night. A memory allocation problem. Used malloc to solve the problem.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups