lpvoid and structs
-
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 :)
-
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 :)
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
-
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 :)
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
-
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 :)
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 -
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 }
Dustinhi... 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 :)
-
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 :)
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