Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / July 2004

Tip: Looking for answers? Try searching our database.

Mixed mode managed/unmanaged dll that uses MFC problem

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
- 29 Jul 2004 12:39 GMT
I am stuck in a situation and I do believe that this should work, but it
doesn't.

I have a unmanaged dll, that uses MFC. This works great.

Now I recompile the unmanaged dll so it contains mixed mode
managed/unmanaged code, but only use unmanaged code, but this gives a error
the moment I want to display a MFC dialog box: Something like unreferenced
object,... during runtime.

If I disable this dialogbox, then de code works fine.

Now in a final step, I want to use managed dll's that contains mixed
managed/unmanaged code also using MFC.
It all works fine until I compile with a managed class to be instanciated
durin runtime. This makes my dll terminate the moment I start using that
function with the containing managd class.

I guess that I must initialize something, call some initialization function
when the dll loads?
Does anyone have sompe links or tips in order to fix this problem once and
for all?

I use VC# 2003 and VC++ 2003 standard edition.
Thanks
- 29 Jul 2004 13:06 GMT
> Now I recompile the unmanaged dll so it contains mixed mode
> managed/unmanaged code, but only use unmanaged code, but this gives a error
> the moment I want to display a MFC dialog box: Something like unreferenced
> object,... during runtime.

AHA! part of the mysterie solved, in order to use the mixed mode I reverted
to MFC in dll instead of static linking. So I need this macro in the
function that needs to call the dialog:
AFX_MANAGE_STATE(AfxGetStaticModuleState());

One small step closer to solving the biggest mysterie in my life. :-)

Next problem... :-)
- 29 Jul 2004 14:18 GMT
> Now in a final step, I want to use managed dll's that contains mixed
> managed/unmanaged code also using MFC.
> It all works fine until I compile with a managed class to be instanciated
> durin runtime. This makes my dll terminate the moment I start using that
> function with the containing managd class.

As far as I can test, using the functonality standard from .NET 1.1 seems to
work normally, only when I call a managed class created in another C++
managed dll that uses MFC code. I keep on testing.

This works:
BOOL CRotate2DFlt::Execute(IPlgProgress &pr ) {
   System::String *sTemp=__gc new System::String("");
}

But his doesnt:

BOOL CRotate2DFlt::Execute(IPlgProgress &pr ) {
   SkyscanLibBase::Dataset* test=__gc new SkyscanLibBase::Dataset();
}

It terminates my function and dll even before I could reach the break point
at the very beginning of the function.
(SkyscanLibBase is a VC++ 2003 managed dll that uses MFC as dll, and this
dll works perfect on C# projects)
- 30 Jul 2004 09:27 GMT
I managed to put a breakpoint here and I get an exception when I start to
execute that function.

The message is: " Message "Request for the permission of type
System.Security.Permissions.
                         StrongNameIdentityPermission, mscorlib,
Version=1.0.5000.0, Culture=neutral,
                         PublicKeyToken=b77a5c561934e089 failed." String*
The Source is: "error: an exception of type: 0x02623f18 occurred"

Any idea what that could mean?
Strange because when I use System::String directly no problem.
> > Now in a final step, I want to use managed dll's that contains mixed
> > managed/unmanaged code also using MFC.
[quoted text clipped - 21 lines]
> (SkyscanLibBase is a VC++ 2003 managed dll that uses MFC as dll, and this
> dll works perfect on C# projects)
- 30 Jul 2004 13:07 GMT
It seems to be a monolog, but I found the problem.

Two problems are causing it, one is related to not finding the correct .NET
dll's that are in that same folder, and is solved by moving the .NET dll's
to the GAC.
But I don't like this, so and so far forcing the current directory to the
folder of the first .NET dll does not solve the problem of finding the other
.NET dll's.
What happens is that a pure unmanaged exe file dynamically loads a mixed
mode managed/unmanaged dll which in turn loads another .NET dll.

The second problem was the fact that the caller dll, was not code signed but
the class that I wanted to load from the second dll expected a linkdemand of
that code.

[StrongNameIdentityPermission( SecurityAction.InheritanceDemand,
PublicKey="002...")]
[StrongNameIdentityPermission( SecurityAction.LinkDemand,
PublicKey="002...")]
public sealed class Element:IEnumerable, IComparable

Creating an assembly.cpp file and signing with the same key and everything
was working.
> I managed to put a breakpoint here and I get an exception when I start to
> execute that function.
[quoted text clipped - 36 lines]
> > (SkyscanLibBase is a VC++ 2003 managed dll that uses MFC as dll, and this
> > dll works perfect on C# projects)

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.