具有C ++未处理异常的MFC DLL [英] MFC dll with c++ unhandled exception

查看:61
本文介绍了具有C ++未处理异常的MFC DLL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我一直在尝试找出应用程序中到底出了什么问题.
我基本上在c ++中制作了一种用于"LexEngine"的包装dll文件.
lexengine
lexengine是mfc应用程序.从上面的链接,它的前端是SmartLexicon.
我不断收到以下错误.
teendreams.exe中0x102e683e(msvcr100d.dll)的未处理异常:

0xC0000005: Access violation reading location 0x0065006e.



粗体部分的更改通常取决于我的调试方式.
我知道我没有正确初始化某些东西,或者我没有正确删除它.但我不知道该怎么办.

我创建一个lexManagement指针作为全局指针.我通过使用lexEngine的lexview代码收集了其余功能.

请帮忙.我已经在这里呆了很长时间了,我很失落.

我真正需要的最终结果只是一个词的含义.所以我加载了特定的字典并得到了含义.这些函数需要CStrings作为输入,并创建一个据我所知从CObject派生的对象.一个mfc dll,这是否意味着您正在调试中运行?如果要转到developer Studio中的调试"菜单,然后找到菜单项"Exceptions ..",请检查C ++异常以在抛出时中断,然后通过调试器运行应用程序.

希望这应该为您提供异常的来源.异常本身很可能是由于指针未指向属于您的程序的内存引起的.

您的调用和正在调用的函数的代码示例可能会有所帮助.


我真正需要的最终结果只是单词的含义.因此,我加载了特定的字典并得到的含义.这些函数需要CStrings作为输入,并创建一个据我所知从CObject派生的对象.
您确实需要了解库函数才能使用它们.您的描述似乎有点含糊.您有任何文档吗?


我检查了c ++部分,但在msvcr100d.dll中仍然出现异常
这是代码的细分...
我在dll cpp中创建的全局变量

//class
    template <class T>
    class less_locale
    {
    public:
        bool operator() (const T& s1, const T& s2)
        {
            return (wcsicoll(s1.c_str(), s2.c_str()) < 0);
        }
    };
//declarations
    //dictionary stuff
    CLexiconObject *lexObject;
    CLexManagement *lexMng = new CLexManagement;
    CLexDataBase *lexDB;
    //parameters and typeders
    static const int PARAM_COUNT = 3;//CLexIndexFileBase::PARAM_COUNT;
    CString paramName[PARAM_COUNT],param[PARAM_COUNT];
    int paramType[PARAM_COUNT];
    typedef multimap<wstring, int, less_locale<wstring> > MultimapKeyWord;
    //word finding stuff
    CString wordToSearch;
    CString xo;
    vector<int> wordAppearancesVector;
    MultimapKeyWord keyWordTable;
    vector<WordEntry> mWordEntryVector;
    CLexSourceFileBase *lexSourceFile;
    CLexIndexFileBase *lexIndexFile;
    vector<CString> langstore;

//globals i created to help returning stuff 
    CString retmessage = _T(" ");
    char * retloaded = new char; //used to return value for function load dictionary
    wchar_t* testing = new wchar_t; // used to return value for function findword



我制作的功能...该功能的主体来自于我在源代码中观察到的内容

char * loaddictionary(CString m_FileName,CString pathName, CString m_DictionaryName, CString language1, CString language2, int type, int* wlen)
{
    lexObject = lexMng->CreateNewObject(type,language1);
    lexObject->SetSourceFileName(m_FileName);
    lexObject->SetSourceFilePath(pathName);
    lexObject->SetName(m_DictionaryName);
    for(int i=0; i < PARAM_COUNT; i++)
        lexObject->GetIndexFile()->SetParam(i, param[i]);


    BOOL OK = lexObject->GetSourceFile()->Open(pathName);//m_FileName);
    if (OK)
    {
        lexObject->GetSourceFile()->Analyse();

        int result = lexObject->GetIndexFile()->LoadNew(lexObject->GetSourceFile());
        if (result == CLexIndexFileBase::LOADING_PENDING)
        {
            CString str;
            lexObject->GetIndexFile()->GetProgressMessage(str);

            CString keyw=_T("Reading keywords...");
            CString writin=_T("Writing index file...");

            char *toshow = (char *)(LPCTSTR)(str);
            for(int i=0;i<str.GetLength();i++)
            cout<<*(toshow+(i*2));
            cout<<endl;
            while(str==keyw)
            {
                int progress = lexObject->GetIndexFile()->GetProgress();
                cout<<progress<<"...";
                //for(int i=0;i<100;i++);
                cout<<''\xd'';

                lexObject->GetIndexFile()->GetProgressMessage(str);
            }
            cout<<"done"<<endl;

                lexObject->GetIndexFile()->GetProgressMessage(str);
            toshow = (char *)(LPCTSTR)(str);
            for(int i=0;i<str.GetLength();i++)
            cout<<*(toshow+(i*2));
            cout<<endl;
        //  lexObject->GetIndexFile()->IsLoadingOver(result);
        for(int i=0;i<1000;i++)
        {
             int progress = lexObject->GetIndexFile()->GetProgress();
                cout<<progress<<"...";
                //for(int i=0;i<100;i++);
                cout<<''\xd'';

                lexObject->GetIndexFile()->GetProgressMessage(str);
         }
        lexObject->GetIndexFile()->IsLoadingOver(result);
        if(result)
        {
            cout<<"done"<<endl;
            str=_T("Loaded");
        }
        else
        {
            cout<<"not done"<<endl;
            str=_T("Not Loaded");
        }
        memcpy(retloaded,str,(str.GetLength())*2);
        *wlen=str.GetLength();


        }
        else if (result != CLexIndexFileBase::LOADING_SUCCESSFUL)
        {
            lexMng->Delete(lexObject);
            lexObject = NULL;

            xo=_T("Loading Unsuccessful");
            *wlen=xo.GetLength();

            memcpy(retloaded,xo,(xo.GetLength())*2);
        }
        else
        {
            xo=_T("Loading Successful");
            memcpy(retloaded,xo,(xo.GetLength())*2);
            *wlen=xo.GetLength();
            }
        storelangind(language1,language2);
    }
    else
    {
        lexMng->Delete(lexObject);
        lexObject = NULL;
        xo=_T("No such File");
        memcpy(retloaded,xo,(xo.GetLength())*2);
        *wlen=xo.GetLength();

    }

    return retloaded;
}


wchar_t* findword(CString aWordToSearch,int* wlen)
	{
		//char *toret=new char;
		lexIndexFile = lexObject->GetIndexFile();
		lexSourceFile = lexObject->GetSourceFile();
		wordToSearch=aWordToSearch;
		BOOL completeWord = 1;
		BOOL exactMatch = 1;
        mWordEntryVector.clear();
        keyWordTable.clear();
        wordAppearancesVector.clear();
		
		int count = 0;
	
		if (wordToSearch.GetLength() > 0)
		{
			count = lexIndexFile->FindWords(wordToSearch,
                                            &wordAppearancesVector,
                                            completeWord,
                                            exactMatch);
			
			
		
			if(count>0)
			{
			int i = 0;
			CLang *lang = lexSourceFile->GetLang();
			CString tempLocale;
			lang->GetLocale(tempLocale);
			_wsetlocale(LC_ALL, tempLocale);
	        vector<int>::iterator it;
			for(it = wordAppearancesVector.begin(); it < wordAppearancesVector.end(); it++)
			{
				int entryLine = *it;
				CString entryWord = lexSourceFile->GetHeadWord(*it, wordToSearch);

				if (entryWord!= _T(""))
				{
					wstring wstr(entryWord.GetBuffer());
				

					keyWordTable.insert(pair<wstring, int>(wstr, entryLine));
				}
			}
			_wsetlocale(LC_ALL, L"C");
			vector<WordEntry>::iterator its;

			MultimapKeyWord::iterator mm_it = keyWordTable.begin();
			lexSourceFile->GetWordEntryAt(mm_it->second,
                                      mWordEntryVector);

			its = mWordEntryVector.begin();
			CString orig = (*its).meaning;

			retmessage = orig;
 *wlen=orig.GetLength();
			
	
			}
			else
			{
				xo=_T("no meaning found");
					
			memcpy(retmessage,xo,(xo.GetLength())*2);
				retmessage = xo;
			*wlen=xo.GetLength();
			}
		}
		else
		{
		xo=_T("no word entered");
	
			retmessage = xo;
		*wlen=xo.GetLength();
		}

		memcpy(testing,retmessage.GetBuffer(),retmessage.GetLength());
		wchar_t * we = retmessage.GetBuffer();
		//memcpy(testing,we,*wlen);
		for(int i=0;i<*wlen;i++)
		{
		*(testing+i) = *(we+i);
		}
		return testing;
	}


Hi,
I''ve been trying to figure out what exactly goes wrong in the application.
I basically made a sort of wrapper dll file in c++ for using "LexEngine".
lexengine
lexengine is an mfc application. from the above link, its front end is SmartLexicon.
I keep getting the following error.
Unhandled exception at 0x102e683e (msvcr100d.dll) in teenagedreams.exe:

0xC0000005: Access violation reading location 0x0065006e.



the part in bold changes usually depending on how i''m debugging.
I know i havent initialised something properly or i''m not deleting it properly. but i have no idea what.

i create a lexManagement pointer as a global. i collected the rest of the functions going through the lexview code which used lexEngine.

please help. i''ve been at this for quite a long while and i am very lost.

the end result i really need is just the meaning of a word. so i load the particular dictionary and get the meaning. the functions require CStrings as inputs and create an object that is to my knowledge derived from CObject....

解决方案

I notice that msvcr100d.dll is the debug version of an mfc dll, does this mean you are running in debug? If you are go to the Debug menu in developer studio and find the menu item "Exceptions.." check C++ exceptions to break when thrown and then run you application through the debugger.

Hopefully this should give you the source of the exception. The exception itsself is most likely caused by a pointer not pointing at memory that belongs to your program.

A code example of your call and the functions you''re calling may help.


"the end result i really need is just the meaning of a word. so i load the particular dictionary and get the meaning. the functions require CStrings as inputs and create an object that is to my knowledge derived from CObject...."

You really need to understand the library functions to use them. Your description seems a bit vague. Do you have any documentation?


i checked the c++ part but the exception still occurs in msvcr100d.dll
here''s a breakdown of the code...
globals i created in the dll cpp

//class
    template <class T>
    class less_locale
    {
    public:
        bool operator() (const T& s1, const T& s2)
        {
            return (wcsicoll(s1.c_str(), s2.c_str()) < 0);
        }
    };
//declarations
    //dictionary stuff
    CLexiconObject *lexObject;
    CLexManagement *lexMng = new CLexManagement;
    CLexDataBase *lexDB;
    //parameters and typeders
    static const int PARAM_COUNT = 3;//CLexIndexFileBase::PARAM_COUNT;
    CString paramName[PARAM_COUNT],param[PARAM_COUNT];
    int paramType[PARAM_COUNT];
    typedef multimap<wstring, int, less_locale<wstring> > MultimapKeyWord;
    //word finding stuff
    CString wordToSearch;
    CString xo;
    vector<int> wordAppearancesVector;
    MultimapKeyWord keyWordTable;
    vector<WordEntry> mWordEntryVector;
    CLexSourceFileBase *lexSourceFile;
    CLexIndexFileBase *lexIndexFile;
    vector<CString> langstore;

//globals i created to help returning stuff 
    CString retmessage = _T(" ");
    char * retloaded = new char; //used to return value for function load dictionary
    wchar_t* testing = new wchar_t; // used to return value for function findword



the functions i made... the body of the function is taken from what i observed going on in the source stuff

char * loaddictionary(CString m_FileName,CString pathName, CString m_DictionaryName, CString language1, CString language2, int type, int* wlen)
{
    lexObject = lexMng->CreateNewObject(type,language1);
    lexObject->SetSourceFileName(m_FileName);
    lexObject->SetSourceFilePath(pathName);
    lexObject->SetName(m_DictionaryName);
    for(int i=0; i < PARAM_COUNT; i++)
        lexObject->GetIndexFile()->SetParam(i, param[i]);


    BOOL OK = lexObject->GetSourceFile()->Open(pathName);//m_FileName);
    if (OK)
    {
        lexObject->GetSourceFile()->Analyse();

        int result = lexObject->GetIndexFile()->LoadNew(lexObject->GetSourceFile());
        if (result == CLexIndexFileBase::LOADING_PENDING)
        {
            CString str;
            lexObject->GetIndexFile()->GetProgressMessage(str);

            CString keyw=_T("Reading keywords...");
            CString writin=_T("Writing index file...");

            char *toshow = (char *)(LPCTSTR)(str);
            for(int i=0;i<str.GetLength();i++)
            cout<<*(toshow+(i*2));
            cout<<endl;
            while(str==keyw)
            {
                int progress = lexObject->GetIndexFile()->GetProgress();
                cout<<progress<<"...";
                //for(int i=0;i<100;i++);
                cout<<''\xd'';

                lexObject->GetIndexFile()->GetProgressMessage(str);
            }
            cout<<"done"<<endl;

                lexObject->GetIndexFile()->GetProgressMessage(str);
            toshow = (char *)(LPCTSTR)(str);
            for(int i=0;i<str.GetLength();i++)
            cout<<*(toshow+(i*2));
            cout<<endl;
        //  lexObject->GetIndexFile()->IsLoadingOver(result);
        for(int i=0;i<1000;i++)
        {
             int progress = lexObject->GetIndexFile()->GetProgress();
                cout<<progress<<"...";
                //for(int i=0;i<100;i++);
                cout<<''\xd'';

                lexObject->GetIndexFile()->GetProgressMessage(str);
         }
        lexObject->GetIndexFile()->IsLoadingOver(result);
        if(result)
        {
            cout<<"done"<<endl;
            str=_T("Loaded");
        }
        else
        {
            cout<<"not done"<<endl;
            str=_T("Not Loaded");
        }
        memcpy(retloaded,str,(str.GetLength())*2);
        *wlen=str.GetLength();


        }
        else if (result != CLexIndexFileBase::LOADING_SUCCESSFUL)
        {
            lexMng->Delete(lexObject);
            lexObject = NULL;

            xo=_T("Loading Unsuccessful");
            *wlen=xo.GetLength();

            memcpy(retloaded,xo,(xo.GetLength())*2);
        }
        else
        {
            xo=_T("Loading Successful");
            memcpy(retloaded,xo,(xo.GetLength())*2);
            *wlen=xo.GetLength();
            }
        storelangind(language1,language2);
    }
    else
    {
        lexMng->Delete(lexObject);
        lexObject = NULL;
        xo=_T("No such File");
        memcpy(retloaded,xo,(xo.GetLength())*2);
        *wlen=xo.GetLength();

    }

    return retloaded;
}


wchar_t* findword(CString aWordToSearch,int* wlen)
	{
		//char *toret=new char;
		lexIndexFile = lexObject->GetIndexFile();
		lexSourceFile = lexObject->GetSourceFile();
		wordToSearch=aWordToSearch;
		BOOL completeWord = 1;
		BOOL exactMatch = 1;
        mWordEntryVector.clear();
        keyWordTable.clear();
        wordAppearancesVector.clear();
		
		int count = 0;
	
		if (wordToSearch.GetLength() > 0)
		{
			count = lexIndexFile->FindWords(wordToSearch,
                                            &wordAppearancesVector,
                                            completeWord,
                                            exactMatch);
			
			
		
			if(count>0)
			{
			int i = 0;
			CLang *lang = lexSourceFile->GetLang();
			CString tempLocale;
			lang->GetLocale(tempLocale);
			_wsetlocale(LC_ALL, tempLocale);
	        vector<int>::iterator it;
			for(it = wordAppearancesVector.begin(); it < wordAppearancesVector.end(); it++)
			{
				int entryLine = *it;
				CString entryWord = lexSourceFile->GetHeadWord(*it, wordToSearch);

				if (entryWord!= _T(""))
				{
					wstring wstr(entryWord.GetBuffer());
				

					keyWordTable.insert(pair<wstring, int>(wstr, entryLine));
				}
			}
			_wsetlocale(LC_ALL, L"C");
			vector<WordEntry>::iterator its;

			MultimapKeyWord::iterator mm_it = keyWordTable.begin();
			lexSourceFile->GetWordEntryAt(mm_it->second,
                                      mWordEntryVector);

			its = mWordEntryVector.begin();
			CString orig = (*its).meaning;

			retmessage = orig;
 *wlen=orig.GetLength();
			
	
			}
			else
			{
				xo=_T("no meaning found");
					
			memcpy(retmessage,xo,(xo.GetLength())*2);
				retmessage = xo;
			*wlen=xo.GetLength();
			}
		}
		else
		{
		xo=_T("no word entered");
	
			retmessage = xo;
		*wlen=xo.GetLength();
		}

		memcpy(testing,retmessage.GetBuffer(),retmessage.GetLength());
		wchar_t * we = retmessage.GetBuffer();
		//memcpy(testing,we,*wlen);
		for(int i=0;i<*wlen;i++)
		{
		*(testing+i) = *(we+i);
		}
		return testing;
	}


这篇关于具有C ++未处理异常的MFC DLL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆