Got it to work!!!!!!!!!!! Haha!
I went about trying to understand the process of loading a library and running a function from it. My simplest example was:
testdllcall.cpp
Code: Select all
#include <iostream>
#include <windows.h>
typedef char* (__stdcall *pProtoFunc)(void);
void PrintErrCode(DWORD err)
{
// Translate ErrorCode to String.
LPTSTR Error = 0;
if(FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
err,
0,
(LPTSTR)&Error,
0,
NULL) == 0)
{
wprintf(L"Unable to translate error code");
}
wprintf(L"Error: %s\n",Error);
}
void CallLib(char* strbuf)
{
HINSTANCE DLLID = LoadLibrary(L"C:\\testdll.dll");
FARPROC ProcID = GetProcAddress(HMODULE(DLLID),"testfunction");
if (!ProcID)
{
PrintErrCode(GetLastError());
return;
}
pProtoFunc func;
func = pProtoFunc(ProcID);
memcpy(strbuf,func(),3);
FreeLibrary(DLLID);
}
int main()
{
char buf[3];
CallLib(buf);
std::cout<<buf<<std::endl;
std::system("pause");
return 0;
}
testdll.dll
Code: Select all
char* testfunction()
{
return "yo";
}
Running that would give me the same error "Specified procedure could not be found".
But then, I figured out if you change testdll.dll to this:
Code: Select all
#include <iostream>
extern "C" __declspec(dllexport) char* testfunction()
{
return "yo";
}
It got rid of the error and printed "yo"!
I did the same with my code for LOVE dll and it worked! The function was pushed onto the lua stack! A good day indeed.