Re: Forwarding DLL



Mihai P wrote:

I want to make a DLL to forward some classes from a LIB.

So, I have a solution in VS.NET2005 which contains 3 projects
presented in their build order:

ForwardLib [Win32.Static Library -pch] ~ no reference
ForwardDll [Win32.DLL + Export Simbols] ~ reference to Lib
ForwardApp [Win32 Application] ~ reference to Dll

In ForwardLib I have MathFuncs class, it's header file is:

[MathFuncs.h]
#pragma once

#ifndef FORWARDDLL_API
#define FORWARDDLL_API
#endif

class FORWARDDLL_API MathFuncs
{
public:
MathFuncs(void);
public:
~MathFuncs(void);
public:
int add(int a, int b);
public:
int mul(int a, int b);
};
#EOF#

This is compiled as static lib, and nothing of this is marked as
DLL-exported during compilation.

ForwardDll.h
#ifdef FORWARDDLL_EXPORTS
#define FORWARDDLL_API __declspec(dllexport)
#else
#define FORWARDDLL_API __declspec(dllimport)
#endif

#include "..\ForwardLib\MathFuncs.h"

This might declare some parts as being exported but it doesn't change
anything. The code is still only taken from the static lib and nothing is
changed, in particular not the exports.

In ForwardApp.h I added:
#include "..\ForwardDll\ForwardDll.h"


When I make no explicit calls of the imported class from the application
everything is ok, but when I try to use it, even to create an object of
that type linker shouts:

Error 1 error LNK2019: unresolved external symbol "__declspec(dllimport)
public: __thiscall MathFuncs::~MathFuncs(void)"
(__imp_??1MathFuncs@@QAE@XZ) referenced in function "int __cdecl
InitInstance(struct HINSTANCE__ *,int)"
(?InitInstance@@YAHPAUHINSTANCE__@@H@Z) ForwardApp.obj

Yep, nothing was exported from the DLL and so there is nothing to satisfy
the dependencies, leading to linker errors.

I'm a bit confused about how linker exports my functions within the
class from the dll though I think it doesnt do that at all.

Right, because it wasn't told to do so during compilation.

To my mind, the problem is when exporting/forwarding the class from
DLL. When I link a LIB to another project, the code from the lib is
linked to the project as if I define&declare it there?

A static library is just a collection of .obj files. IOW, it is as if you
had the sourcefiles in your project except that it is compiled separately.

If so, the DLL should contain those symbols, but it doesn't and I
cannot figure this out!

What I'm doing wrong? Is there another way?

Two ways:
1. Make the static lib a DLL. There is no need to first make a static lib
and then create a dynamic one from it.
2. You could also declare the symbols as being DLL-exported while compiling
the static lib, but I'm not sure if that has any other side effects.

Uli



.



Relevant Pages

  • /CLR Compilation: 125x slower when calling virtual function from DLL?
    ... searching for possible bottlenecks (the application is currently running ... "CallTheFunctionAndBenchmark" from this DLL: ... virtual int* gimmeAnInt; ... I know CLR compilation is supposed to take longer, ...
    (microsoft.public.dotnet.languages.vc)
  • /CLR Compilation: 125x slower when calling virtual function from DLL?
    ... searching for possible bottlenecks (the application is currently running ... "CallTheFunctionAndBenchmark" from this DLL: ... virtual int* gimmeAnInt; ... I know CLR compilation is supposed to take longer, ...
    (microsoft.public.vc.language)
  • Re: Problem with constants (MSVC)
    ... h79 wrote: ... >is the same as (after compilation): ... int main ... Fixing this could break clients of the DLL who also use the ...
    (microsoft.public.vc.language)
  • error LINK2019: unresolved external symbol
    ... some use as parameter of the int, other CString. ... During the compilation of the DLL I don't have errors. ...
    (microsoft.public.vc.mfc)
  • Re: OTOH, you folks are smart ...
    ... user to initialize the SDK. ... It would be interesting to see what the aforementioned DLL entry ... I'm able to use the static lib to build an app with no problems as long as ... referenced by the linker *before* the run-time is referenced. ...
    (microsoft.public.vc.mfc)