DLL export function name and system API name same conflict problem _api name conflict

Source: Internet
Author: User

: 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:













Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.