: http://blog.163.com/zhangjinqing1234@126/blog/static/307302602012111295026614/
--------------------------------------------------------------------------------------------------------------- ----------------------------------
The thing is, in actual development, the function name exported by the DLL is defined by the customer, unfortunately the customer-defined exported function name
and the name of the system API is the same, so that the API name conflicts, causing the call failed, the following is my test examples and solutions.
--------------------------------------------------------------------------------------------------------------- ---------------------------------------------------------
Header file TestDll.h, API prototypes are defined as follows:
#pragma once
/Os has a Api:dword getversion (VOID);
void GetVersion (char *pszbuf, int *pbuflen); Client-defined APIs
CPP file TESTDLL.CPP,API implementation code as follows:
#include "stdafx.h"
#include "TestDll.h"
void GetVersion (char *pszbuf, int *pbuflen)
{
if (pszbuf!= Null && pbuflen!= null && *pbuflen >=)
{
strcpy (pszbuf, "1.0.0.1");
}
DLL export module definition file Testdll.def contents are as follows:
LIBRARY "Testdll"
Exports
GetVersion
The test program code is as follows:
#include "stdafx.h"
#include ". /testdll/testdll.h "
#ifdef _debug
#pragma comment (lib," ...). /debug/testdll.lib ")
#else
#pragma comment (lib," ...). /release/testdll.lib ")
#endif
int _tmain (int argc, _tchar* argv[])
{
char szversion[16] = {0};
int ibuflen =;
GetVersion (szversion, &ibuflen);
printf ("%s", szversion);
GetChar ();
return 0;
}
Compile run, generate error message as follows:
1> TestDemo.cpp
1>testdemo.obj:error lnk2019:unresolved external symbol "void __cdecl getversion (char *,int *)" (?) getversion@ @YAXPADPAH @z) referenced in function _wmain
--------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------
Workaround:
The contents of the TestDll.h header file are modified as follows:
#pragma once
/Os has a Api:dword getversion (VOID);
void GetVersion (char *pszbuf, int *pbuflen); Client-defined API
void Mygetversion (char *pszbuf, int *pbuflen);
TestDll.cpp content is modified as follows:
#include "stdafx.h"
#include "TestDll.h"
void GetVersion (char *pszbuf, int *pbuflen)
{
// Implementation in Mygetversion
}
void Mygetversion (char *pszbuf, int *pbuflen)
{
if (pszbuf!= NULL && Pbuflen!= NULL && *pbuflen >=)
{
strcpy (pszbuf, "1.0.0.1");
}
Testdll.def memory modifications are as follows:
LIBRARY "Testdll"
Exports
Getversion=mygetversion
The final compilation runs with the following effect: