Home > Software engineering >  How to use after LoadLibrary c DLL.
How to use after LoadLibrary c DLL.

Time:10-04

C + + DLL in addition to full function, can also be derived classes, and variables,

LoadLibrary. Then how to use these classes and variables, such as the following code, is vs automatically generated DLL files, how to use the CConsoleApplication8 and nConsoleApplication8



//the following ifdef block is created to make from the DLL export more simple 
//macro standard method, all the files in this DLL is defined using the command line CONSOLEAPPLICATION8_EXPORTS
The compiler//symbol, and the DLL for use in
//should not define this symbol on any other project, so, any other project in the source file containing the file will be
//CONSOLEAPPLICATION8_API functions as from a DLL import, while the DLL will use this macro to define the
//symbol as are exported,
# ifdef CONSOLEAPPLICATION8_EXPORTS
# define CONSOLEAPPLICATION8_API __declspec (dllexport)
# the else
# define CONSOLEAPPLICATION8_API __declspec (dllimport)
# endif

//this is from ConsoleApplication8. DLL export
The class CONSOLEAPPLICATION8_API CConsoleApplication8 {
Public:
CConsoleApplication8 (void);
//TODO: add your way here,
};

Extern CONSOLEAPPLICATION8_API int nConsoleApplication8;

CONSOLEAPPLICATION8_API int fnConsoleApplication8 (void);



Use:
 int main () 
{
Auto pMod=LoadLibrary (L "ConsoleApplication8. DLL");
STD: : cout & lt; CConsoleApplication8 * PDDDDD=new CConsoleApplication8 ();

getchar();
return 0;
}


1 & gt; ConsoleApplication6. Obj: error LNK2019: cannot resolve the external symbol "__declspec (dllimport) public: __thiscall CConsoleApplication8: : CConsoleApplication8 (void)" (__imp_?? 0 cconsoleapplication8 @ @ QAE @ XZ), the symbol referenced in the function _main
1 & gt; ConsoleApplication6. Obj: error LNK2001: cannot resolve the external symbol "__declspec (dllimport) int nConsoleApplication8" (__imp_? NConsoleApplication8 @ @ 3 ha)
1 & gt; C: \ Users \ tydq \ documents \ visual studio 2015 \ Projects \ ConsoleApplication6 \ Debug \ ConsoleApplication6 exe: fatal error LNK1120:2 cannot resolve the external command

CodePudding user response:

Unresolved external symbol, appear the wrong usually two reasons, don't load into the first library, the second statement does not implement,

CodePudding user response:

Derived classes to direct link with the lib way, then document containing h class can be used

CodePudding user response:

GetProcAdress like;
Typedef BOOL (__stdcall * pGetCount) (HIMAGELIST himglst);
DWORD WINAPI rtGetImageCount (LPVOID lpParam)
{
HINSTANCE hInst=: : LoadLibrary (" comctl32. DLL ");
if (! HInst)
{
AfxMessageBox (" can 't load comctl32. DLL ");
return -1;
}
//get the adress of 'ImageList_GetImageCount'
PGetCount pfunCall=(pGetCount) GetProcAddress call (hInst, "ImageList_GetImageCount");
FreeLibrary (hInst);
* (((pPARAMETER) (lpParam)) - & gt; PretCount)=pfunCall (HIMAGELIST lpParam);
return 0;
}

Implicit linking is used, the lib files

CodePudding user response:

DLL in the derived class cannot use explicit connection

CodePudding user response:

http://www.codeguru.com/cpp/w-p/dll/importexportissues/article.php/c123/Explicitly-Linking-to-Classes-in-DLLs.htm

CodePudding user response:

Library file contains the CPP file compiled file, add the library file header file, called directly
  • Related