int main() { HINSTANCE hGetProcIDDLL = LoadLibrary("test.dll"); if (!hGetProcIDDLL) {…
- User
int main() { HINSTANCE hGetProcIDDLL = LoadLibrary("test.dll"); if (!hGetProcIDDLL) { std::cout << "could not load the dynamic library" << std::endl; return EXIT_FAILURE; } f_funci funci = (f_funci)GetProcAddress(hGetProcIDDLL, "funci"); if (!funci) { std::cout << "could not locate the function" << std::endl; return EXIT_FAILURE; } std::cout << "funci() returned " << funci() << std::endl;
codereturn EXIT_SUCCESS;} argument of type "const char *" is incompatible with parameter of type "LPCWSTR"
- Assistant
To fix the error, you need to convert the string literal from "const char*" to "LPCWSTR". Here's an updated version of the code:
cpp#include <iostream> #include <Windows.h> int main() { HINSTANCE hGetProcIDDLL = LoadLibrary(L"test.dll"); if (!hGetProcIDDLL) { std::cout << "could not load the dynamic library" << std::endl; return EXIT_FAILURE; } f_funci funci = (f_funci)GetProcAddress(hGetProcIDDLL, "funci"); if (!funci) { std::cout << "could not locate the function" << std::endl; return EXIT_FAILURE; } std::cout << "funci() returned " << funci() << std::endl; return EXIT_SUCCESS; }Here, the "LoadLibrary" function expects a wide-string (LPCWSTR) as the parameter, so we prefix the string literal with "L" to make it a wide-string.