从C ++中的Export DLL返回值时,程序崩溃 [英] Program Crash While returning Value from Export DLL in C++
本文介绍了从C ++中的Export DLL返回值时,程序崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的ABC.DLL标头
Hi,
Here is my ABC.DLL Header
extern "C"
{
__declspec(dllexport) unsigned int CallFile(string, string);
}
class __declspec(dllexport) CPW
{
Convert();
};
在ABC.DLL CPP中
In ABC.DLL CPP
__declspec(dllexport) unsigned int CallFile(string str1, string str2)
{
CPW *pR = new CPW();
unsigned int nStatus = pR->File(str1, str2);
if (pRAWFileConverter)
delete pRAWFileConverter;
return nReaderStatus;
}
现在,我将AS.EXE调用为
Now I am calling in my AS.EXE as
typedef unsigned int (*EntryPointfuncPtr)(string argv_1, string argv_2);
string Lib_File = "ABC.dll";
HINSTANCE LoadMe = LoadLibrary(Lib_File.c_str());
EntryPointfuncPtr LibMainEntryPoint = (EntryPointfuncPtr)GetProcAddresS(LoadMe, "CallFile");
if (LibMainEntryPoint != NULL)
{
cout << "MESSAGE SENT" << endl;
}
string str1 = "abc.txt";
string str2 = "ytr.txt";
unsigned int nReaderStatus = LibMainEntryPoint(str1, str2);
FreeLibrary(LoadMe);
当"CallFile"函数返回值时,它将崩溃.
任何帮助!!
When "CallFile" function is returning value, it is getting crashed.
Any Help!!
推荐答案
返回错误与堆栈问题有关(主要是)
所以
1-检查参数是否超出范围
2-检查您的通话转换(std call,cdecl,...)
正如我在您的代码中看到的那样,问题返回到__cdecl调用
使用__stdcall代替__declspec
Error in returns is about stack problem(mostly)
so
1 - check your parameter out of bound write
2 - check your calling conversion (std call , cdecl ,... )
as i see in ur code the problem returns to __cdecl call
use __stdcall Instead of __declspec
这篇关于从C ++中的Export DLL返回值时,程序崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文