0

I have a class inside a dll which I want to use in another project. I read this tutorial about how to do this and my pseudo code looks like this

interface.h

#ifdef  EXPORT
#define SOMEAPI __declspec(dllexport)
#else
#define SOMEAPI __declspec(dllimport)
#endif

struct ISomeInterface
{
  virtual void SomeMethod()=0;
};

typedef ISomeInterface* SOMEHANDLE;

#define EXTERN_C     extern "C"

EXTERN_C SOMEAPI SOMEHANDLE WINAPI CreateSomething(VOID);

And then I have SomeDLL.dll which implements ISomeInterface and CreateSomething.
When I try to use this in my client I get linker error. The client looks like this:
Client.cpp

#include "interface.h"
SOMEHANDLE h = ::CreateSomething();  // Linker error here: Unresolved external  

I can solve this by adding the dll project as a dependency of Client project in VC++. Then everything is good.
The problem is what if I want to use this a standalong dll(which is the case right now)? How do I get rid of the linker error then?

Community
  • 1
  • 1
atoMerz
  • 7,534
  • 16
  • 61
  • 101
  • You may need to provide a static lib, that allows loading the dll at runtime and wraps the interface for your client. Have a look [here](http://stackoverflow.com/questions/3360828/plugin-pattern-with-dll-how-can-i-extract-plugin-interface-from-dll) – πάντα ῥεῖ Nov 10 '12 at 12:34

1 Answers1

0

I can solve this by adding the dll project as a dependency of Client project

Yes, that automatically does the one thing you have to do in a stand-alone project by hand. Project + Properties, Linker, Input, Additional Dependencies setting. Add the .lib file that was generated by the DLL project. The import library, it tells the linker about the functions exported by the DLL.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • Thank you. I managed to solve this problem by adding `#pragma comment(lib, "FormatDriveDLL.lib")`. But you're doing this automatically. – atoMerz Nov 12 '12 at 09:19