Hi, im haveing a rather strange problem and im not sure whats causing it. Im building myself a plugin type program, and c plugins(.dlls) seem to load fine, but when i try to convert them to cpp plugins one particular function fails.
here is the code for my "dummy" plugin.
dll.h
Code:
#ifndef _DLL_H_
#define _DLL_H_
#if BUILDING_DLL
# define DLLIMPORT __declspec (dllexport)
#else /* Not BUILDING_DLL */
# define DLLIMPORT __declspec (dllimport)
#endif /* Not BUILDING_DLL */
#include <windows.h>
#include <cstdlib>
#include <iostream>
///// DEFINE THE "REQUEST" FUNCTION WHICH IS USED TO RECIEVE THE FUNCTIONS FROM THE CORE AND OTHER MODULES
typedef int(*defaultFunc)();
typedef defaultFunc(*request)(char *, char *);
///// DEFINE FUNCTIONS THAT WE WANT TO USE
typedef void(*logMessage)(char*);
///// DEFINE DLL FUNCTIONS
DLLIMPORT char * getName();
DLLIMPORT int initialize(request _req);
#endif /* _DLL_H_ */
the only thing ive changed is the c includes to the cpp includes, but it didnt solve the problem
dllmain.cpp
Code:
/* Replace "dll.h" with the name of your header */
#include "dll.h"
///// MAKE A POINTER TO OUR FUNCTIONS
request _request;
logMessage _logMessage;
DLLIMPORT void doSomething()
{
_logMessage("Im a loaded DUMMY :D");
}
DLLIMPORT char * getName()
{
return("dummy");
}
///// THIS FUNCTION IS CALLED AUTOMATICALLY WHEN LOADED, AND THE POINTER TO REQUEST() IS PASSED TO IT
DLLIMPORT int initialize(request _req)
{
_request = _req; // NOW THE ADDRESS OF THE REQUEST FUNCTION IS STORED AND ANYTHING CAN USE IT
_logMessage = (void (*)(char*))_request("core", "logMessage"); //STORE THE ADDRESS OF LOG MESSAGE
doSomething();
}
BOOL APIENTRY DllMain (HINSTANCE hInst /* Library instance handle. */ ,
DWORD reason /* Reason this function is being called. */ ,
LPVOID reserved /* Not used. */ )
{
switch (reason)
{
case DLL_PROCESS_ATTACH:
break;
case DLL_PROCESS_DETACH:
break;
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
break;
}
/* Returns TRUE on success, FALSE on failure */
return TRUE;
}
and this is the code which loads a dll
Code:
int loadModule(wxString path)
{
const char * cpath = path.c_str();
HINSTANCE hInstLibrary = LoadLibrary(cpath);
if(hInstLibrary == NULL)
{
wxString output;
output.Printf("didnt Load:%d",GetLastError());
logMessage(output);
return 0;
}
logMessage(wxT("initdef"));
int (*initialize)(int(*(*)(char *, char *))()) = NULL;
logMessage(wxT("initeq"));
initialize = (int(*)(int(*(*)(char *, char *))()))GetProcAddress(hInstLibrary, "initialize");
logMessage(wxT("namedef"));
char * (*getName)() = NULL;
logMessage(wxT("nameeq"));
getName = (char*(*)())GetProcAddress(hInstLibrary, "getName");
logMessage(wxT("namecall"));
if(!modLog.findMod((*getName)()))
{
logMessage(wxT("initcall"));
(*initialize)(&request);
logMessage(wxT("namecall"));
modLog.addMod((*getName)(),hInstLibrary);
}
return 1;
}
its basically a fairly jumbled mess of function pointers, but it calls initialize() and getName() from the .dll. Using the c dll, this works perfectly, but fails using the cpp dll. The last successful call is the first logMessage(wxT("nameCall")), so it is the actual calling of the function which crashes the program.
EDIT: also i forgot to mention that the function pointer is still null, meaning that getProcAddress failed, and also last error is 127.
I pulled this off another forum with a similar problem, but ive got no clue what it means. Im using dev-cpp.
Code:
it means that it could not find the NtOpenSection() function in ntdll.dll. Procedure is basically the function in the dll. When you call GetProcAddress(handle,"NtOpenSection"), it means you ask Windows to search for the address of procedure ( GetProcAddress is Get Procedure Address ) NtOpenSection in the dll and return it if found.
Maybe, your version of ntdll.dll doesn't implement that.