Desidero sviluppare un sistema di plugin utilizzando LoadLibrary.
Il mio problema è: voglio che la mia funzione prenda un const char*
e LoadLibrary
prende uno LPCTSTR
.
Ho avuto l'idea brillante da fare (LPCSTR)path
che continuava a darmi un errore di modulo non trovato.
Il codice attuale è di seguito. Se disattivi la riga widepath = L..
, funziona correttamente. Ho letto le soluzioni usando MFC ma non vorrei usare MFC.LoadLibrary taking a LPCTSTR
codice attuale:
bool PluginLoader::Load(char *path)
{
path = "Release\\ExamplePlugin.dll";
LPCTSTR widepath = (LPCTSTR)path;
//widepath = L"Release\\ExamplePlugin.dll";
HMODULE handle = LoadLibrary(widepath);
if (handle == 0)
{
printf("Path: %s\n",widepath);
printf("Error code: %d\n", GetLastError());
return false;
}
int (*load_callback)() = (int (*)()) GetProcAddress(handle, "[email protected]");
if (load_callback == 0)
{
return false;
}
return load_callback() == LOAD_SUCCESS;
}
Gah. grazie, mi sento ritardato ma a mia difesa, aggiungere un A non è così intuitivo. – Ben
Ecco perché questo sito web esiste, copre l'intuitivo ;-) –