未处理的异常:访问冲突错误 [英] Unhandled Exception:Access Violation Error
本文介绍了未处理的异常:访问冲突错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
正在创建MFC DLL&收到错误:Key_Testing.exe中0x00000000的未处理异常:0xC0000005:访问冲突.
DLL代码如下:
Hello Everyone,
Am working creating MFC DLL & am getting an error:Unhandled exception at 0x00000000 in Key_Testing.exe: 0xC0000005: Access violation.
The DLL Code is like this:
//Demo.h
char* GetDiskSerialNumber (char g_DiskLetter);
//Demo.cpp
char* DLLclass::GetDiskSerialNumber(char g_DiskLetter)
{
CHAR SN[64];
memset(SN,0,sizeof(SN));
if(GetSerialNumber(SN,g_DiskLetter)){ // Error in this Line..
return (char*)SN;
}
}
This DLL am using in an application..
void CKey_TestingDlg::OnBnClickedgetserial()
{
// TODO: Add your control notification handler code here
DLLclass Dllobj;
char ltr='h';
char* ser=Dllobj.GetDiskSerialNumber(ltr);
}
请,任何人都可以建议我哪里出了问题..任何帮助都会得到应用..
谢谢.
Please,, Could anyone suggest where i gone wrong.. Any help will be appriciated..
Thank you.
推荐答案
GetSerialNumber
中的代码是什么?
那里可能有一些错误.
另外,您还要声明一个本地数组并返回其地址,当该函数返回时,该地址将不再有效.
而是按如下所示更改它-
What is the code insideGetSerialNumber
?
There is probably some error there.
Also, you''re declaring a local array and returning its address, which will no longer be valid when the function returns.
Instead change it as follows -
void DLLclass::GetDiskSerialNumber(char g_DiskLetter, char* SN)
{
GetSerialNumber(SN, g_DiskLetter);
}
void CKey_TestingDlg::OnBnClickedgetserial()
{
// TODO: Add your control notification handler code here
DLLclass Dllobj;
char ltr=''h'';
CHAR SN[64];
memset(SN,0,sizeof(SN));
Dllobj.GetDiskSerialNumber(ltr, SN);
}
GetDiskSerialNumber
正在返回指向本地数组的指针.这是无效的.当函数退出并驻留在堆栈中时,局部变量将死亡.
GetDiskSerialNumber
is returning a pointer to a local array. This is not valid. Local variables die when the function exits as they reside on the stack.
这篇关于未处理的异常:访问冲突错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文