I have an MFC application that uses several MFC extension DLL's. I want this app (and several other similar apps) to be able to access some parts of the .net framework. I wrote a C# library to do the .net work I want and was hoping to be able to write an MFC dll to hide all the C++/CLI code from my apps. The apps would stay as pure MFC apps and the only C++/CLI code would be in my new MFX extension DLL. However when I did this the apps crashed when accessing the new MFC C++/CLI dll. If I put the C++/CLI code in the apps it works ok and I can debug my way all the way in to the C#.
我有一个使用几个MFC扩展DLL的MFC应用程序。我希望这个应用程序(以及其他几个类似的应用程序)能够访问.net框架的某些部分。我写了一个C#库来完成我想要的.net工作,并希望能够编写一个MFC DLL来隐藏我的应用程序中的所有C ++ / CLI代码。应用程序将保留为纯MFC应用程序,唯一的C ++ / CLI代码将在我的新MFX扩展DLL中。但是当我这样做时,应用程序在访问新的MFC C ++ / CLI dll时崩溃了。如果我将C ++ / CLI代码放在应用程序中它可以正常工作,我可以调试我的方式一直到C#。
Does anyone understand why the dll idea doesn't work?
有谁理解为什么dll的想法不起作用?
Thanks
3 个解决方案
#1
1
You can't reference managed assemblies from pure native code. You have to either flip the /clr switch on the consumer (either project-wide or in certain files,) or do some interop.
您无法从纯本机代码引用托管程序集。您必须在消费者(项目范围或某些文件)中翻转/ clr开关,或者进行一些互操作。
One interop option that will allow your consumer to say pure native is calling into the managed assembly via COM Callable Wrapper.
一个允许您的消费者说纯本机的互操作选项是通过COM Callable Wrapper调用托管程序集。
#2
1
I believe I have run into a similar problem. My setup was similar - A pure MFC app with a pure MFC DLL which in turn interacted with the C++/CLI DLL. Everything would run fine, but it would crash on exit. The problem was exacerbated while testing the pure MFC DLL using CppUnit.
我相信我遇到了类似的问题。我的设置类似 - 纯MFC应用程序与纯MFC DLL,后者又与C ++ / CLI DLL交互。一切都会运行良好,但退出时会崩溃。使用CppUnit测试纯MFC DLL时,问题更加严重。
On debugging, I found out that due to a bug, my C++ code was throwing first-chance exceptions for access violations (objects referenced via a dangling pointer) on exit. Now, the C++ runtime ignores these violations on exit, whereas the CLR does not. The CLR runtime throws an unhandled exception making it appear that the program / unit-test crashed.
在调试时,我发现由于一个错误,我的C ++代码在退出时抛出了访问冲突(通过悬空指针引用的对象)的第一次机会异常。现在,C ++运行时在退出时忽略这些违规,而CLR则不会。 CLR运行时抛出一个未处理的异常,使程序/单元测试看起来崩溃。
Your problem maybe different, but it does sound quite similar to the one I had.
你的问题可能有所不同,但听起来与我的问题非常相似。
#3
0
The MFC dll project references the C# library and has one file compiled with /clr that handles the interface into my C# library. I have actually seen this work sometimes at run time but have never been able to debug into the MFC dll or into the C# code. However it doesn't seem to be at all stable and crashes in the majority of cases.
MFC DLL项目引用C#库,并有一个用/ clr编译的文件,用于处理我的C#库中的接口。我实际上有时会在运行时看到这项工作,但从来没有能够调试到MFC DLL或C#代码。然而,在大多数情况下,它似乎并不稳定和崩溃。
#1
1
You can't reference managed assemblies from pure native code. You have to either flip the /clr switch on the consumer (either project-wide or in certain files,) or do some interop.
您无法从纯本机代码引用托管程序集。您必须在消费者(项目范围或某些文件)中翻转/ clr开关,或者进行一些互操作。
One interop option that will allow your consumer to say pure native is calling into the managed assembly via COM Callable Wrapper.
一个允许您的消费者说纯本机的互操作选项是通过COM Callable Wrapper调用托管程序集。
#2
1
I believe I have run into a similar problem. My setup was similar - A pure MFC app with a pure MFC DLL which in turn interacted with the C++/CLI DLL. Everything would run fine, but it would crash on exit. The problem was exacerbated while testing the pure MFC DLL using CppUnit.
我相信我遇到了类似的问题。我的设置类似 - 纯MFC应用程序与纯MFC DLL,后者又与C ++ / CLI DLL交互。一切都会运行良好,但退出时会崩溃。使用CppUnit测试纯MFC DLL时,问题更加严重。
On debugging, I found out that due to a bug, my C++ code was throwing first-chance exceptions for access violations (objects referenced via a dangling pointer) on exit. Now, the C++ runtime ignores these violations on exit, whereas the CLR does not. The CLR runtime throws an unhandled exception making it appear that the program / unit-test crashed.
在调试时,我发现由于一个错误,我的C ++代码在退出时抛出了访问冲突(通过悬空指针引用的对象)的第一次机会异常。现在,C ++运行时在退出时忽略这些违规,而CLR则不会。 CLR运行时抛出一个未处理的异常,使程序/单元测试看起来崩溃。
Your problem maybe different, but it does sound quite similar to the one I had.
你的问题可能有所不同,但听起来与我的问题非常相似。
#3
0
The MFC dll project references the C# library and has one file compiled with /clr that handles the interface into my C# library. I have actually seen this work sometimes at run time but have never been able to debug into the MFC dll or into the C# code. However it doesn't seem to be at all stable and crashes in the majority of cases.
MFC DLL项目引用C#库,并有一个用/ clr编译的文件,用于处理我的C#库中的接口。我实际上有时会在运行时看到这项工作,但从来没有能够调试到MFC DLL或C#代码。然而,在大多数情况下,它似乎并不稳定和崩溃。