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. lpvoid and structs

lpvoid and structs

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialquestion
6 Posts 4 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.
  • G Offline
    G Offline
    ginjikun
    wrote on last edited by
    #1

    hi! can someone give me a sample code on how to pass 2 different structs to a function with lpvoid as parameter and how to convert back to the structs from lpvoid. the structs should be received by the lpvoid... how to combine the 2 different structs together? and how to split the lpvoid back to the 2 structs? the structs are something like typedef struct { int dataStructCount; DWORD totalSize; } strHeader; typedef struct { int num; lptstr str; } dataStruct; the function to receive func(LPVOID data) { // get the structs from data } this will be used for writing and reading data from named pipe.. the header will be used to determine the count of dataStruct send/read. thanks for any help! newbie :)

    J D 3 Replies Last reply
    0
    • G ginjikun

      hi! can someone give me a sample code on how to pass 2 different structs to a function with lpvoid as parameter and how to convert back to the structs from lpvoid. the structs should be received by the lpvoid... how to combine the 2 different structs together? and how to split the lpvoid back to the 2 structs? the structs are something like typedef struct { int dataStructCount; DWORD totalSize; } strHeader; typedef struct { int num; lptstr str; } dataStruct; the function to receive func(LPVOID data) { // get the structs from data } this will be used for writing and reading data from named pipe.. the header will be used to determine the count of dataStruct send/read. thanks for any help! newbie :)

      J Offline
      J Offline
      John R Shaw
      wrote on last edited by
      #2

      I have not idea why you would want to do this but:

      void func(LPVOID data)
      {
      strHeader *pH = (strHeader*)data;
      dataStruct *pS = (datasStruct*)(data + sizeof(strHeader));
      }

      INTP "Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra

      1 Reply Last reply
      0
      • G ginjikun

        hi! can someone give me a sample code on how to pass 2 different structs to a function with lpvoid as parameter and how to convert back to the structs from lpvoid. the structs should be received by the lpvoid... how to combine the 2 different structs together? and how to split the lpvoid back to the 2 structs? the structs are something like typedef struct { int dataStructCount; DWORD totalSize; } strHeader; typedef struct { int num; lptstr str; } dataStruct; the function to receive func(LPVOID data) { // get the structs from data } this will be used for writing and reading data from named pipe.. the header will be used to determine the count of dataStruct send/read. thanks for any help! newbie :)

        J Offline
        J Offline
        John R Shaw
        wrote on last edited by
        #3

        A better way:

        typedef struct
        {
        strHeader sh;
        dataStruct dh;
        } myData;

        Void func( myData* md)
        {
        md->sh ….;
        md->dh….;
        }

        INTP "Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra

        1 Reply Last reply
        0
        • G ginjikun

          hi! can someone give me a sample code on how to pass 2 different structs to a function with lpvoid as parameter and how to convert back to the structs from lpvoid. the structs should be received by the lpvoid... how to combine the 2 different structs together? and how to split the lpvoid back to the 2 structs? the structs are something like typedef struct { int dataStructCount; DWORD totalSize; } strHeader; typedef struct { int num; lptstr str; } dataStruct; the function to receive func(LPVOID data) { // get the structs from data } this will be used for writing and reading data from named pipe.. the header will be used to determine the count of dataStruct send/read. thanks for any help! newbie :)

          D Offline
          D Offline
          d34studios
          wrote on last edited by
          #4

          Although I don't know exactly what you are trying to accomplish, I would think you would just want to overload the function with different parameters. For Example: void MyFunction(strHeader tStruct) { // Do Somehting } void MyFunction(dataStruct tStruct) { // Do Somehting } Dustin

          G 1 Reply Last reply
          0
          • D d34studios

            Although I don't know exactly what you are trying to accomplish, I would think you would just want to overload the function with different parameters. For Example: void MyFunction(strHeader tStruct) { // Do Somehting } void MyFunction(dataStruct tStruct) { // Do Somehting } Dustin

            G Offline
            G Offline
            ginjikun
            wrote on last edited by
            #5

            hi... thanks for the replies! :) the idea in having the structs header and data is because the receiving end of the pipe have no idea how many data structs will be sent... thus the header contains the count of data structs. it will be written on the pipe together (header and data) and will be read by the other end of the pipe... the problem i have is how to code it efficiently... :( i figured maybe i can just call readfile twice... read the header first and then the data.. since the header will also contain the size of the data struct sent.. for any better ideas pls do reply! thanks again! newbie :)

            M 1 Reply Last reply
            0
            • G ginjikun

              hi... thanks for the replies! :) the idea in having the structs header and data is because the receiving end of the pipe have no idea how many data structs will be sent... thus the header contains the count of data structs. it will be written on the pipe together (header and data) and will be read by the other end of the pipe... the problem i have is how to code it efficiently... :( i figured maybe i can just call readfile twice... read the header first and then the data.. since the header will also contain the size of the data struct sent.. for any better ideas pls do reply! thanks again! newbie :)

              M Offline
              M Offline
              Mark Salsbery
              wrote on last edited by
              #6

              ginjikun wrote:

              i figured maybe i can just call readfile twice... read the header first and then the data.. since the header will also contain the size of the data struct sent..

              Often, that's the only way to do it with pipes, sockets, etc. and a protocol that supports variable length data. Mark

              "Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder

              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