Got Stucked in C++ Static Library Loading.. for some time

I used to load library using 1 single .dll file, so when I happen to do method calling between 2 projects in a solution, I got puzzled..

In the solution, doing method calling between projects is constant, so as far as I can see, the dynamic calling method is onerous. It's also not Okay to call method from the other project directly, that will invoke the unresolved external link error(2001,1014,2011, etc..) during link.

Eventually I found that static calling is the remedy. In this way, you can avoid doing onerous calling that dynamic calling might cause. But the shortcoming is to attach a .lib with the release, making the size larger. Most times .lib files are small in size.

dynamic calling in x86 programs:

1 //method definition in .dll: type Func(type1 t1, type2 t2);
2 typedef type (*F)(type1,type2);
3 HINSTANCE hInst = new LoadLibrary(".dll");
4 F f = GetProcAddress(
5         hInst,
6         "Func"
7 };
8 //method name never coincides.

static calling:

1 //statically calling method
2 //First, specify the additional c/c++ include directory where func.h is in C/C++ general from project properties.
3 //Second, if needed, specify the func2.lib file directory in link general from project properties
4 //func.h
5 #include "func2.h"//this file contains the function definition
6 #pragma comment(lib, "func2.lib")//.lib file contains info about method addresses in .dll file
7 func2();//method calling

 

posted on 2016-04-19 16:11  三叁  阅读(206)  评论(0编辑  收藏  举报

导航