关于DLL的两个小问题
以前DLL接触很少,今天在学习DLL的基本使用,编了一个小程序做试验。结果发现了两个问题:
1. 为什么导出函数的名字变成了_TextOutMe@16这么怪?是C++编译的需要吗?能否简单介绍一下关于导出函数命名变化的问题?
2. DEBUG版程序结束退出时,发生错误:
The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling conversion with a function pointer declared with a different calling conversion.
不太明白是什么意思,能否请高手指点一二?
===============================================
附:我的程序代码
///////////////////////////////////////////////////
//DLLMe.h
//
///////////////////////////////////////////////////
#include <string>
#ifdef __cplusplus
#define EXPORT extern"C" __declspec(dllexport)
#else
#define EXPORT __declspec(dllexport)
#endif
using namespace std;
EXPORT BOOL CALLBACK TextOutMe(const string);
///////////////////////////////////////////////////
//DLLME.cpp
//
///////////////////////////////////////////////////
#include <windows.h>
#include <iostream>
#include <string>
#include "DLLMe.h"
using namespace std;
int WINAPI DllMain(HINSTANCE hInstance, DWORD fdwReason, LPVOID pvReserved)
{
return TRUE;
}
EXPORT BOOL CALLBACK TextOutMe(const string str)
{
cout << "DLL:" << str << endl;
return TRUE;
}
////////////////////////////////////////////////////////
//DllMeTry.cpp
//
////////////////////////////////////////////////////////
#pragma once
#include <windows.h>
#include <iostream>
#include <string>
#include <tchar.h>
#include "DLLMe.h"
using namespace std;
typedef BOOL(* FNP)(const string);
HINSTANCE hLib;
FNP pfnTextOut;
main()
{
string str;
cin >> str;
hLib = LoadLibrary(_T(str.c_str()));
if(hLib == NULL)return 0;
pfnTextOut = (FNP)GetProcAddress(hLib, _T("_TextOutMe@16"));
if(pfnTextOut == NULL)return 0;
while(str != "quit")
{
cin >> str;
pfnTextOut(str);
}
FreeLibrary(hLib);
return 0;
}