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. Managed C++/CLI
  4. struct and lpvoid

struct and lpvoid

Scheduled Pinned Locked Moved Managed C++/CLI
helptutorialquestion
3 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.
  • 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; 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 :)

    G 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; 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 :)

      G Offline
      G Offline
      George L Jackson
      wrote on last edited by
      #2

      Newbie, First of all, you are in the wrong forum! This is the C++/CLI or Managed C++ forum. C++/CLI uses the .NET Framework and depends on Garbage Collection (GC) for memory management. It appears you are writing C or possibly C++ code. You should get better assistance int the Visual C++/MFC forum. However, LPVOID is really a typedef of void*. Thus, LPVOID is a pointer to any type. Unfortunately, once a pointer of a type, in your case strHeader and dataStruct, is casted to a void pointer, LPVOID, its type information is lost. Thus, if you have a function that accepts void pointers, the compiler will not help you with type checking.void Foo(LPVOID header, LPVOID data) { strHeader* theHeader = (strHeader*) header; dataStruct* theData = (dataStruct*) data;   // Do something with the data }   int main() { strHeader header; dataStruct data;   Foo(&strHeader, &dataStruct);   // Rest of application ...   return 0; }

      "We make a living by what we get, we make a life by what we give." --Winston Churchill

      G 1 Reply Last reply
      0
      • G George L Jackson

        Newbie, First of all, you are in the wrong forum! This is the C++/CLI or Managed C++ forum. C++/CLI uses the .NET Framework and depends on Garbage Collection (GC) for memory management. It appears you are writing C or possibly C++ code. You should get better assistance int the Visual C++/MFC forum. However, LPVOID is really a typedef of void*. Thus, LPVOID is a pointer to any type. Unfortunately, once a pointer of a type, in your case strHeader and dataStruct, is casted to a void pointer, LPVOID, its type information is lost. Thus, if you have a function that accepts void pointers, the compiler will not help you with type checking.void Foo(LPVOID header, LPVOID data) { strHeader* theHeader = (strHeader*) header; dataStruct* theData = (dataStruct*) data;   // Do something with the data }   int main() { strHeader header; dataStruct data;   Foo(&strHeader, &dataStruct);   // Rest of application ...   return 0; }

        "We make a living by what we get, we make a life by what we give." --Winston Churchill

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

        oooopppss! sorry! i did not notice the message board... i thought i was posting in vc++/mfc forum... i have reposted the qxn there... thanks for your reply! however, for the foo function... i only have 1 LPVOID paramter... thus the strHeader and dataStruct should be combined together and passed as 1 data to function Foo.... :( newbie :)

        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