View Full Version : .dll in c++ --> to Simba
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
03-02-2012, 12:23 AM
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;
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
In the thread you posted from villavu read the section titled: "Exporting Functions"
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
03-03-2012, 02:45 AM
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:
#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;
}
Brandon
03-03-2012, 02:53 AM
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
03-03-2012, 02:57 AM
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
03-03-2012, 04:28 AM
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.
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
03-03-2012, 06:50 AM
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;
}
Powered by vBulletin® Version 4.2.1 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.