return value when you don't know the size?

I'm getting in the habit of creating functions for things which I will use on a regular basis. How can I return this value when I don't know the size of it?

mylib.h
1
2
3
...
char getUser();
...


mylib.cpp
1
2
3
4
5
6
7
8
...
	char getUser() {
		char lpszUsername[255];
		DWORD dUsername = sizeof(lpszUsername);
		GetUserName(lpszUsername, &dUsername);
		return lpszUsername;
	}
...


I get the 'return value does not match function type' error for lpszUsername. I have this within a separate cpp file than the main and link with a header. I didn't include the entire files.
char lpszUsername[255]; is an array of chars, but char getUser(); returns only a char.

It would be much easier to return a string.
1
2
3
4
5
6
7
8
std::string getUser()
 {
	char lpszUsername[255];
	DWORD dUsername = sizeof(lpszUsername);
	GetUserName(lpszUsername, &dUsername);
	
       return std::string(lpszUsername);
}


Thomas1965 + 1
Topic archived. No new replies allowed.