-
using dll, assertion failed afxgetthread()
I am designing a project in which am calling a function that is exported from a dll, the dll is designed by vc++ 6.0 and contains a project that is MFC application wizard based with dialog boxes and stuff.
For calling that MFC application wizard based object in my dll i have declared the application class variable of mfc based project in a function thats not a member of any predefined class and also have exported this function after including the required files.My First question is "is this method correct??"
Next I am Using this dll in My Other Language(fortran) and I am calling this function from a sub-routine in that language.I build the project without any error and whenever i execute the project I am given the error
"Debug Assertion Failed!
Program:........
File :appcore.cpp
Line:85
on debugging i got to know that the assertion thats failed is
[code]
ASSERT(AfxGetThread()==NULL);
Please help me out pf this.......
thanx
-
Re: using dll, assertion failed afxgetthread()
Run the application with debug mode (F5 key).
When the assert dialog comes, press 'Retry'.
This will take you to the code where assertion is coming.
Now trace back to your code (non-MFC's internal).
And fix the issue, or let us know what function call is being made.
-
Re: using dll, assertion failed afxgetthread()
MSDN Says: AfxGetThread() returns: Pointer to the currently executing thread; otherwise NULL.(Must be called from within the desired thread. )
Just check the place from where you are calling the function...
Thanks,
-
Re: using dll, assertion failed afxgetthread()
hi.
I guess that MFC DLL can not be call by fortran language .
Because I Call MFC DLL by delphi at one time, That's fail.
thanks
-
Re: using dll, assertion failed afxgetthread()
Quote:
MSDN Says: AfxGetThread() returns: Pointer to the currently executing thread; otherwise NULL.(Must be called from within the desired thread. )
Probably that ASSERT is placed in AfxBeginThread itself, to check if CWinThread is already attached to current thread.
-
Re: using dll, assertion failed afxgetthread()
I never used MFC dlls with any but VC++ languages, so I can only guess...
If your dll is a regular MFC dll then you have to use
Code:
AFX_MANAGE_STATE(AfxGetStaticModuleState( ))
See
http://msdn.microsoft.com/en-us/libr...tx(VS.80).aspx
http://msdn.microsoft.com/en-us/libr...f7(VS.80).aspx
http://msdn.microsoft.com/en-us/libr...84(VS.80).aspx
-
Re: using dll, assertion failed afxgetthread()
Well i have already used this macro with every function that am exporting the error remains the same....thanx anyways...please help.
-
Re: using dll, assertion failed afxgetthread()
-
Re: using dll, assertion failed afxgetthread()
Code:
#include "stdafx.h"
#include "Pflow.h"
#include "Buspropertysheet.h"
#include "MainFrm.h"
#include "ChildFrm.h"
#include "PflowDoc.h"
#include "PflowView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
__declspec(dllexport)void funcn()
{
AFX_MANAGE_STATE(AfxGetStaticModuleState())
CPflowApp theApp;
}
this is the file for my exproted function in my dll
and this is where error is shown in debug mode...
Code:
// This is a part of the Microsoft Foundation Classes C++ library.
// Copyright (C) 1992-1998 Microsoft Corporation
// All rights reserved.
//
// This source code is only intended as a supplement to the
// Microsoft Foundation Classes Reference and related
// electronic documentation provided with the library.
// See these sources for detailed information regarding the
// Microsoft Foundation Classes product.
#include "stdafx.h"
#include <malloc.h>
#ifdef AFX_CORE1_SEG
#pragma code_seg(AFX_CORE1_SEG)
#endif
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
AFX_STATIC_DATA const TCHAR _afxFileSection[] = _T("Recent File List");
AFX_STATIC_DATA const TCHAR _afxFileEntry[] = _T("File%d");
AFX_STATIC_DATA const TCHAR _afxPreviewSection[] = _T("Settings");
AFX_STATIC_DATA const TCHAR _afxPreviewEntry[] = _T("PreviewPages");
/////////////////////////////////////////////////////////////////////////////
// globals (internal library use)
// CDocManager statics are in this file for granularity reasons
BOOL CDocManager::bStaticInit = TRUE;
CDocManager* CDocManager::pStaticDocManager = NULL;
CPtrList* CDocManager::pStaticList = NULL;
BEGIN_MESSAGE_MAP(CWinApp, CCmdTarget)
//{{AFX_MSG_MAP(CWinApp)
// Global File commands
ON_COMMAND(ID_APP_EXIT, OnAppExit)
// MRU - most recently used file menu
ON_UPDATE_COMMAND_UI(ID_FILE_MRU_FILE1, OnUpdateRecentFileMenu)
ON_COMMAND_EX_RANGE(ID_FILE_MRU_FILE1, ID_FILE_MRU_FILE16, OnOpenRecentFile)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// _AFX_WIN_STATE implementation
#ifndef _AFX_NO_GRAYDLG_SUPPORT
#ifdef AFX_INIT_SEG
#pragma code_seg(AFX_INIT_SEG)
#endif
_AFX_WIN_STATE::_AFX_WIN_STATE()
{
// Note: it is only necessary to intialize non-zero data.
}
#ifdef AFX_TERM_SEG
#pragma code_seg(AFX_TERM_SEG)
#endif
_AFX_WIN_STATE::~_AFX_WIN_STATE()
{
AfxDeleteObject((HGDIOBJ*)&m_hDlgBkBrush);
}
#endif //!_AFX_NO_GRAYDLG_SUPPORT
#ifdef AFX_INIT_SEG
#pragma code_seg(AFX_INIT_SEG)
#endif
CWinApp::CWinApp(LPCTSTR lpszAppName)
{
if (lpszAppName != NULL)
m_pszAppName = _tcsdup(lpszAppName);
else
m_pszAppName = NULL;
// initialize CWinThread state
AFX_MODULE_STATE* pModuleState = _AFX_CMDTARGET_GETSTATE();
AFX_MODULE_THREAD_STATE* pThreadState = pModuleState->m_thread;
ASSERT(AfxGetThread() == NULL);
the last line the above second code is error and this part of code is contained in appcore.cpp file thats's not designed by me.
-
Re: using dll, assertion failed afxgetthread()
Code:
__declspec(dllexport)void funcn()
{
AFX_MANAGE_STATE(AfxGetStaticModuleState())
CPflowApp theApp;
}
theApp is supposed to be global variable. These must be exactly one isntance for CWinApp-derived class in your application.
By the way, what are you doing with 'theApp' object? I guess you have omitted some code. If you are willing to use 'theApp', which might be defined in other file, use extern to import that global variable in this CPP file.
Code:
extern CPflowApp theApp;
__declspec(dllexport)void funcn()
{
AFX_MANAGE_STATE(AfxGetStaticModuleState())
// Use theApp
}
-
Re: using dll, assertion failed afxgetthread()
actually am defining this app object so because as soon as this object is created my application would run, because its InitInstance is supposed to be the entry point if am not wrong??and actually this application class is of another set of class thats included in the project so i guess thier is no issue of Global variable.
The thing i wish to say is my project is in hierarchy like:
PFlowDll (MFC Application Wizard dll)
----PFlow (MFC Application Wizard exe file no exe included)
only files related to this project have been included
now am declaring the object of this PFlowApp in one of the files that i have created in PFlowDll after including the required header files.....i hope this may help that what am trying to do and also you could tell my mistakes that am doing......
thnx
-
Re: using dll, assertion failed afxgetthread()
You executable links with this DLL, right?
If so, your application will run from EXE itself.
And, if you need the CWinApp object in DLL functions, just call AfxGetApp
-
Re: using dll, assertion failed afxgetthread()
hey just leave that all above stuff and please help from here step wise.....
1.I have a project designed on VC++6.0 MFC Application Wizard (exe) format and now I changed my mind and wished that if I could Get Dll of this project so what am suppose to do??
2. I have a plan of using this dll file in one of my fortran files by importing it.
3. Now in Fortran am suppose to give a entry point function that will start the project that was in dll.So what am function can I call??
i know am making a much fuss but am sorry....please help
thank you
-
Re: using dll, assertion failed afxgetthread()
Just create a Regular MFC DLL project. Place all your files (that exports function) into new DLL project. For Fortran, I suppose, you need to export them in "C extern" calling convention.
But, as I see you are already on correct path. Why you need application instance?
You need something to do with current process, window, or anything?
-
Re: using dll, assertion failed afxgetthread()
Thanks for the motivation...
I need the application instance so as the window of the MFC project will be created and displayed
Code:
BOOL CPflowApp::InitInstance()
{
AfxEnableControlContainer();
// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.
#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif
// Change the registry key under which our settings are stored.
// TODO: You should modify this string to be something appropriate
// such as the name of your company or organization.
SetRegistryKey(_T("Local AppWizard-Generated Applications"));
LoadStdProfileSettings(); // Load standard INI file options (including MRU)
// Register the application's document templates. Document templates
// serve as the connection between documents, frame windows and views.
CMultiDocTemplate* pDocTemplate;
pDocTemplate = new CMultiDocTemplate(
IDR_PFLOWTYPE,
RUNTIME_CLASS(CPflowDoc),
RUNTIME_CLASS(CChildFrame), // custom MDI child frame
RUNTIME_CLASS(CPflowView));
AddDocTemplate(pDocTemplate);
// create main MDI Frame window
CMainFrame* pMainFrame = new CMainFrame;
if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
return FALSE;
m_pMainWnd = pMainFrame;
// Parse command line for standard shell commands, DDE, file open
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
// Dispatch commands specified on the command line
if (!ProcessShellCommand(cmdInfo))
return FALSE;
// The main window has been initialized, so show and update it.
pMainFrame->ShowWindow(m_nCmdShow);
pMainFrame->UpdateWindow();
return TRUE;
}
this is all what is called after the constructor....
-
Re: using dll, assertion failed afxgetthread()
Well.. well..
Do you need to display window that interacts to user. And you need to control that from your Fortran program? Why is that?
If you just need MFC and to display some GUI, you can just use dialog (CDialog), and display controls in it. Write code to control window in CDialog's derived class.
But if you must display entire window (SDI), I would recommend you keep the MFC project as exe only. Further to that, implement some IPC to communicate from Fortran-process to MFC-process. Choosing IPC mechanism, out of mutex, pipes, mailslots, sockets, clipboard... all depends on your requirement.
SQL Server is an example. It displays everything with client process, but performs database operations in non-GUI service (sqlserver.exe).
-
Re: using dll, assertion failed afxgetthread()
Well calling the VC Application from Fortran is my instructors need.
And yes you got that right that i need VC++ Code only to present user with the GUI.So that user interacts with the dialog boxes and else stuff.
Regarding those mutex n pipes am totally unaware of these thing, but probably these things are similar to system call i guess?? so i cant pass parameters ato these if am correct....cant it be simple??
If I use VS.NET 2003 i have heard that i can call one project from other...is that true if you have any idea about that???
-
Re: using dll, assertion failed afxgetthread()
and yes is my method of starting the GUI correct??(by declaring the object of application class)
-
Re: using dll, assertion failed afxgetthread()
So, you want us to do you your homework?
I quit then!
-
Re: using dll, assertion failed afxgetthread()
hey its not an home-work its actually a MHRD project that I was designing but since I have to leave...am suppose to do so....so that later designing part can be done also fortran packages have to be used to solved those values that are entered by the user in GUI