2

I've developed a program and I am trying to make this program work with a controllable light source manufactured by some other company. I've emailed the company and they have agreed to send me their external library as a DLL.

I have developed all of my software using Qt 4.8.1 and it has been compiled using MSVC2008.

The controllable light's DLL was compiled in Visual Studio 2008 and was written in either C++ or C# (the manufacturer is uncertain). All I have been given is the DLL and a text file saying that I must:

  1. Add the DLL as a reference to my project
  2. Add using LightName; to the top of the class
  3. Instantiate an instance of the object like so: LightName *ln = new LightName();
  4. Call function void turnOn() with the newly created LightName instance.

Firstly, I find it odd that an external library requires me to instantiate an instance of their object especially when its for a simple piece of hardware.

Secondly, the other company has provided me with no interface files.

My question is: How can I possibly link to a C++ DLL and expose the functions nested in this library without having an interface header file in a Qt environment? Is there someway to make an interface for an external library?


I have already attempted using QLibrary and doing the following:

 QLibrary myLib("mylib");
 typedef void (*MyPrototype)();
 MyPrototype myFunction = (MyPrototype) myLib.resolve("mysymbol");
 if (myFunction)
     myFunction();

However, this doesn't work because the DLL I was given was not a C DLL and I have no interface so Qt doesn't have a clue about what symbols it needs to resolve.


I've attempted to display all the definitions exported from my DLL using the dumpbin /EXPORTS command. Unfortunately this was unable to produce anything. I was hoping that I would get some sort of mangled C++ from this that I could then unscramble to make my own header.


I've attempted to use the dependency walker(very useful tool) however it couldn't resolve any symbols to give me some function definitions.


Paul Roub
  • 36,322
  • 27
  • 84
  • 93
stackunderflow
  • 10,122
  • 4
  • 20
  • 29
  • I don't advice to use `QLibrary` for using externals libraries. It needs only when you don't know name of library beforehand (e.g. when you want to support plugins). I think you just need link a library using your *.pro file. – fasked Sep 20 '12 at 02:41
  • Yes that's all well and fine, it is possible to load a library from the .pro as well. Regardless of whether an external library is loaded from QLibrary or from the .pro, how can I call the functions within that given library for a DLL written in C++? @fasked – stackunderflow Sep 20 '12 at 06:08
  • Did they give a reason why they wouldn't send the headers? – cmannett85 Sep 20 '12 at 06:25
  • No, no reasons. Its looking like its a necessity though. – stackunderflow Sep 21 '12 at 16:44

2 Answers2

1

QLibrary only helps you if the library has functions exported as C symbols. If that is C++ you can dump the symbol table and look if that is sufficient for you. Names must be demangled: try to look for dumpbin or similar. It is however possible that you can't do this, it depends on how the symbols have been defined. In that case you'll have to ask for the header: read this.

Community
  • 1
  • 1
Luca Carlon
  • 9,546
  • 13
  • 59
  • 91
1

Well it's absolutely legal to ask you for "instantiating an instance of their object". It's been simply their design decision to make the dll interface object oriented (as contrary to plain extern "C"). QtCore.dll is just someone else's DLL too, and you are instantiating their objects all the time.

But it also means that you will have harder time to call the DLL. The symbols are not "C" symbols (you can't export class that way) so QLibrary can't do anything for you. You can try dumpbin /EXPORTS from the DLL and then tediously unmangle them to reconstruct the class declaration. Luckily there are tools to help you (even online)

But not providing a header file for such DLL is completely dumb in the first place.

Pavel Zdenek
  • 7,146
  • 1
  • 23
  • 38
  • Well I was really hoping that the website for unmangling C++ code would be helpful. Unfortunately, when I ran dumpbin it couldn't detect any method definitions scrambled or unscrambled [(Screenshot of dumpbin results)](http://www.freeimagehosting.net/gi3xx). Any other possible suggestions? Otherwise, I guess I'm back to the drawing board and must find a new light. I agree, its really silly that they could not provide a header file. Thanks for your help @Pavel Zdenek. – stackunderflow Sep 21 '12 at 17:06
  • I admit not being very familiar with dumpbin. It's just what everyone is using. So to be 100% sure, try [Dependency Walker](http://www.dependencywalker.com/). Just drop your DLL on `depends.exe` and the symbols (if any) should be visible in the second window from the top right side. – Pavel Zdenek Sep 21 '12 at 18:23
  • Thanks @Pavel for your suggestions. Unfortunately, I have already given the Dependancy Walker a try and it couldn't resolve any symbols. It looks like I'm going to have to send an email to the organization because I need the header file. Otherwise, I may just go with a different controllable light which is unfortunate. – stackunderflow Sep 28 '12 at 16:54