www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - How do I interface D to a C library based on a DLL?

reply Christopher Grantham <cgrantham gmail.com> writes:
Hi,
     I'm very new to D, I have worked with other typical languages 
previously (C, C++, Java etc) and have some familiarity with .NET 
(mainly Visual C++), I need to use a C API in the form of a DLL for my 
uni work (research) and would like to try some experiments in D (I hate 
VC++ - IJW & M$ interop be damned!), I have the interface (.h), .LIB and 
.OBJ files as well as the DLL itself, but I'm not sure how to go about 
using/Linking the API in D, I've used it in VS.NET (VC++) but want to 
get away from it and use D if possible.
The DLL is closed source/proprietary so I can only edit the interface; 
I've read the 'Converting C .h files to D Modules' 
(http://www.digitalmars.com/d/htomodule.html), 'Writing Win32 DLLs in 
D'(http://www.digitalmars.com/d/dll.html), 'Converting C .h Files to D 
Modules' (http://www.digitalmars.com/d/htomodule.html), and 'Interfacing 
to C' (http://www.digitalmars.com/d/interfaceToC.html), however it isn't 
clear from these articles (at least to a n00b like myself) how I can use 
this C interfaced DLL in D code.
So far I've tried converting the header to D (manually), which hasn't 
worked (I get error: 138 data corruption), I think I should be able to 
interface directly to the C code, but am not confident.
If someone could assist/explain how to get D code working with a C 
interface from a DLL, then I'd be most grateful.

Thanks in advance.
Chris.
Jun 12 2007
next sibling parent reply torhu <fake address.dude> writes:
Christopher Grantham wrote:
 Hi,
      I'm very new to D, I have worked with other typical languages 
 previously (C, C++, Java etc) and have some familiarity with .NET 
 (mainly Visual C++), I need to use a C API in the form of a DLL for my 
 uni work (research) and would like to try some experiments in D (I hate 
 VC++ - IJW & M$ interop be damned!), I have the interface (.h), .LIB and 
 .OBJ files as well as the DLL itself, but I'm not sure how to go about 
 using/Linking the API in D, I've used it in VS.NET (VC++) but want to 
 get away from it and use D if possible.
 The DLL is closed source/proprietary so I can only edit the interface; 
 I've read the 'Converting C .h files to D Modules' 
 (http://www.digitalmars.com/d/htomodule.html), 'Writing Win32 DLLs in 
 D'(http://www.digitalmars.com/d/dll.html), 'Converting C .h Files to D 
 Modules' (http://www.digitalmars.com/d/htomodule.html), and 'Interfacing 
 to C' (http://www.digitalmars.com/d/interfaceToC.html), however it isn't 
 clear from these articles (at least to a n00b like myself) how I can use 
 this C interfaced DLL in D code.
 So far I've tried converting the header to D (manually), which hasn't 
 worked (I get error: 138 data corruption), I think I should be able to 
 interface directly to the C code, but am not confident.
 If someone could assist/explain how to get D code working with a C 
 interface from a DLL, then I'd be most grateful.
It would be nice to know what you did when you got that error. But in case you got it when trying to link with a lib file meant for a different linker, I'll explain how to get one that works with dmd. Download: ftp://ftp.digitalmars.com/bup.zip In that zip, you'll find implib.exe. It creates dmd-compatible import libs, based on DLL files. implib /s thelib.lib thedll.dll 'thedll.lib' is the output, so move the lib file you've got somewhere else first. Try linking with that file, if that's what you were doing.
Jun 12 2007
parent reply Christopher Grantham <cgrantham gmail.com> writes:
torhu wrote:
 Christopher Grantham wrote:
 Hi,
      I'm very new to D, I have worked with other typical languages 
 previously (C, C++, Java etc) and have some familiarity with .NET 
 (mainly Visual C++), I need to use a C API in the form of a DLL for my 
 uni work (research) and would like to try some experiments in D (I 
 hate VC++ - IJW & M$ interop be damned!), I have the interface (.h), 
 .LIB and .OBJ files as well as the DLL itself, but I'm not sure how to 
 go about using/Linking the API in D, I've used it in VS.NET (VC++) but 
 want to get away from it and use D if possible.
 The DLL is closed source/proprietary so I can only edit the interface; 
 I've read the 'Converting C .h files to D Modules' 
 (http://www.digitalmars.com/d/htomodule.html), 'Writing Win32 DLLs in 
 D'(http://www.digitalmars.com/d/dll.html), 'Converting C .h Files to D 
 Modules' (http://www.digitalmars.com/d/htomodule.html), and 
 'Interfacing to C' (http://www.digitalmars.com/d/interfaceToC.html), 
 however it isn't clear from these articles (at least to a n00b like 
 myself) how I can use this C interfaced DLL in D code.
 So far I've tried converting the header to D (manually), which hasn't 
 worked (I get error: 138 data corruption), I think I should be able to 
 interface directly to the C code, but am not confident.
 If someone could assist/explain how to get D code working with a C 
 interface from a DLL, then I'd be most grateful.
It would be nice to know what you did when you got that error. But in case you got it when trying to link with a lib file meant for a different linker, I'll explain how to get one that works with dmd. Download: ftp://ftp.digitalmars.com/bup.zip In that zip, you'll find implib.exe. It creates dmd-compatible import libs, based on DLL files. implib /s thelib.lib thedll.dll 'thedll.lib' is the output, so move the lib file you've got somewhere else first. Try linking with that file, if that's what you were doing.
Thanks for that :), when I get the error I mentioned, I was attempting to convert the C interface (.h) file to a D module like in the article I mentioned, I was attempting to build it in Eclipse which gave the following output: project "/OrcfxAPITest" build started, configuration=default compiling... C:\dmd\bin\dmd.exe -c -odbin/default src\test.d src\OrcFxAPI.d -IC:\dmd\src\phobos\ linking... C:\dm\bin\link.exe bin\default\test.obj src\OrcFxGUI.obj bin\default\OrcFxAPI.obj ,bin\OrcfxAPITest.EXE,bin\OrcfxAPITest.map,C:\dmd\lib\ ,,, OPTLINK (R) for Win32 Release 7.50B1 Copyright (C) Digital Mars 1989 - 2001 All Rights Reserved src\OrcFxGUI.obj Offset 00000H Record Type 004C Error 138: Module or Dictionary corrupt project "/OrcfxAPITest" build finished As for your suggestion, I downloaded implib, generated the new .lib file without any problems, moved the original out of the way and tried to build everything in Eclipse, if I use the '.d' file I created by converting the header, and try to import it as a module I get the following (warning, its a bit long): project "/OrcfxAPITest" build started, configuration=default compiling... C:\dmd\bin\dmd.exe -c -odbin/default src\test.d src\OrcFxAPI.d -IC:\dmd\src\phobos\ linking... C:\dm\bin\link.exe bin\default\test.obj src\OrcFxApi.obj bin\default\OrcFxAPI.obj ,bin\OrcfxAPITest.EXE,bin\OrcfxAPITest.map,C:\dmd\lib\ ,,, OPTLINK (R) for Win32 Release 7.50B1 Copyright (C) Digital Mars 1989 - 2001 All Rights Reserved bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 000DDH Record Type 0091 Error 1: Previous Definition Different : _stUserDefinedError bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 000EDH Record Type 0091 Error 1: Previous Definition Different : _otGeneral bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 00101H Record Type 0091 Error 1: Previous Definition Different : _otEnvironment bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 00110H Record Type 0091 Error 1: Previous Definition Different : _otVessel bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 0011DH Record Type 0091 Error 1: Previous Definition Different : _otLine bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 0012CH Record Type 0091 Error 1: Previous Definition Different : _ot6DBuoy bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 00141H Record Type 0091 Error 1: Previous Definition Different : _ot3DBuoy bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 0014FH Record Type 0091 Error 1: Previous Definition Different : _otWinch bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 0015CH Record Type 0091 Error 1: Previous Definition Different : _otLink bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 0016AH Record Type 0091 Error 1: Previous Definition Different : _otShape bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 0017CH Record Type 0091 Error 1: Previous Definition Different : _otDragChain bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 0018DH Record Type 0091 Error 1: Previous Definition Different : _otLineType bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 0019FH Record Type 0091 Error 1: Previous Definition Different : _otClumpType bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 001B6H Record Type 0091 Error 1: Previous Definition Different : _otWingType bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 001C9H Record Type 0091 Error 1: Previous Definition Different : _otVesselType bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 001DFH Record Type 0091 Error 1: Previous Definition Different : _otDragChainType bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 001F5H Record Type 0091 Error 1: Previous Definition Different : _otFlexJointType bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 00207H Record Type 0091 Error 1: Previous Definition Different : _otFlexJoint bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 0021CH Record Type 0091 Error 1: Previous Definition Different : _otAttachedBuoy bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 00237H Record Type 0091 Error 1: Previous Definition Different : _otBrowserGroup bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 0024FH Record Type 0091 Error 1: Previous Definition Different : _otDragCoefficient bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 00266H Record Type 0091 Error 1: Previous Definition Different : _otAxialStiffness bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 0027FH Record Type 0091 Error 1: Previous Definition Different : _otBendingStiffness bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 002A2H Record Type 0091 Error 1: Previous Definition Different : _otBendingConnectionStiffness bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 002C0H Record Type 0091 Error 1: Previous Definition Different : _otWingOrientation bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 002DBH Record Type 0091 Error 1: Previous Definition Different : _otKinematicViscosity bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 002F4H Record Type 0091 Error 1: Previous Definition Different : _otFluidTemperature bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 00309H Record Type 0091 Error 1: Previous Definition Different : _otCurrentSpeed bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 00322H Record Type 0091 Error 1: Previous Definition Different : _otCurrentDirection bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 00341H Record Type 0091 Error 1: Previous Definition Different : _otExternalFunction bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 00363H Record Type 0091 Error 1: Previous Definition Different : _otHorizontalVariationFactor bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 00375H Record Type 0091 Error 1: Previous Definition Different : _otLoadForce bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 00388H Record Type 0091 Error 1: Previous Definition Different : _otLoadMoment bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 003A0H Record Type 0091 Error 1: Previous Definition Different : _otExpansionFactor bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 003BEH Record Type 0091 Error 1: Previous Definition Different : _otWinchPayoutRate bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 003D3H Record Type 0091 Error 1: Previous Definition Different : _otWinchTension bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 003F3H Record Type 0091 Error 1: Previous Definition Different : _otVerticalVariationFactor bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 0040EH Record Type 0091 Error 1: Previous Definition Different : _otTorsionalStiffness bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 0042EH Record Type 0091 Error 1: Previous Definition Different : _otMinimumBendRadius bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 00443H Record Type 0091 Error 1: Previous Definition Different : _vdnWingAzimuth bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 0045CH Record Type 0091 Error 1: Previous Definition Different : _vdnWingDeclination bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 0046FH Record Type 0091 Error 1: Previous Definition Different : _vdnWingGamma bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 0048CH Record Type 0091 Error 1: Previous Definition Different : _vdnGlobalAppliedForceX bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 004AFH Record Type 0091 Error 1: Previous Definition Different : _vdnGlobalAppliedForceY bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 004CCH Record Type 0091 Error 1: Previous Definition Different : _vdnGlobalAppliedForceZ bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 004EAH Record Type 0091 Error 1: Previous Definition Different : _vdnGlobalAppliedMomentX bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 00508H Record Type 0091 Error 1: Previous Definition Different : _vdnGlobalAppliedMomentY bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 0052CH Record Type 0091 Error 1: Previous Definition Different : _vdnGlobalAppliedMomentZ bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 00548H Record Type 0091 Error 1: Previous Definition Different : _vdnLocalAppliedForceX bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 00564H Record Type 0091 Error 1: Previous Definition Different : _vdnLocalAppliedForceY bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 00580H Record Type 0091 Error 1: Previous Definition Different : _vdnLocalAppliedForceZ bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 005A3H Record Type 0091 Error 1: Previous Definition Different : _vdnLocalAppliedMomentX bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 005C0H Record Type 0091 Error 1: Previous Definition Different : _vdnLocalAppliedMomentY bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 005DDH Record Type 0091 Error 1: Previous Definition Different : _vdnLocalAppliedMomentZ bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 005F6H Record Type 0091 Error 1: Previous Definition Different : _vdnRefCurrentSpeed bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 00619H Record Type 0091 Error 1: Previous Definition Different : _vdnRefCurrentDirection bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 00639H Record Type 0091 Error 1: Previous Definition Different : _vdnWholeSimulationTension bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 0065CH Record Type 0091 Error 1: Previous Definition Different : _vdnWholeSimulationPayoutRate bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 00674H Record Type 0091 Error 1: Previous Definition Different : _vdnXBendStiffness bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 00691H Record Type 0091 Error 1: Previous Definition Different : _vdnXBendMomentIn bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 006A8H Record Type 0091 Error 1: Previous Definition Different : _vdnYBendMomentIn bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 006C0H Record Type 0091 Error 1: Previous Definition Different : _vdnXBendMomentOut bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 006D8H Record Type 0091 Error 1: Previous Definition Different : _vdnYBendMomentOut bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 006F3H Record Type 0091 Error 1: Previous Definition Different : _moduleDynamics bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 00709H Record Type 0091 Error 1: Previous Definition Different : _moduleVIV bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 00786H Record Type 0091 Error 1: Previous Definition Different : _pnBuildUp bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 0081BH Record Type 0091 Error 1: Previous Definition Different : _D8OrcFxAPI6Period6__initZ bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 00841H Record Type 0091 Error 1: Previous Definition Different : _D8OrcFxAPI11ObjectExtra6__initZ bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 00868H Record Type 0091 Error 1: Previous Definition Different : _D8OrcFxAPI12ObjectExtra26__initZ bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 0087BH Record Type 0091 Error 1: Previous Definition Different : _ptEndA bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 0088EH Record Type 0091 Error 1: Previous Definition Different : _ptEndB bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 008A0H Record Type 0091 Error 1: Previous Definition Different : _ptTouchdown bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 008B0H Record Type 0091 Error 1: Previous Definition Different : _ptNodeNum bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 008C2H Record Type 0091 Error 1: Previous Definition Different : _ptArcLength bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 008D6H Record Type 0091 Error 1: Previous Definition Different : _rpInner bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 008EAH Record Type 0091 Error 1: Previous Definition Different : _rpOuter bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 008FDH Record Type 0091 Error 1: Previous Definition Different : _dtreal bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 00913H Record Type 0091 Error 1: Previous Definition Different : _dtInteger bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 00922H Record Type 0091 Error 1: Previous Definition Different : _dtString bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 00933H Record Type 0091 Error 1: Previous Definition Different : _dtVariable bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 0094DH Record Type 0091 Error 1: Previous Definition Different : _rtTimeHistory bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 00966H Record Type 0091 Error 1: Previous Definition Different : _rtRangeGraph bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 0097FH Record Type 0091 Error 1: Previous Definition Different : _rtLinkedStatistics bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 00993H Record Type 0091 Error 1: Previous Definition Different : _msReset bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 009B4H Record Type 0091 Error 1: Previous Definition Different : _msCalculatingStatics bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 009CAH Record Type 0091 Error 1: Previous Definition Different : _msInStaticState bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 009E4H Record Type 0091 Error 1: Previous Definition Different : _msRunningSimulation bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 009FEH Record Type 0091 Error 1: Previous Definition Different : _msSimulationStopped bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 00AD0H Record Type 0091 Error 1: Previous Definition Different : _msSimulationStoppedUnstable bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 00AFAH Record Type 0091 Error 1: Previous Definition Different : _D8OrcFxAPI15StatisticsQuery6__initZ bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 00B22H Record Type 0091 Error 1: Previous Definition Different : _D8OrcFxAPI13WaveComponent6__initZ bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 00B83H Record Type 0091 Error 1: Previous Definition Different : _D8OrcFxAPI10GraphCurve6__initZ bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 00C7CH Record Type 0091 Error 1: Previous Definition Different : _D8OrcFxAPI10ObjectInfo6__initZ bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 00CABH Record Type 0091 Error 1: Previous Definition Different : _D8OrcFxAPI20RangeGraphCurveNames6__initZ bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 00CD4H Record Type 0091 Error 1: Previous Definition Different : _D8OrcFxAPI14ViewParameters6__initZ bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 00D3EH Record Type 0091 Error 1: Previous Definition Different : _D8OrcFxAPI23SolveEquationParameters6__initZ bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 00D99H Record Type 0091 Error 1: Previous Definition Different : _D8OrcFxAPI7VarInfo6__initZ bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 00E18H Record Type 0091 Error 1: Previous Definition Different : _D8OrcFxAPI9TimeSteps6__initZ bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 00EE3H Record Type 0091 Error 1: Previous Definition Different : _D8OrcFxAPI42UseCalculatedPositionsForStaticsParameters6__initZ bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 00F15H Record Type 0091 Error 1: Previous Definition Different : _D8OrcFxAPI23RunSimulationParameters6__initZ bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 00F47H Record Type 0091 Error 1: Previous Definition Different : _D8OrcFxAPI17AVIFileParameters6__initZ bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 00F60H Record Type 0091 Error 1: Previous Definition Different : _eaInitialise bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 00FB7H Record Type 0091 Error 1: Previous Definition Different : _eaFinalise bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 00FC9H Record Type 0091 Error 1: Previous Definition Different : _eaCalculate bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 00FE2H Record Type 0091 Error 1: Previous Definition Different : _eaStoreStateCreate bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 00FFCH Record Type 0091 Error 1: Previous Definition Different : _eaStoreStateDestroy bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 0101AH Record Type 0091 Error 1: Previous Definition Different : _eaCalculateNominalValue bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 010FAH Record Type 0091 Error 1: Previous Definition Different : _D8OrcFxAPI20ExternalFunctionInfo6__initZ bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 01135H Record Type 0091 Error 1: Previous Definition Different : _D8OrcFxAPI32NodeInstantaneousCalculationData6__initZ bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 01210H Record Type 0091 Error 1: Previous Definition Different : _D8OrcFxAPI34VesselInstantaneousCalculationData6__initZ bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 0124BH Record Type 0091 Error 1: Previous Definition Different : _D8OrcFxAPI32BuoyInstantaneousCalculationData6__initZ bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 0128CH Record Type 0091 Error 1: Previous Definition Different : _D8OrcFxAPI32WingInstantaneousCalculationData6__initZ bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 012ACH Record Type 0091 Error 1: Previous Definition Different : _thstSpectralDensity bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 012D2H Record Type 0091 Error 1: Previous Definition Different : _thstEmpiricalDistribution bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 012EFH Record Type 0091 Error 1: Previous Definition Different : _thstRainflowHalfCycles bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 01304H Record Type 0091 Error 1: Previous Definition Different : _propObjectName bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 0131AH Record Type 0091 Error 1: Previous Definition Different : _propNumOfStages bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 01338H Record Type 0091 Error 1: Previous Definition Different : _propStageDuration bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 0134DH Record Type 0091 Error 1: Previous Definition Different : _propNumOfNodes bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 01365H Record Type 0091 Error 1: Previous Definition Different : _propNumOfSegments bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 0137DH Record Type 0091 Error 1: Previous Definition Different : _propNodeArcLength bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 01398H Record Type 0091 Error 1: Previous Definition Different : _propSegmentArcLength bin\default\OrcFxAPI.obj(OrcFxAPI) Offset 01445H Record Type 0091 Error 1: Previous Definition Different : _D8OrcFxAPI12__ModuleInfoZ C:\dmd\lib\phobos.lib(ti_double) Offset 2941CH Record Type 0091 Error 1: Previous Definition Different : _D10TypeInfo_d6__initZ C:\dmd\lib\phobos.lib(ti_double) Offset 29439H Record Type 0091 Error 1: Previous Definition Different : _D10TypeInfo_d7__ClassZ C:\dmd\lib\phobos.lib(ti_double) Offset 29455H Record Type 0091 Error 1: Previous Definition Different : _D10TypeInfo_d6__vtblZ project "/OrcfxAPITest" build finished ---------------------------------------------------------------------- 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 16 --- errorLevel 1 ----------------------------------------------------------------------- So, I'm not sure if I should/can compile this as a D module, or if it should/can get statically linked or something else...as before, any help is very much appreciated
Jun 13 2007
next sibling parent reply Christopher Grantham <cgrantham gmail.com> writes:
Sorry, should have included the 'test.d' file...very n00bish, but its 
the most simple way to know the API library is working:



import std.stdio;
import std.c.windows.windows;

import OrcFxAPI;

int main(char[][] args) {
	writefln("Hello World!");
	foreach(argv, argc; args) {
		writefln("Arg:\t%s",argv);
	}
	
	// if this works, then we are interfacing to the DLL successfully :)
	/*C_GetDLLVersion(TDLLVersion *lpRequiredDLLVersion,
                                                      TDLLVersion 
*lpDLLVersion,
                                                      int* lpOK,
                                                      int* lpStatus);
	*/
	TDLLVersion dll_ver;
	int lpOK, lpStatus;
	
	C_GetDLLVersion(null,&dll_ver,&lpOK,&lpStatus);
	writefln("Orcaflex DLL Version:\t%s",dll_ver);
	
	
	return 0;
}

As you can see, I'm assuming the converted header becomes a D module 
with the filename as the module name (minus the '.d' extension)...
I'm probably going about it all wrong or something, so feel free to 
correct me, I could use the constructive criticism...
Jun 13 2007
next sibling parent Daniel Keep <daniel.keep.lists gmail.com> writes:
If you've made an import library using implib.exe, then you shouldn't
need to manually load the DLL: the import library should do that for
you.  Just start using it like you would any other C library...

...unless the library requires you to do something strange before using
it...

	-- Daniel
Jun 13 2007
prev sibling parent Frits van Bommel <fvbommel REMwOVExCAPSs.nl> writes:
Christopher Grantham wrote:
 Sorry, should have included the 'test.d' file...very n00bish, but its 
 the most simple way to know the API library is working:
 

 
 import std.stdio;
 import std.c.windows.windows;
 
 import OrcFxAPI;
[snip]
 
 As you can see, I'm assuming the converted header becomes a D module 
 with the filename as the module name (minus the '.d' extension)...
 I'm probably going about it all wrong or something, so feel free to 
 correct me, I could use the constructive criticism...
The naming of the converted header doesn't matter much, though consistency with the C name is probably a good thing. You may want to post your OrcFxApi.{h,d} files (or links to them) if you need help translating. Or you could just see if bcd (http://dsource.org/projects/bcd) can translate it automatically. At first glance, since the errors you get are all "Previous Definition Different", I'd guess you were compiling your translated header and linking to it. And you're not using extern {} to stop inclusion of symbols already defined in the actual library. If you're using a raw command line, not compiling your module at all may work (if everything needed to use it can be linked in from the C library). If you're using (re)build, putting "version(build) pragma(nolink);" in the .d file or renaming it to .di may do the trick. Otherwise, try wrapping your translated header (except any #defines translated to constants or functions) in an "extern {}" (as well as the normal "extern(C) {}"). If none of the above works, post your .h and .d/.di files and someone may be able to help.
Jun 13 2007
prev sibling parent reply Carlos Santander <csantander619 gmail.com> writes:
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 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. -- Carlos Santander Bernal
Jun 13 2007
parent reply Christopher Grantham <cgrantham gmail.com> writes:
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 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 16 _C_GetDLLVersion 16 OrcFxAPI.dll C_GetDLLVersion 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 16[]__imp__C_GetDLLVersion 16 _C_GetDLLVersion 16[] __imp__C_GetDLLVersion 16 C_GetDLLVersion 16[][].text [][][]__imp__C_GetDLLVersion 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
Jun 13 2007
parent reply Carlos Santander <csantander619 gmail.com> writes:
Christopher Grantham escribió:
 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:
 
There should be a file OrcFxAPI.lst with that info. Sorry for not mentioning that. -- Carlos Santander Bernal
Jun 14 2007
parent Christopher Grantham <cgrantham gmail.com> writes:
Carlos Santander wrote:
 Christopher Grantham escribió:
 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:
There should be a file OrcFxAPI.lst with that info. Sorry for not mentioning that.
Gah, I'm so stupid, I can't believe I missed that in the documentation... Examining the .lst file shows that the extern(C) and extern(Windows) symbols are all there; Daniel Keep solved the problem, it wasn't anything wrong (possibly sub-optimal) in the .h file converted to .d file, but that I was doing the following: dmd -run test.d OrcFxAPI.d OrcFxAPI.lib Since dmd -run only uses the first file argument to actually do compilation etc, the other files were being ignored, as soon as I ran the test.exe, everything worked (was very frustrated with myself). So I say to all who replied a very big thank you, I really appreciate the effort in helping a n00b along the path to learning/using D, keep up the noble work :D Thanks again. Chris.
Jun 16 2007
prev sibling parent Hoenir <mrmocool gmx.de> writes:
Christopher Grantham schrieb:
 So far I've tried converting the header to D (manually), which hasn't 
 worked (I get error: 138 data corruption), I think I should be able to 
 interface directly to the C code, but am not confident.
Try using htod: http://www.digitalmars.com/d/htod.html Also have a look at dmd/samples/d/mydll
Jun 13 2007