News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

passing a string array from c++ into a masm function that will be called by c++

Started by bobl, April 27, 2013, 10:51:15 PM

Previous topic - Next topic

japheth

Quote from: bobl on April 30, 2013, 07:27:27 PM
You're not joking but I suppose I'm asking for trouble doing what I'm trying to do with my limited understanding so it's sort of self-inflicted. Of the three options I'd prefer...the JWLink one
i.e. a while back it succeeded (in MichaelW's hands) on some gcc stuff where gcc's own failed
and since then I've always thought that when I get around to "doing" linkers...JWLink would be the one.
Perhaps it's about time now.

Please note that I did sort my suggestions, by ( assumed ) ascending level of difficulty.

jwlink has been placed as the last because I - vaguely - remember that Borland may use some proprietary interpretations of OMF records for its C++ compiler - jwlink might be unaware of such "extensions".

Hence my suggestion is: try option 1 first.


bobl

In searching the net to understand how compilation works I accidentally came across this
http://flap.mynetmemo.com/?p=19
which might make things easier...Borland Developer Studio 2006 doesn't sem to have implib (perhaps I didn't install it) but luckily C++ Builder 4 does.
I thought you used either a static link library OR a dll..I'm therefore seeking clarity re the command line and fact that both are in it at the same time i.e. is that essential if you only intend to use a lib on it's own or are you just creating a universal import library that serves both?

To build a project that uses the DLL you will need to generate a Borland
import library. BCB6 comes with a command line tool called implib that will
do this. Simply open a command promt window, change to the directory where
the DLL is located, and run the following command (assuming that the Borland
bin directory is on your path);

implib -a sqlite.lib sqlite.dll

The -a argument is required to generate the correct symbol names in the
import library.

Any advice appreciated.

Edit:
Oops...Is this the answer to my question. If yes what's a static link library i.e. is it an import library by another name?

For the former, an import library (.lib file) will be required

Vortex

Hi bobl,

Digital Mars is providing a tool to create OMF import libraries, implib.exe :

http://www.digitalmars.com/ctg/implib.html

You can visit this page to download the basic utilities package. It contains implib.exe

http://www.digitalmars.com/download/freecompiler.html

An example usage :

implib.exe kernel32.lib kernel32.def

bobl

Gosh Vortex that was a rapid response.
I've just re-read what Japeth said
>the Borland import libraries contain undecorated publics ( missing the '_'-prefix and the '@nn'-suffix ).
>1. create an OMF import library that contains decorations ( OW wlib or jwlib can do this )
Given this I suppose Borland's implib probably wouldn't decorate the import library so my reasoning seems false.
Thanks for the link...I'll check it out.
I also have JWLink to play with which seems to invoke the JWLib library manager to create import libraries...
with the right command line.

Vortex
Just came back to say...your first link offers a very good explanation of the process...Thank you very much.

bobl

It was very easy to create the import library for kernel32.lib with implib using kernel32.defs (there was no dll)
and I was hopeful that it would work because it was about 3X the size of the Borland one but...
unfortunately I'm still getting what I think are the same errors i.e.

Linker command line
  -Tpe -Gn -v -L"c:\program files\borland\bds\4.0\lib\debug";C:\my_delphi\my_cbuilder2006\proj4;"c:\program files\borland\bds\4.0\lib";"c:\program
  files\borland\bds\4.0\lib\obj";"c:\program files\borland\bds\4.0\lib\psdk";"c:\program files\borland\bds\4.0\Include\Indy9";"c:\program
  files\borland\bds\4.0\Lib\Indy9";"C:\Documents and Settings\me\My Documents\Borland Studio Projects\bpl" -j -x -LC:\my_delphi\my_cbuilder2006\proj4
  -GA"C:\my_delphi\my_cbuilder2006\proj4\vfs3C.tmp"="C:\my_delphi\my_cbuilder2006\proj4\Project1.res" c0x32.obj vcl.bpi rtl.bpi vclx.bpi dbrtl.bpi
  vcldb.bpi adortl.bpi dbxcds.bpi dbexpress.bpi vclib.bpi ibxpress.bpi xmlrtl.bpi vclactnband.bpi inet.bpi IntrawebDB_80_100.bpi Intraweb_80_100.bpi
  vclie.bpi inetdbbde.bpi inetdbxpress.bpi indy.bpi bcbsmp.bpi soaprtl.bpi dsnap.bpi bcbie.bpi bdertl.bpi teeui.bpi teedb.bpi tee.bpi vcldbx.bpi
  memmgr.lib sysinit.obj C:\my_delphi\my_cbuilder2006\proj4\Debug_Build\Unit1.obj
  C:\my_delphi\my_cbuilder2006\proj4\myomfdmasm.obj,C:\my_delphi\my_cbuilder2006\proj4\Debug_Build\Project1.exe,C:\my_delphi\my_cbuilder2006\proj4\Debug_Build\Project1.map,import32.lib
   C:\my_delphi\my_cbuilder2006\proj4\mas32_omfd.lib "C:\Program Files\Borland\BDS\4.0\lib\psdk\kernel32.lib" cp32mti.lib,,
  C:\my_delphi\my_cbuilder2006\proj4\vfs3C.tmp
[Linker Error] Error: Unresolved external '_GetStdHandle@4' referenced from C:\MY_DELPHI\MY_CBUILDER2006\PROJ4\MAS32_OMFD.LIB|stdout.obj
[Linker Error] Error: Unresolved external '_WriteFile@20' referenced from C:\MY_DELPHI\MY_CBUILDER2006\PROJ4\MAS32_OMFD.LIB|stdout.obj


Perhaps the def file isn't decorated and implib just uses what it's got without decoration

Vortex

Hi bobl,

You can download the attachment containing some decorared module definition files : kernel32,user32,gdi32,shell32,comctl32,comdlg32,advapi32 and msvcrt.def

Creating those def files with lib2def is easy :

QuoteMS COFF import library to module definition file converter V2.0
lib2def converts MS COFF import libraries to module definition files. lib2def accepts wildcards like *.lib

http://vortex.masmcode.com/files/lib2def21.zip

EDIT : You can remove the double quotes in the def files if implib complains about them.

bobl

Vortex
I've downloaded those and will try them when I get back tonight.
Thank you for your kindness in providing them.
It's very much appreciated!

bobl

Well things have certainly moved on...
I created the import library i.e. kernel32.lib...
using Vortex's decorated kernel32.def in conjunction with the Digital Mars implib.exe command line

"implib /s kernel32.lib kernel32.dll"

I now get a message box entitled...

"Project1.exe...Entry point not found"
with the message...
"The procedure entry point _GetStdHandle@4 could not be located in the dynamic link library KERNEL32." 

That looks like progress but I'm not sure what to do in response to the message.
Also I have 3 such DLLs ie. in...
c:\WINDOWS\system32
c:\WINDOWS\ServicePackFiles\i386 &
C:\WINDOWS\$NtServicePackUninstall$

BTW I did try to create the import library using the DLL in \system32 but that just gave me the old errors
i.e. only Vortex's decorated def file got me this far.

Any advice much appreciated.

Vortex

Hi bobl,

implib /s kernel32.lib kernel32.dll

This looks incorrect.

implib kernel32.lib kernel32.def

The symbols in the def files have already a leading uderscore so need of the option /s

japheth

I did a test of my own, which I will describe in detail below:

1. I just installed the C++-builder command line tools - this is rather old stuff, AFAICS, they're installed by running freecommandlinetools.exe and the result is a directory C:\bcc55 with various sub-directories that contain the compiler, linker ( ilink32.exe ),, an implib.exe tool and finally include files and libraries ( import32.lib contains the undecorated Win32 imports, but isn't needed here ).

2. I wrote a small assembly test file (test.asm), assembled with masm/jwasm, output format OMF:


.386
.Model flat, stdcall
option casemap:none

GetStdHandle proto :dword
WriteFile proto :dword, :dword, :dword, :dword, :dword
ExitProcess  proto :dword

.code

szHello db "abc",13,10

main proc c
local dwWritten:dword
invoke GetStdHandle, -11
mov ebx, eax
invoke WriteFile, ebx, addr szHello, sizeof szHello, addr dwWritten, 0
invoke ExitProcess, 0
main endp

end main


3.  I created an import library with this kernel32.DEF file:


library kernel32

exports
_ExitProcess@4
_GetStdHandle@4
_WriteFile@20


to create it, I run:

implib kernel32.lib kernel32.def

4. finally linked the object module with:

ilink32 test.obj kernel32.lib


and the resulting binary test.exe runs fine.

Vortex

It looks like that Borland's linker cannot interpret corectly the import libraries created by Digital Mars' implib.exe

bobl

Vortex, Japeth
I'm very grateful for your advice and help and will try to do your suggestions justice.
Vortex...I'll try your decorated def file with the implib that Japeth has suggested and if that doesn't work with the implib that's in BCB4 that I have.
Thanks for bearing with me

bobl

SUCCCCCCCCCESS! with the first combination
i.e. Vortex's decorated kernel32.def + Japeth's recommendation re implib.exe and associated command line.
I REALLY appreciate your help in cracking this. Thank you!

>It looks like that Borland's linker cannot interpret corectly the import libraries created by Digital Mars' implib.exe
spot on!