Originally posted by stovellp
I cannot change the definition of GetServerVariable(), and so I must make it work without changing the way the function looks to the client. Thats why I must find a way to make it work with an LPVOID rather than any other type of function.
One last try from my side. I think my memcpy suggestion was valid, so I'll give you an example. If it's not what you want... err, ya, 14 posts for nothing
Code:
#include <iostream>
#include <stdlib.h>
using namespace std;
const int g_iBufferSize= 100;
void vtemp(LPVOID pcBuffer, int *iSize) {
char szTemp[g_iBufferSize];
// fill szTemp with some junk
char *pcSomeJunk= "somejunk";
strncpy(szTemp, pcSomeJunk, *iSize);
// end of junk
// limit iSize as defined by ms spec
// min() is better, just don't know if it's standard
// strlen should better be cached
if (*iSize > strlen(pcSomeJunk))
*iSize= strlen(pcSomeJunk);
memcpy(pcBuffer, &szTemp, *iSize);
}
int main(int argc, char *argv[])
{
char szBuffer[100];
int iSize= sizeof(szBuffer);
vtemp(szBuffer, &iSize);
cout << szBuffer;
system("PAUSE");
return 0;
}
I'm not a fan of cstrings - they are slow like a snail and pose a great threat to application security. I hardly ever use them, which is the reason why the above code might be a prime example of insecure code. Better check it twice.
edit: I know, to use both strcpy and memcpy is somewhat redundant. This is only because I needed to supply some kind of data to fill the buffer and I don't know in what format your data is stored. In my above example you could even use strncpy to directly copy the string to a typecasted LPVOID pcBuffer (cast as (char *)). Ya.... err. Hope that somehow helps.