Replies: 15 comments 1 reply
-
It should be
The default here is |
Beta Was this translation helpful? Give feedback.
-
The implementation seems to follow the definition here so I'm not sure what to make of this.
I will assume this apply to all versions of Asmc so I think it's better to just leave it as it is, and update the documentation for the switches. |
Beta Was this translation helpful? Give feedback.
-
I will assume PB needs to interact with Windows API calls in order to produce a Windows application (it sort-of have to), which means there's a method to define external calling conventions (STDCALL in this case) within PB. As for using dll's are there any difference between BASIC and PB in that regard? If the only difference is that PB is case sensitive and BASIC is not, this could easily be fixed. Have you tried using If this don't work you may test the above assumption by adding these changes to mangle.asm from:
to:
|
Beta Was this translation helpful? Give feedback.
-
Seems the standard calling convention for PB is STDCALL. |
Beta Was this translation helpful? Give feedback.
-
It could be that the actual problem here is the creation of the library from the DLL. As the decoration can't be extracted from the DLL the DEF file needs to be written manually. If you look at how the system libraries are created in 64-bit the function names are simply extracted from the DLL, but the 32-bit version needs a decorated name list. I use a simple program that loads the 32-bit DLL, extract the undecorated names and scan the function for the RET statement. In STDCALL this will coded as 0xC2 (RET) followed by a WORD indicating the number of bytes returned.
This may not work for all functions so you still need to edit the DEF file to match the prototypes. |
Beta Was this translation helpful? Give feedback.
-
PB´s calling convention is like STDCALL but without decoration, so "... proto BASIC ..." should do. The problem is in fact creating an import library for the linker (PB doesn´t need import libraries nor does it create import libraries for dlls). I use a similar approach like you suggested to create a .def file from a PB dll with undecorated names, but then MS lib.exe adds a leading underscore to the procedure names in the import library. Therefore "... proto BASIC ..." doesn´t work, because the linker cannot resolve it: "myproc" vs. "_myproc". And i couldn´t find a way of creating an import library with procedure names without a leading underscore. There seems to be no appropriate option for lib.exe. But finally i found a lib tool, which can optionally create import libraries without those offending leading underscores. Initial tests show, that these import libraries work with "... proto BASIC ....". This seems to solve my problem - no need to add/change code in asmc Thanks JK |
Beta Was this translation helpful? Give feedback.
-
BASIC push arguments in the opposite direction (like PASCAL) so that will fail (with arg-cout > 1). I also think the assumption about decoration is wrong as this will not be exported to the DLL. This means the calling convention is STDCALL with standard decoration in OBJ and LIB files but without decoration in the DLL. It's possible to test this logic by linking directly to the PB DLL file (using the -pe switch).
Yes, that would be helpful. |
Beta Was this translation helpful? Give feedback.
-
my bad, i think you are right, "BASIC" pushes arguments in wrong order. I think i already have been there som time ago, therefore as a last resort, i tried tweaking asmc. here is my test code
and as an attachment the called PB dll and two versions of an import library The "nounderscore" version works with "BASIC", but caption and test get mixed up, the "underscore" version works with "C", but oviously the stack is not correct after the procedure returns. "testme" calls MessageBoxA and returns -1 |
Beta Was this translation helpful? Give feedback.
-
A bit puzzled by the whole lib-creating thing here, but whatever is in the DLL file works as follows:
Point is, it should work if you use STDCALL. pb_dll.def:
pb_dll.dll:
LINK will not add any decoration here so now you may access the external function as follow:
This will now work directly using the DLL:
Or indirectly using the import library
|
Beta Was this translation helpful? Give feedback.
-
To build the DLL and import library using LINKW and LIBW the switch
|
Beta Was this translation helpful? Give feedback.
-
Creating dlls and invoking exported procedures with asmc isn´t a problem, this works like a charm. The problem here is, PB doesn´t create .obj files, it creates the final dlls and i have absolutely no influence on the linking process. PB is a compiler and linker all in one. I can take dlls from PB only as they are. The next problem is, PB doesn´t create import libraries, in fact PB doesn´t need import libraries at all. It´s linker can link to whatever dll without a .lib file. So i must take those dlls as they are, and i must create my own .lib (import library) from such a dll somehow. I´m going to try your approch for creating a .def file with decorated names, all it takes is getting the x from "ret x", then i could create a .lib file, which makes STDCALL linking possible. I´m going to try this and report about the results |
Beta Was this translation helpful? Give feedback.
-
Same as the Asmc built-in linker (-pe).
It is sort of the same problem with the tools used here (LIB[W] and LINK[W]). It works fine when a DLL is created as the linker then knows the type of the exported functions and handle the import library accordingly. The problem occur when a DEF file is used as the type is then unknown. This is however exclusively a 32-bit STDCALL problem.
You will need a header file for these functions anyway so it may be more convenient to do that first. The linker within Asmc needs to know the name of the DLL for each function:
Otherwise (with a linker and import library) the INLUDELIB directive is used. The .pragma directive sort this out based on the link switch (-pe).
Well, the point is that it may be simpler to just copy the prototypes to an ASM file (with the same name as the DLL) and just build a dummy DLL.
Build the dummy:
LINK will now produce a (dummy) DLL and LIB file: no DEF file needed. |
Beta Was this translation helpful? Give feedback.
-
How could i create a .lib file from a .def file using LIBW? I need a sample commandline for this. Ok - there is some basic documentation, if you just run it, but where to find a more comprehensive documentation with more explanations and samples? The same applies to LINKW - seems capable, but very hard to find out how it works ... |
Beta Was this translation helpful? Give feedback.
-
Same as the sample above by moving the
LINKW/LIBW is used for most things here: Libraries, imports, applications and tests. The system configuration used are defined in the linkw.cfg file and some more details in the Open Watcom Linker User's Guide. |
Beta Was this translation helpful? Give feedback.
-
Thanks! |
Beta Was this translation helpful? Give feedback.
-
Hi Nidud,
would it be possible to add another calling convention for PowerBasic dlls?
I couldn´t find a combination of calling convention and switches, which makes the linker happy. PowerBasic´s calling convention is like standard call but without decorated names, or like C, but without caller stack cleanup. PowerBasic exports blank names, stack is filled from right to left and procedures cleanup the stack before returning.
So i tried to add this kind of convention to asmc by modifying and adding code and indeed i got it working. I could supply the modified sources, Unfortunately these sources are from an older version. I see you made changes, fixes and additions in the meantime, so it´s not possible to use a simple diff tool. PowerBasis is 32 bit only and doesn´t use .lib files, but it is possible to create a .lib file from a dll, i could supply such a dll and lib for testing on your own.
... seems i cannot edit the title anymore - should of course have been "... calling ..."
Beta Was this translation helpful? Give feedback.
All reactions