I have a function which should return me text. This is the declaration:
typedef bool(WINAPI* GetMenuHelpName)(intptr_t dll, LPVOID lpBuffer, int size);
I suppose my text is in LpBuffer
:
GetMenuHelpName func2 = (GetMenuHelpName)GetProcAddress(hGetProcIDDLL, "GetMenuHelpName");
LPVOID lpBuffer;
func2(instance, lpBuffer, 2048);
I got this error:
Error C4700 : uninitialized local variable 'lpBuffer' used
How could I initialize lpBuffer
and put my result in a std:string
?
An LPVOID
type is exactly the same as void*
, which means a pointer to something which doesn't have a specific type. Also, as it stands right now, lpBuffer isn't pointing at anything because it has not been initialized. There are two main ways to initialize this pointer: on the heap or on the stack. To initalize on the stack, initialize it like a char
array:
char lpb[1000]; // Or however much space
LPVOID lpBuffer = (LPVOID) lpb;
To initialize on the heap, use the malloc
(memory allocation) function. This allocates some space somewhere and returns a pointer to it. Just remember to call free
on it when you're done to give that space back to the OS:
#include <stdlib.h> // malloc, free
// ...
LPVOID lpBuffer = malloc(1000); // pick your space
// ...
free(lpBuffer); // release the space
As for converting to a std::string
, see this page .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.