dll的问题
我的问题:如此调用dll中函数时,当传入的字符串只有一位时可以正常返回真,当超过一位时就全部返回假。
如果直接将函数写在可执行程序中就没有问题,返回值都是正确的。达人帮忙呀。
1、可执行程序中调用代码:
HINSTANCE hInst;
hInst=LoadLibrary("Check.dll");
typedef int ( *CHECKPROC)(CString str);
CHECKPROC CheckNumeric=(CHECKPROC)GetProcAddress(hInst,"CheckNumeric");
if(!CheckNumeric)
{
MessageBox("Load Check.dll failed!");
return;
}
CString str;
UpdateData();
str=m_TextString;
BOOL a ;
a = CheckNumeric(str);
if(a)
MessageBox(str);
else
AfxMessageBox("haha,wrong!");
FreeLibrary(hInst);
2、Dll中函数:
BOOL CheckNumeric(CString strValue)
{
BOOL bReturn;
bReturn = true;
CString sValue;
sValue = strValue.Trim();
if(sValue.Left(1)=='-'&&sValue.GetLength()>1)
sValue = sValue.Right(sValue.GetLength()-1);
for(int i = 0;i < sValue.GetLength();i++ )
{
if(sValue.GetAt(i)=='0'||sValue.GetAt(i)=='1'||sValue.GetAt(i)=='2'||sValue.GetAt(i)=='3'||sValue.GetAt(i)=='4'||
sValue.GetAt(i)=='5'||sValue.GetAt(i)=='6'||sValue.GetAt(i)=='7'||sValue.GetAt(i)=='8'||sValue.GetAt(i)=='9')
{
bReturn = false;
break;
}
if(sValue.GetAt(i)< 48 || sValue.GetAt(i)>57)
{
bReturn = false;
break;
}
}
if(sValue.IsEmpty())
{
bReturn = false;
}
return(bReturn);
}