c++ - WINAPI - error LNK2019, LNK2001, LNK1120 when compiling. -


very new winapi gentle.

i have read "windows via c/c++" book jeffrey richter , i'm trying of basic dll stuff descibes in book.

in chapter 19 make simple example. have tried make example, keep getting these 3 errors when building project:

error   1   error lnk2019: unresolved external symbol __imp__add referenced in function _wwinmain@16     error   2   error lnk2001: unresolved external symbol __imp__g_nresult error   3   error lnk1120: 2 unresolved externals 

i have 3 files:

dllchapter19.h :

#ifdef mylibapi #else #define mylibapi extern "c" __declspec(dllimport) #endif mylibapi int g_nresult; mylibapi int add(int nleft, int nright); 

dllchapter19.cpp :

//#include <windows.h> //apparently complier says should use stdafx.h instead(?) #include "stdafx.h" #define mylibapi extern "c" __declspec(dllexport) #include "dllchapter19.h"  int g_nresult;  int add(int nleft, int nright) {     g_nresult = nleft + nright;     return(g_nresult); } 

and (in project, in same solution).

dllchapter19exe.cpp :

//#include <windows.h> //apparently complier says should use stdafx.h instead? #include "stdafx.h" #include <strsafe.h> #include <stdlib.h>  #include "c:\users\kristensen\documents\visual studio 2012\projects\dllchapter19\dllchapter19\dllchapter19.h"   int winapi _twinmain(hinstance , hinstance , lptstr, int) {      int nleft = 10, nright = 25;      tchar sz[100];     stringcchprintf(sz, _countof(sz), text("%d +%d =%d"),         nleft, nright, add(nleft, nright));     messagebox(null, sz, text("calculation"), mb_ok);      stringcchprintf(sz, _countof(sz),         text("the result last add is: %d"), g_nresult);     messagebox(null, sz, text("last result"), mb_ok);     return(0); } 

why getting these 3 errors? have @ dllchapter19.dll via 'dumpbin -exports' , looks fine, 2 exported symbols:

c:\program files (x86)\microsoft visual studio 11.0\vc\bin\amd64>dumpbin -export s dllchapter19.dll microsoft (r) coff/pe dumper version 11.00.60315.1 copyright (c) microsoft corporation.  rights reserved.   dump of file dllchapter19.dll  file type: dll    section contains following exports dllchapter19.dll      00000000 characteristics     5184f8ee time date stamp sat may 04 14:02:54 2013         0.00 version            1 ordinal base            2 number of functions            2 number of names      ordinal hint rva      name            1    0 000110c3 add           2    1 00017128 g_nresult    summary          1000 .data         1000 .idata         2000 .rdata         1000 .reloc         1000 .rsrc         4000 .text        10000 .textbss 

i have searched , searched not find solution problem.

this linker error when compiling executable. dll fine, have not told linker how link it. need pass linker import library (the .lib file) created when built dll.

i take using visual studio. in case add import library additional library dependencies setting in project configuration executable.


Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -