views:

17

answers:

2

I have two WIN32 DLL projects in the solution, main.dll should call a function in mgn.dll.

mgn.dll has mgn.h header file:

#ifdef MGN_EXPORTS
#define MGN_API __declspec(dllexport)
#else
#define MGN_API __declspec(dllimport)
#endif

extern "C" bool MGN_API AttachMGN(void);

and mgn.cpp source file:

#include "stdafx.h"
#include "mgn.h"

MGN_API bool AttachMGN(void)
{
...
}

main.dll calls AttachMGN function from one of the source file:

#include "stdafx.h"
#include "..\mgn\mgn.h"

bool CreateClient()
{
    return ::AttachMGN();
}

mgn.dll compiles successfully. main.dll doesn't show any errors in VS text editor, I can navigate using "Go To Definition" function. However during build I get the error:

error LNK2019: unresolved external symbol _imp_AttachMGN referenced in function "bool __cdecl CreateClient(void)" (?CreateClient@@AW4XZ)

Both DLLs compile into the same folder. DependencyWalker shows the function AttachMGN as exported. Main project has a dependency set to Mgn project, if that matters.

I believe that I simply have overlooked something....

Thanks in advance.

A: 

Is your mgn.lib linked with the main? By the sound of it, it looks as if main cannot find the lib file to link against the DLL.

tommieb75
A: 

You probably just forgot to add MGN.lib to your link arguments for main.dll

John Knoeller
how to do that from VS environment? :8 sorry, this is my first win32 project.
kriau
Just checked and main.dll has the value %(AdditionalDependencies) in the Additional Dependencies field in the Linker->Input section. And main.dll has has a dependency set to mgn.dll
kriau
Add mgn as a reference to main, it's on the same menu that you use to set it as a dependent.
John Knoeller
Thanks, that has helped !!!
kriau