Converting C to D Header Issues

I am trying to translate MySql C 6.02 headers to D, but I am getting some weird crashes. I assume that I made some mistakes when translating structures or functions (I am not very good at C).

I used implib / system on libmysql.dll to create the lib file.

I could not get htod.exe to work. Using -hs (including system files) complained that it could not find system files.

Coffimplib.exe did not have the ability to add _ to exported internal names.

I could not find the free version of coff2omf.

mysql.d is a shell. I included the definition of C before each wrapped definition in simpler errors. The file includes the mysql dll and the converted libfile.

When compiling mytest_fails.d it crashes. mytest_works.d has only a statement, and this makes it work. Compiling mytest_works with -release also crashes.

I am using dmd 2.051

Download mytest.zip from share1t.com

Update: I also asked some questions regarding this in the D.learn newsgroup, but I don't think anyone went through the code.

+4
source share
1 answer

stdcall is a call to a Windows function call (very different from a C call convention). HTOD failed to flag multiple functions using extern (Windows) . This is normal, since the HTOD is not equipped for macro processing ( STDCALL is defined as a macro, I see this from the remaining comments in msyql.d).

The mysql.d file is updated here: http://dl.dropbox.com/u/9218759/mysql.d

Now you need the proper import library in OMF format. I would generally advise that you do not use the implicit for this. I had a few problems with this, and others reported problems using it. Using coffimplib is the way to go. But first, you need the COFF import library.

If you need it, the Mysql edition with the COFF import library can be downloaded here: http://dev.mysql.com/downloads/mirror.php?id=377977#mirrors (DLL libraries marked for Visual Studio usually come with COFF import libraries )

But I provide you with the translated COFF import library in OMF format here: http://dl.dropbox.com/u/9218759/libmysql.lib

I tried both of your test cases, and they both seem to be working fine now. In case of problems, try checking the translated header file (mysql.d) again, it is possible that I may have skipped to correctly specify all the calling conventions.

+5
source

Source: https://habr.com/ru/post/1342424/


All Articles