SRL Archive - Help

.dll in c++ --> to Simba


bg5

2012-03-01 19:12:56

This is first time I make DLL ,so I'm green ,please be patient.

I read this:
http://villavu.com/forum/showthread.php?t=39677

and this:

http://rvelthuis.de/articles/articles-cppobjs.html

and made this in Dec-C++ :

http://pastebin.com/pBz3PbAi


Tried:

program new;
{$loadlib project2.dll}

begin
addC(2);
end.
[Error] (8:1): Unknown identifier 'addC' at line 7

What's wrong?

masterBB

2012-03-01 19:23:46

Don't you need that whole functioncount stuff etc?

http://villavu.com/forum/showthread.php?t=71883

function GetFunctionCount: integer; stdcall;
function GetFunctionInfo (x: Integer; var ProcAddr: Pointer; var ProcDef: PChar): integer; stdcall;
function GetFunctionCallingConv(x: integer): integer; stdcall;
function GetTypeCount: integer; stdcall;
function GetTypeInfo(x: Integer; var sType, sTypeDef: string): integer; stdcall;
procedure SetPluginMemManager(MemMgr : TMemoryManager); stdcall;

bg5

2012-03-01 20:01:49

From: masterBB
Don't you need that whole functioncount stuff etc?

http://villavu.com/forum/showthread.php?t=71883

function GetFunctionCount: integer; stdcall;
function GetFunctionInfo (x: Integer; var ProcAddr: Pointer; var ProcDef: PChar): integer; stdcall;
function GetFunctionCallingConv(x: integer): integer; stdcall;
function GetTypeCount: integer; stdcall;
function GetTypeInfo(x: Integer; var sType, sTypeDef: string): integer; stdcall;
procedure SetPluginMemManager(MemMgr : TMemoryManager); stdcall;


I don't know ,compiler makes .def file itself ,I can't change it ,because it will be overwritten. And it's looks like:
; dlltool --base-file C:\Users\user\AppData\Local\Temp/cca05276.base --output-exp Project2.exp --dllname Project2.dll --output-def libProject2.def --no-export-all-symbols --add-stdcall-alias --exclude-symbol=DllMainCRTStartup@12 --def C:\Users\user\AppData\Local\Temp/cca05276.def --output-lib libProject2.a
EXPORTS
addC@4 @ 1
addC = addC@4 @ 2

mormonman

2012-03-01 20:06:52

In the thread you posted from villavu read the section titled: "Exporting Functions"

bg5

2012-03-01 20:42:17

From: mormonman
In the thread you posted from villavu read the section titled: "Exporting Functions"


You mean this?
http://villavu.com/forum/showthread.php?t=39677
there is no such section.

masterBB

2012-03-02 21:45:53

Just look at these two files:

https://github.com/BenLand100/SMART/blob/master/src/libsmart.def

https://github.com/BenLand100/SMART/blob/master/src/Main.cpp

You will note that there is a deff file and that this is used to communicate with simba:

[PHP]#define NumExports 79

//STDCALL - SCAR/Simba
long GetFunctionCount() {
return NumExports;
}

//STDCALL - SCAR/Simba
long GetFunctionInfo(int index, void*& address, char*& def) {
if (index < NumExports) {
address = dlsym(RTLD_DEFAULT,exports[index*2]);
strcpy(def, exports[index*2+1]);
return index;
}
return -1;
}[/PHP]

Brandon

2012-03-02 21:53:52

No.. the .def file is the DLL definition file and it's only needed when you don't use _declspec(dllexport)..

he's just missing the simba requirements which is the function count and stuff..

masterBB

2012-03-02 21:57:03

From: ggzz
No.. the .def file is the DLL definition file and it's only needed when you don't use _declspec(dllexport)..

he's just missing the simba requirements which is the function count and stuff..


I've never came much farther with c++ than "hello world" ;) . Also it is hard to see what he was missing if the source of his dll is gone. Maybe we need a C++ plugin template? Cause I've searched a lot for this information.

KingKong

2012-03-02 23:28:24

Post the dll here, for some reason i cant access the pastebin. Also, did you use 'extern C' while exporting the func/proc anywhere in your code? Because c++ does name mangling unless you tell it not to.

bg5

2012-03-03 01:26:02

Well ,I added some stuff found in this thread:

http://villavu.com/forum/showthread.php?t=66021

.cpp:
http://pastebin.com/uQ7kwkMm

.h:
http://pastebin.com/M1tYYQXp

and:

program new;
{$loadlib Project2.dll}
begin
addc(1);
end.

Your DLL Project2.dll has not been found
Your DLL Project2.dll has not been found
Exception in Script: Unknown compiler directives at 3:3

Maybe we need a C++ plugin template?

That's great idea.

Also, did you use 'extern C' while exporting the func/proc anywhere in your code?


Yes,I did.

Brandon

2012-03-03 01:50:27

I think either we need an export table OR u need to compile with Mingw and that stupid .def file..

I don't think it'll work with codeblocks because codeblocks overwrites the .def file upon compiling and after a little reading, it seems u need it ={
AND since it's pascal types the compiler should have something called #PASCAL defined as __attribute(declspec) or something like that..

Also since it's being exported to pascal, I just read that u MUST provide the Symbolic/Mangled Name for the functions instead.. so.. cdecl or __stdcall should remove the _ from the symbolic name.. OR it could be a __fastcall? can't remember


DLL_EXPORT int __stdcall GetFunctionInfo(int x, void*& address, char*& def)
{
switch(x)
{
case 0:
address = (void*)GetProcAddress(hinstance, "_AddC@0"); //Cast to (Void*) Where it says _AddC@0 must be the symbolic name.. Found in the .def I think
strcpy(def ,"procedure AddC(I: Integer);"); //This is how pascal will call the function..
return x;
}
return -1;
}