Thread overview
importing DLL
Mar 28, 2008
BCS
Mar 28, 2008
Neal Alexander
Mar 28, 2008
BCS
Mar 28, 2008
Frits van Bommel
Mar 28, 2008
Regan Heath
Mar 28, 2008
BCS
Mar 28, 2008
BCS
Mar 29, 2008
Neal Alexander
March 28, 2008
I have a DLL with no .h no .def and nothing but the DLL. What are my odds of linking it in with a D app?


March 28, 2008
BCS wrote:
> I have a DLL with no .h no .def and nothing but the DLL. What are my odds of linking it in with a D app?
> 
> 

implib.exe
March 28, 2008
Neal Alexander wrote:
> BCS wrote:
> 
>> I have a DLL with no .h no .def and nothing but the DLL. What are my odds of linking it in with a D app?
>>
>>
> 
> implib.exe

Tried that. It gives me a .lib (that doesn't seem to work but I could be mistaken) but I still don't know what functions are defined. (maybe I should have added "no documentation")
March 28, 2008
BCS wrote:
> Neal Alexander wrote:
>> BCS wrote:
>>
>>> I have a DLL with no .h no .def and nothing but the DLL. What are my odds of linking it in with a D app?
>>>
>>>
>>
>> implib.exe
> 
> Tried that. It gives me a .lib (that doesn't seem to work but I could be mistaken) but I still don't know what functions are defined. (maybe I should have added "no documentation")

If you don't know what functions it defines things get tricky.
IIRC you should be able to determine their names somehow, but most DLLs use C-like mangling[1] so there's no sure way to know what parameters they expect or what they return.
And even if it's a (non-D[2]) mangling with parameter and type info it's not much better unless you feel like writing e.g. some extern "C" C++ bindings. (Though then at least you know that should work, provided you can demangle them)

I do seem to remember "stdcall"[3]-mangled names include the number of bytes of parameters they expect though, so if based on that and the function name you can make an educated guess as to their parameters and return type...


[1]: In other words: pretty much no parameter & return type information.
[2]: For D mangling, running it through Phobos' std.demangle should produce enough info to declare the right functions.
[3]: "extern(Windows)"
March 28, 2008
BCS wrote:
> Neal Alexander wrote:
>> BCS wrote:
>>
>>> I have a DLL with no .h no .def and nothing but the DLL. What are my odds of linking it in with a D app?
>>>
>>>
>>
>> implib.exe
> 
> Tried that. It gives me a .lib (that doesn't seem to work but I could be mistaken) but I still don't know what functions are defined. (maybe I should have added "no documentation")

Do you have a copy of dumpbin:
http://support.microsoft.com/kb/177429

Regan
March 28, 2008
Reply to Regan,

> BCS wrote:
> 
>> Neal Alexander wrote:
>> 
>>> BCS wrote:
>>> 
>>>> I have a DLL with no .h no .def and nothing but the DLL. What are
>>>> my odds of linking it in with a D app?
>>>> 
>>> implib.exe
>>> 
>> Tried that. It gives me a .lib (that doesn't seem to work but I could
>> be mistaken) but I still don't know what functions are defined.
>> (maybe I should have added "no documentation")
>> 
> Do you have a copy of dumpbin:
> http://support.microsoft.com/kb/177429
> Regan
> 

I will soon.


March 28, 2008
Reply to Benjamin,

> Reply to Regan,
> 
>> BCS wrote:
>> 
>>> Neal Alexander wrote:
>>> 
>>>> BCS wrote:
>>>> 
>>>>> I have a DLL with no .h no .def and nothing but the DLL. What are
>>>>> my odds of linking it in with a D app?
>>>>> 
>>>> implib.exe
>>>> 
>>> Tried that. It gives me a .lib (that doesn't seem to work but I
>>> could be mistaken) but I still don't know what functions are
>>> defined. (maybe I should have added "no documentation")
>>> 
>> Do you have a copy of dumpbin:
>> http://support.microsoft.com/kb/177429
>> Regan
> I will soon.
> 

correction, I have it but it's not working (not installed correctly or some such, More fun!)


March 29, 2008
BCS wrote:
> Reply to Benjamin,
> 
>> Reply to Regan,
>>
>>> BCS wrote:
>>>
>>>> Neal Alexander wrote:
>>>>
>>>>> BCS wrote:
>>>>>
>>>>>> I have a DLL with no .h no .def and nothing but the DLL. What are
>>>>>> my odds of linking it in with a D app?
>>>>>>
>>>>> implib.exe
>>>>>
>>>> Tried that. It gives me a .lib (that doesn't seem to work but I
>>>> could be mistaken) but I still don't know what functions are
>>>> defined. (maybe I should have added "no documentation")
>>>>
>>> Do you have a copy of dumpbin:
>>> http://support.microsoft.com/kb/177429
>>> Regan
>> I will soon.
>>
> 
> correction, I have it but it's not working (not installed correctly or some such, More fun!)
> 
> 

The .lib should work for linking.
Use some PE utility to find the exports - StudPE is ok i think.

or you can modify this code to dump the export table and generate a D header for your self:

http://svn.dsource.org/projects/kong/trunk/kong/examples/import_dump.d