473,378 Members | 1,631 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Mixed mode managed/unmanaged dll that uses MFC problem

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

Nov 17 '05 #1
4 2140
> 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... :-)
Nov 17 '05 #2
> 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)
Nov 17 '05 #3
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.

<Ol**********@skyscan.be> wrote in message
news:41**********************@news.skynet.be...
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)

Nov 17 '05 #4
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.
<Ol**********@skyscan.be> wrote in message
news:41*********************@news.skynet.be...
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.

<Ol**********@skyscan.be> wrote in message
news:41**********************@news.skynet.be...
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)


Nov 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Yoni Rabinovitch | last post by:
Hi, We have a large code base of "regular" C++ code (not MFC, COM or ATL). With VC6.0, we used to compile the "regular" C++ code as static libraries (.lib files), and then we would link the...
5
by: Adam McKee | last post by:
We are using Visual Studio.NET 2003 in our project with .NET framework 1.1. One of our libraries is a mixed-mode dll assembly consisting of one managed C++ library, and several unmanaged C++...
9
by: Edward Diener | last post by:
I received no answers about this the first time I posted, so I will try again. My inability to decipher an MSDN topic may find others who have the same inability and someone who can decipher and...
0
by: Anna | last post by:
Hi, (Initial info: .Net 2003 on Win2000) I'm developing a .Net App that uses a dll (say, dll_1) created in VC6 and _successfully_ recompiled in .Net 2003 (unmanaged, no wrappers). The dll_1...
8
by: Nadav | last post by:
Hi, I am writing a performence critical application, this require me to stick to unmanaged C++ as performance is much better using unmanaged C++ ( about 33% better ), Still, I am trying to avoid...
6
by: Robert Ginsburg | last post by:
I have a DLL that is "mixed mode" in that it is both an ATL com server and a reference managed C++ class. For the most part it works, however the problem I have (which may simply not be solvable)...
4
by: Lonewolf | last post by:
hi, I'm still in the process of transiting from MFC/VC6 to vs2005, and a lot of things are very alien to me. So hope you could bear with me if my question sounds stupid. Basically I have native...
3
by: Mali Guven | last post by:
Hello, I have a native DLL (written in C) which is supposed to call a managed DLL (was written in C#, and an entry point was injected modifying the ildasm'd code). The exectuable calls the...
0
by: Arne Adams | last post by:
Hi all, i have a managed c++ dll using both managed and unmanaged code and an unmanaged application that calls the unmanaged code of the managed dll. I did follow...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.