C ++ / CLI로 작성된 사용자 정의 인터페이스 설정은 프로그램이 중단 될 수 있습니다.

StackOverflow https://stackoverflow.com/questions/6042957

문제

C ++ / CLI로 작성된 사용자 정의 .NET 인터페이스가 있습니다.

public interface class IBackgroundExtractor
{
};
.

내 C # 응용 프로그램에서 인터페이스가 사용됩니다 :

private IBackgroundExtractor extractor = null;
.

위의 코드는 내 컴퓨터에서 원활하게 실행되지만 (Visual Studio)하지만 (Visual Studio 설치하지 않고도) 다른 하나는 다른 하나에서 충돌했습니다.

AppName: speedtest.exe   AppVer: 1.0.0.0     ModName: kernel32.dll
ModVer: 5.1.2600.5512    Offset: 00012aeb
.

널 할당을 제거하면 코드가 두 컴퓨터에서 실행됩니다.

private IBackgroundExtractor extractor;
.

그러나 순수한 C #에서 다른 인터페이스를 만들었습니다. 인터페이스를 null로 설정하면 프로그램이 크래시되지 않습니다.

interface IAnotherInterface
{
}
private IAnotherInterface test = null;
.

C ++ / CLI 인터페이스에서는 무엇이 잘못 되었습니까?

[비고]

테스트를 위해 두 개의 '깨끗한'새 프로젝트를 만들어 첫 번째는 C ++ / CLI 클래스 라이브러리 (새 프로젝트 -> Visual C ++ -> CLR -> 클래스 라이브러리)입니다. 라이브러리의 .h 파일에 다음 줄을 추가하십시오.

public interface class ITest {
};
. 그런 다음 Windows Form Application Project (Net Project -> Visual C # -> Windows -> Windows Forms 응용 프로그램)를 만듭니다. 주요 함수에서 가장 idest 변수를 선언합니다.
static void Main()
{
    Application.EnableVisualStyles();
    Application.SetCompatibleTextRenderingDefault(false);
    Application.Run(new Form1());

    ITest xxx = null;
}
.

프로그램은 개발 컴퓨터 (Visual Studio 설치)에서 실행되지만 두 컴퓨터에서는 충돌이 발생합니다. 추락 된 컴퓨터 중 하나는 물리적 인 컴퓨터이며 다른 하나는 가상 컴퓨터입니다.

Windows XP Pro SP3, Visual Studio 2010 및 .NET Framework 4.0을 사용하고 있습니다.

도움이 되었습니까?

해결책

Have you checked to make sure the right version of the Microsoft Visual C++ Runtime is installed on the target machines? (Your development environment will already have this installed, but no current version of Windows includes this runtime by default).

If you set up your C++/CLI project to use "SAFE" mode, it will not reference the Microsoft Visual c++ runtime at all (just .NET). See this for reference: Pure and Verifiable Code. If you need to do native stuff, then there's a very high chance that you need to have the latest Visual C++ runtime installed. You can pick up the redistributable here: Microsoft Visual C++ 2010 Redistributable Package.

If you want to verify that this is the problem, you can use the sxstrace tool to diagnose these issues (helpful tutorial).

다른 팁

The null assigment is probably not the error but the trigger for the error. This assigment to null is probably first line of code that accesses that the C++/CLI assembly. So before the that null assigment is even executed, the unmanaged part of C++/CLI assembly is initialized. That is probably where the error is occuring.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top