Happy Holidays everybody!
Hope you all have a great new .NETTING year !

Thanks Eddie.

You are right the dll was not being loaded.
But the reason was not that it was not in the right place but it was due to
a global variable being declared in the .cpp file but not declared in the .h
file. There were no compile errors (C++ is too forgiving at times) and that
in effect prevented the dll from getting loaded. All the exported functions
worked just fine.

Bye
Aman
-----Original Message-----
From: Eddie Lascu [mailto:[EMAIL PROTECTED]
Sent: Tuesday, December 21, 2004 9:09 AM
To: ADVANCED-DOTNET@DISCUSS.DEVELOP.COM
Subject: Re: [ADVANCED-DOTNET] Unmanaged MFC dll loading problem

I think your app cannot find the .dll. You need to copy the .dll (once it
was generated) in the "your_project\bin\debug" or "your_project\bin\release"
folder (based on which version you generate). Post build events can help you
with that. If you have it set up so that all executables are sent to a
working folder, you need to send your .dll there as well.
Just a side note, in the MFC .dll you need to decorate your "TestFunction"
with extern "C", 'cause otherwise it will not be exported with that name and
your C# code will not be able to call it. There is a utility that you can
use to inspect all the exported functions in a .dll. Let me see if I can
remember what is it called. Oh yeah, it's called dumpbin.
I hope this will help.
Eddie


-----Original Message-----
From: Unmoderated discussion of advanced .NET topics.
[mailto:[EMAIL PROTECTED] Behalf Of Jain, Aman
Sent: Monday, December 20, 2004 5:07 PM
To: ADVANCED-DOTNET@DISCUSS.DEVELOP.COM
Subject: [ADVANCED-DOTNET] Unmanaged MFC dll loading problem


Hi Everybody,

I have a winforms application in which I load a regular MFC dll. Even before
the InitInstance is called on the dll, there is a crash. If I select
"Ignore" on the crash the dll loads successfully and there is no problem in
using all of its exported functions. If I select "Retry", a CLR DllNotFound
exception is thrown.
 If I debug from the C++ code and select  "Retry", the stack shows that
AfxWinInit is called in which the SetCurrentHandles() crashes on the second
assert.

void CWinApp::SetCurrentHandles()
{
            ASSERT(this == afxCurrentWinApp);
            ASSERT(afxCurrentAppName == NULL);    // Crashes here
            .
            .
}

On C# side, I call the exported function as follows:

[DllImport("WaferMngr.dll")]
private static extern void TestFunction();



Thank you in advance.

Aman.



===================================
This list is hosted by DevelopMentor(r)  http://www.develop.com
Some .NET courses you may be interested in:

Essential .NET: building applications and components with C#
November 29 - December 3, in Los Angeles
http://www.develop.com/courses/edotnet

View archives and manage your subscription(s) at http://discuss.develop.com

===================================
This list is hosted by DevelopMentor(r)  http://www.develop.com
Some .NET courses you may be interested in:

Essential .NET: building applications and components with C#
November 29 - December 3, in Los Angeles
http://www.develop.com/courses/edotnet

View archives and manage your subscription(s) at http://discuss.develop.com

===================================
This list is hosted by DevelopMentorŪ  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to