//加密
typedef int  (__stdcall *XX_RTea)(char* p,char* s,long l);
XX_RTea _XX_RTea;void CEncryptTestDlg::OnBnClickedButton1()
{
// TODO: 在此添加控件通知处理程序代码 UpdateData();
INT X=79;
CString str1,str2;
str2.Empty();
GetDlgItemText(IDC_EDIT1,str1);
if (!str1.IsEmpty())
{
_XX_RTea = (XX_RTea)GetProcAddress(hInstLibrary, "XX_RTea");
//BSTR bstr1;
//BSTR bstr2;
//bstr1 = str1.AllocSysString();
//X=_XX_RTea(bstr1,bstr2,RTea_License);
X=_XX_RTea(str1.GetBuffer(0),str2.GetBuffer(0),RTea_License); SetDlgItemText(IDC_EDIT2,str2); 
}
UpdateData(FALSE);
}==========================
Windows 已在 TFEncryptTest.exe 中触发一个断点。其原因可能是堆被损坏,这也说明 TFEncryptTest.exe 中或它所加载的任何 DLL 中有 bug。输出窗口可能提供了更多诊断信息
=================================
---------------------------
Microsoft Visual C++ Debug Library
---------------------------
Debug Assertion Failed!Program: e:\SU\DSM\11\testICA\testICA\Debug\testICA.exe
File: dbgheap.c
Line: 1252Expression: _CrtIsValidHeapPointer(pUserData)For information on how your program can cause an assertion
failure, see the Visual C++ documentation on asserts.(Press Retry to debug the application)
---------------------------
终止(A)   重试(R)   忽略(I)   
---------------------------不知道该怎么办?各位大侠给看看。

解决方案 »

  1.   

    void CEncryptTestDlg::OnBnClickedButton1()
    {
        UpdateData();
        INT X=79;
        // CString str1,str2;
        char str1[1000]; // 定义足够大的数组
        char str2[1000]; // 定义足够大的数组
        if (GetDlgItemText(IDC_EDIT1,str1,sizeof(str1))) 
        {
            _XX_RTea = (XX_RTea)GetProcAddress(hInstLibrary, "XX_RTea"); 
            X=_XX_RTea(str1,str2,RTea_License); 
            SetDlgItemText(IDC_EDIT2,str2); 
        } 
        UpdateData(FALSE); // 这行貌似没有意义。
    }
      

  2.   

    嗯,谢谢。
    这样是没问题了,但是为什么str1.GetBuffer(0)不行呢?
      

  3.   

    你可以在MSDN中查一下GetBuffer函数的说明,这样会比较清楚。简单提一下,GetBuffer是分配一段内存,把对象中保存的字符串复制到该内存中,函数参数的含义是至少要分配多少内存,如果参数小于字符串长度,则按字符串长度来分配。如果字符串为空,GetBuffer(0)相当于没有分配内存。你调用的DLL函数要通过指针类型的参数返回数据,所以必须提供足够大的缓冲区。
    另外,GetBuffer用完后还需要执行ReleaseBuffer释放缓冲区。
      

  4.   

    这个是我在csdn最快的解决问题和结贴的帖子。