How do I interface D to a C library based on a DLL?

Christopher Grantham cgrantham at gmail.com
Wed Jun 13 21:50:43 PDT 2007


Thanks Frits and Hoenir,
Daniel Keep is helping me to translate the .h to .d files, I tried to 
get htod.exe working before, but it falls over when attempting to find 
'excpt.h' (which is right there in the lib sub-directory where htod was 
extracted...?), as for bcd, I'm downloading the prerequisites etc 
now...I'll give it a go and compare my manual translation against what 
bcd produces...

Carlos Santander wrote:
> Christopher Grantham escribió:
>> Interestingly, if I do this from the command line, I get this output:
>>
>> K:\Projects\SoftwareDev\Learn D\OrcFxAPITest\src>dmd -run ./test.d 
>> OrcFxAPI.d OrcFxAPI.lib
>> OPTLINK (R) for Win32 Release 7.50B1
>> Copyright (C) Digital Mars 1989 - 2001  All Rights Reserved
>>
>> C:\dmd\bin\..\lib\phobos.lib(dmain2)
>>  Error 42: Symbol Undefined _C_GetDLLVersion at 16
>> --- errorLevel 1
> 
> This looks like Windows naming convention. Can you try using extern(C) 
> instead of extern(Windows) wherever you define C_GetDLLVersion? Or you 
> could examine the contents of the .lib (lib -l) and see what symbols are 
> there.
> 
hmmm thats interesting:
 >lib -l OrcFxAPI.lib
Digital Mars Librarian Version 8.02n
Copyright (C) Digital Mars 2000-2007 All Rights Reserved
http://www.digitalmars.com/ctg/lib.html
Digital Mars Librarian complete.

So I guess my LIB file has no symbols...?
I tried this for the original lib file:

 >lib -l OrcFxAPI.lib
Digital Mars Librarian Version 8.02n
Copyright (C) Digital Mars 2000-2007 All Rights Reserved
http://www.digitalmars.com/ctg/lib.html

Error: COFF libraries not supported - Use COFF2OMF

Which is to be expected when using the non-D version of the LIB file I 
guess, so I examined them as text myself, the D version of the LIB file 
has the following references to the C_GetDLLVersion function (attached 
picture shows exact format, lots of other chars etc in between), in 
order of appearance:
C_GetDLLVersion
_C_GetDLLVersion
OrcFxAPI.dll
C_GetDLLVersion
C_GetDLLVersion at 16
_C_GetDLLVersion at 16
OrcFxAPI.dll
C_GetDLLVersion at 16

Searching through the M$ version of the .LIB file, I find the following 
symbols in relation to the function ([] indicates those square block 
characters):

_C_GetDLLVersion at 16[]__imp__C_GetDLLVersion at 16
_C_GetDLLVersion at 16[]
__imp__C_GetDLLVersion at 16
C_GetDLLVersion at 16[][].text
[][][]__imp__C_GetDLLVersion at 16[]__IMPORT_DESCRIPTOR_ORCFXAPI[]

Anyway, I think we're getting closer to the solution, thanks to everyone 
who has been helping so far, keep up the good work! :)

Thanks again.
Chris








-------------- next part --------------
A non-text attachment was scrubbed...
Name: D_LIB-version.PNG
Type: image/png
Size: 8484 bytes
Desc: not available
Url : http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20070614/25dae6dd/attachment-0001.png 


More information about the Digitalmars-d-learn mailing list