Mixed mode managed/unmanaged dll that uses MFC problem

G

Guest

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
 
G

Guest

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... :)
 
G

Guest

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)
 
G

Guest

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.
 
G

Guest

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top