Re: calls to unmanaged dll to create a socket result in debug assertio
- From: Joseph M. Newcomer <newcomer@xxxxxxxxxxxx>
- Date: Fri, 18 Aug 2006 16:10:09 -0400
You have selected an extension DLL and then used AFX_MANAGE_STATE, which is incompatible.
An MFC Extension DLL can *only* be used with an MFC application, not a C# application,
which is what I said: don't use an extension DLL. Use a regular DLL.
joe
On 18 Aug 2006 07:37:19 -0700, "moniqui" <doreen.spalter@xxxxxxxx> wrote:
Joseph,Joseph M. Newcomer [MVP]
Thanks for the reply...I have tried to make use of the AFX_MANAGE_STATE
macro, but when I use it, I get Dllmain linking errors which I think
are explained in this msdn article:
http://support.microsoft.com/kb/q161589/
Do you know of any way to work around this problem?
Thanks,
Doreen
Joseph M. Newcomer wrote:
Read the code for AfxGetInstanceHandle. It is pretty magic, and it assumes that certain
pieces of code are well-behaved. For example, it assumes that in an extension DLL, you
should be getting the handle of the main app from AfxGetInstanceHandle . Since you're
calling an MFC Extension DLL from C#, it isn't an extension DLL; so when it tries to find
the instance handle of the MFC app it is extending, that app isn't there, and it fails. A
regular DLL should result in AfxGetInstanceHandle returning the actual instance handle of
the DLL, and you probably have to use the AFX_MANAGE_STATE macros to make that work right.
joe
On Thu, 17 Aug 2006 10:32:02 -0700, moniqui <moniqui@xxxxxxxxxxxxxxxxx> wrote:
I have an unmanaged C++ dll which is an MFC shared DLL that has functions inJoseph M. Newcomer [MVP]
it to initialize sockets and do other ethernet related things. I have built a
managed C++ wrapper project which is also an MFC shared DLL, compiled with
/clr that calls functions in the unmanaged dll. Then I have a C# project
which instantiates a member of the wrapper class to access the unmanaged
functions.
One of the functions in the unmanaged dll creates a new CAsyncSocket, checks
to see if AfxSocketInit is successful, and if so, calls Create to create a
new socket. When I call this function through my wrapper from C#, I get a
debug assertion when Create is called. The call stack trace indicates that
the problem is in a call to AfxGetInstanceHandle.
I've done a lot of reading about the use of AfxGetInstanceHandle, but I can
still not find any solution to this problem.
Within the unmanaged code, in the DllMain procedure, I see the following
comment:
// Insert this DLL into the resource chain
// NOTE: If this Extension DLL is being implicitly linked to by
// an MFC Regular DLL (such as an ActiveX Control)
// instead of an MFC application, then you will want to
// remove this line from DllMain and put it in a separate
// function exported from this Extension DLL. The Regular DLL
// that uses this Extension DLL should then explicitly call that
// function to initialize this Extension DLL. Otherwise,
// the CDynLinkLibrary object will not be attached to the
// Regular DLL's resource chain, and serious problems will
// result.
new CDynLinkLibrary(MITTDLL);
// Sockets initialization
// NOTE: If this Extension DLL is being implicitly linked to by
// an MFC Regular DLL (such as an ActiveX Control)
// instead of an MFC application, then you will want to
// remove the following lines from DllMain and put them in a separate
// function exported from this Extension DLL. The Regular DLL
// that uses this Extension DLL should then explicitly call that
// function to initialize this Extension DLL.
if (!AfxSocketInit())
{
return FALSE;
}
This seems to have something to do with my problem since my managed DLL is
an MFC DLL, but I'm not quite sure what this comment is saying - I think it
is generated code by the wizard...
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.
- References:
- Re: calls to unmanaged dll to create a socket result in debug assertio
- From: Joseph M . Newcomer
- Re: calls to unmanaged dll to create a socket result in debug assertio
- From: moniqui
- Re: calls to unmanaged dll to create a socket result in debug assertio
- Prev by Date: Re: edit control problem
- Next by Date: Re: Reading symbol table
- Previous by thread: Re: calls to unmanaged dll to create a socket result in debug assertio
- Next by thread: New essay: Avoiding EN_CHANGE
- Index(es):
Relevant Pages
|