Bumping this old thread...
So I'm using this code:
Code:
#include <windows.h>
#define Export _declspec(dllexport)
#define DelphiExport extern "C" Export
HINSTANCE inst;
Export BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID checks) {
switch(reason) {
case DLL_PROCESS_ATTACH:
//Do you're init here, but don't change anything else (besides cleanup)
inst = instance;
case DLL_THREAD_ATTACH:
return true;
case DLL_PROCESS_DETACH:
//Do you're cleanup here, but don't change anything else (besides init)
FreeLibrary(inst);
case DLL_THREAD_DETACH:
return true;
}
return false;
}
//Add in your functions
void Test(void) {
//Shows a message box.
MessageBox(NULL, "Testing 1 2 3", "DLL", MB_OK);
}
//Export name changed in def file
DelphiExport int __stdcall GetFunctionCount(void) {
return 1; //Change depending on number to export
}
//Export name changed in def file
DelphiExport int __stdcall GetFunctionInfo(int x, void** address, char** def) {
switch (x) {
case 0:
*address = (void*)Test;
strcpy(*def,"procedure DllTest;"); //Have to strcpy, how you want it to be called
return x;
}
return -1;
}
Compiled with CodeBlocks.
Simba script:
Code:
program new;
{$loadlib test2}
begin
DllTest;
end.
However I get error that DllTest is undefined.
It also sometimes give "Your DLL test2 has not been found. Exception in Script: Unknown compiler directives at 4:3" errors.
Few things wasn't clear for me:
1. .def file has to be generated by compile or should I create it manually? And if my dll is test2.dll so this file should be test2.def?
2. How do I enable debugging to know what functions were exported?
Thanks.
EDIT: Nvm, fixed... I was unable to make Code::Blocks include .def file into dll so I used MinGW.