Using resource defined in MFC DLL project from ARXProject

Using resource defined in MFC DLL project from ARXProject

Anonymous
Not applicable
836 Views
7 Replies
Message 1 of 8

Using resource defined in MFC DLL project from ARXProject

Anonymous
Not applicable
Hello,

We use AutoCad Architect 2009 with ObjectARX 2009 and Visual Studio 2005 SP1.

We define in an ARX Project the function below :

void CSendingCommandsApp::AdskSendingCommands_TEST1(void)
{
CAcModuleResourceOverride temp;
CDisplay a;
a.Display();
}

In this function, we want to display a resource define in a MFC extension DLL.

void CDisplay::Display()
{
CString cs;
cs.LoadStringW(IDS_Hello);
AfxMessageBox(cs);
}

When we execute our command TEST1 in Autocad, we have an Assert in AfxWin1.inl :

_AFXWIN_INLINE HINSTANCE AFXAPI AfxGetResourceHandle()
{ ASSERT(afxCurrentResourceHandle != NULL);
return afxCurrentResourceHandle; }

Thank you for your help,
0 Likes
837 Views
7 Replies
Replies (7)
Message 2 of 8

Anonymous
Not applicable
> When we execute our command TEST1 in Autocad, we
> have an Assert in AfxWin1.inl :

Is CDisplay::Display() defined in the .arx module? Did you use the
ObjectARX wizard to create your project skeleton?
--
Owen Wengerd
President, ManuSoft <>
VP Americas, CADLock, Inc. <>
0 Likes
Message 3 of 8

Anonymous
Not applicable
Hello Owen,

Tanks for your reply.
I've found a solution, and it's work fine!! But now, I've another problem when I try to load a DialogBoxe defined in my MFC dll...
To answer, your question, yes I use the ObjectARX wizard to create my project skeleton and The CDisplay::Display() method is defined in my MFC DLL module.

First, that is what I have done (if it could help someone else...) :

In my ARX module :
------------------

void CSendingCommandsApp::AdskSendingCommands_TEST1(void)
{
CAcModuleResourceOverride temp;
CDisplay a;
a.Display(acedGetAcadResourceInstance(), acedGetAcadFrame() );
}

In my MFC DLL module :
--------------------

In the CDisplay.h file :

static HINSTANCE hInstanceSafe;

In the entry point of my MFC DLL module :

DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
{
CDisplay::hInstanceSafe = hInstance;
...
...

}


In the CDisplay.cpp file :

HINSTANCE CDisplay::hInstanceSafe = NULL;
void CDisplay::Display( HINSTANCE h, CWnd* pParent )
{
AfxSetResourceHandle( hInstanceSafe );

CString cs;
cs.LoadStringW(IDS_Bonjour);
AfxMessageBox(cs);

AfxSetResourceHandle( h );
}


The Step2, and my real goal, is to display a DialogBoxe, defined in my MFC DLL module.
I've tried all solutions I've found on the net, but nothing work for me.

Now, when I call DoModal(), I have an Assert in objcore.cpp :

BOOL CObject::IsKindOf(const CRuntimeClass* pClass) const
{
ENSURE(this != NULL);
// it better be in valid memory, at least for CObject size
ASSERT(AfxIsValidAddress(this, sizeof(CObject)));
...
...
}

That is what I have done :

In my ARX module :
------------------

void CSendingCommandsApp::AdskSendingCommands_TEST1(void)
{
CAcModuleResourceOverride temp;

CDisplay a;
a.Display( acedGetAcadResourceInstance(), acedGetAcadFrame() );
}

In my MFC DLL :
--------------

void CDisplay::Display( HINSTANCE h, CWnd* pParent )
{
AfxSetResourceHandle( hInstanceSafe );

CDlgBidon* pDlg = new CDlgBidon( pParent );
pDlg->DoModal();
pDlg->DestroyWindow();
delete pDlg;

/*CString cs;
cs.LoadStringW(IDS_Bonjour);
AfxMessageBox(cs);*/

AfxSetResourceHandle( h );
}

What's going wrong??

Thanks for your help,

Sophie D.
0 Likes
Message 4 of 8

Anonymous
Not applicable
Having this problem in debug builds, release builds, or both?

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2009
Supporting AutoCAD 2000 through 2009

http://www.acadxtabs.com

Introducing AcadXTabs 2010:
http://www.caddzone.com/acadxtabs/AcadXTabs2010.htm

wrote in message news:5961074@discussion.autodesk.com...
Hello Owen,

Tanks for your reply.
I've found a solution, and it's work fine!! But now, I've another problem when I try to load a DialogBoxe defined in my MFC dll...
To answer, your question, yes I use the ObjectARX wizard to create my project skeleton and The CDisplay::Display() method is defined in my MFC DLL module.

First, that is what I have done (if it could help someone else...) :

In my ARX module :
------------------

void CSendingCommandsApp::AdskSendingCommands_TEST1(void)
{
CAcModuleResourceOverride temp;
CDisplay a;
a.Display(acedGetAcadResourceInstance(), acedGetAcadFrame() );
}

In my MFC DLL module :
--------------------

In the CDisplay.h file :

static HINSTANCE hInstanceSafe;

In the entry point of my MFC DLL module :

DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
{
CDisplay::hInstanceSafe = hInstance;
...
...

}


In the CDisplay.cpp file :

HINSTANCE CDisplay::hInstanceSafe = NULL;
void CDisplay::Display( HINSTANCE h, CWnd* pParent )
{
AfxSetResourceHandle( hInstanceSafe );

CString cs;
cs.LoadStringW(IDS_Bonjour);
AfxMessageBox(cs);

AfxSetResourceHandle( h );
}


The Step2, and my real goal, is to display a DialogBoxe, defined in my MFC DLL module.
I've tried all solutions I've found on the net, but nothing work for me.

Now, when I call DoModal(), I have an Assert in objcore.cpp :

BOOL CObject::IsKindOf(const CRuntimeClass* pClass) const
{
ENSURE(this != NULL);
// it better be in valid memory, at least for CObject size
ASSERT(AfxIsValidAddress(this, sizeof(CObject)));
...
...
}

That is what I have done :

In my ARX module :
------------------

void CSendingCommandsApp::AdskSendingCommands_TEST1(void)
{
CAcModuleResourceOverride temp;

CDisplay a;
a.Display( acedGetAcadResourceInstance(), acedGetAcadFrame() );
}

In my MFC DLL :
--------------

void CDisplay::Display( HINSTANCE h, CWnd* pParent )
{
AfxSetResourceHandle( hInstanceSafe );

CDlgBidon* pDlg = new CDlgBidon( pParent );
pDlg->DoModal();
pDlg->DestroyWindow();
delete pDlg;

/*CString cs;
cs.LoadStringW(IDS_Bonjour);
AfxMessageBox(cs);*/

AfxSetResourceHandle( h );
}

What's going wrong??

Thanks for your help,

Sophie D.
0 Likes
Message 5 of 8

Anonymous
Not applicable
Hi Tony,

I've this problem on both debug and release builds.

Sophie.
0 Likes
Message 6 of 8

Anonymous
Not applicable
Elcom,

Have you added this macro prior to running you function?

myFunction()
{
MFC_RESOURCE_INIT;

do_it_now();

}



Regards Gary.

www.drcauto.com



wrote in message news:5961074@discussion.autodesk.com...
Hello Owen,

Tanks for your reply.
I've found a solution, and it's work fine!! But now, I've another problem
when I try to load a DialogBoxe defined in my MFC dll...
To answer, your question, yes I use the ObjectARX wizard to create my
project skeleton and The CDisplay::Display() method is defined in my MFC DLL
module.

First, that is what I have done (if it could help someone else...) :

In my ARX module :
------------------

void CSendingCommandsApp::AdskSendingCommands_TEST1(void)
{
CAcModuleResourceOverride temp;
CDisplay a;
a.Display(acedGetAcadResourceInstance(), acedGetAcadFrame() );
}

In my MFC DLL module :
--------------------

In the CDisplay.h file :

static HINSTANCE hInstanceSafe;

In the entry point of my MFC DLL module :

DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
{
CDisplay::hInstanceSafe = hInstance;
...
...

}


In the CDisplay.cpp file :

HINSTANCE CDisplay::hInstanceSafe = NULL;
void CDisplay::Display( HINSTANCE h, CWnd* pParent )
{
AfxSetResourceHandle( hInstanceSafe );

CString cs;
cs.LoadStringW(IDS_Bonjour);
AfxMessageBox(cs);

AfxSetResourceHandle( h );
}


The Step2, and my real goal, is to display a DialogBoxe, defined in my MFC
DLL module.
I've tried all solutions I've found on the net, but nothing work for me.

Now, when I call DoModal(), I have an Assert in objcore.cpp :

BOOL CObject::IsKindOf(const CRuntimeClass* pClass) const
{
ENSURE(this != NULL);
// it better be in valid memory, at least for CObject size
ASSERT(AfxIsValidAddress(this, sizeof(CObject)));
...
...
}

That is what I have done :

In my ARX module :
------------------

void CSendingCommandsApp::AdskSendingCommands_TEST1(void)
{
CAcModuleResourceOverride temp;

CDisplay a;
a.Display( acedGetAcadResourceInstance(), acedGetAcadFrame() );
}

In my MFC DLL :
--------------

void CDisplay::Display( HINSTANCE h, CWnd* pParent )
{
AfxSetResourceHandle( hInstanceSafe );

CDlgBidon* pDlg = new CDlgBidon( pParent );
pDlg->DoModal();
pDlg->DestroyWindow();
delete pDlg;

/*CString cs;
cs.LoadStringW(IDS_Bonjour);
AfxMessageBox(cs);*/

AfxSetResourceHandle( h );
}

What's going wrong??

Thanks for your help,

Sophie D.
0 Likes
Message 7 of 8

Anonymous
Not applicable
Hello Gary,

Thanks for your reply, but could you be more clear please? I don't understand what you suggest me to do. What is this macro MFC_RESOURCE_INIT? I don't find it.

Regards,
0 Likes
Message 8 of 8

Anonymous
Not applicable
Sophie,

Sorry about that was one of ours!

I think your problem is here.


DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
{
CDisplay::hInstanceSafe = hInstance;
...
...

}


You don't appear to be initializing it!

Try this!
DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
{
if (dwReason == DLL_PROCESS_ATTACH) {

_hdllInstance = hInstance;

// CDisplay initialization

CDisplay::SetDefaultResource(_hdllInstance);

}

..................

}

Regards Gary.
www.drcauto.com


wrote in message news:5962236@discussion.autodesk.com...
Hello Gary,

Thanks for your reply, but could you be more clear please? I don't
understand what you suggest me to do. What is this macro MFC_RESOURCE_INIT?
I don't find it.

Regards,
0 Likes