إعداد واجهة مخصصة مكتوبة في C ++ / CLI إلى NULL قد يؤدي إلى تعطل البرنامج

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

سؤال

لدي واجهة مخصصة مكتوبة في C ++ / CLI: giveacodicetagpre.

في تطبيقي C #، يتم استخدام الواجهة من قبل: giveacodicetagpre.

يتم تشغيل التعليمات البرمجية أعلاه بسلاسة في جهاز الكمبيوتر الخاص بي (والتي قمت بتثبيت Visual Studio) ولكنها تعطلت في واحدة أخرى (دون تثبيت Visual Studio): giveacodicetagpre.

إذا قمت بإزالة المهمة الخالية، فسيتم تشغيل الرمز في كلا الكمبيوتر: giveacodicetagpre.

ومع ذلك، قمت بواجهة أخرى في C #. لن يقوم إعداد الواجهة إلى NULL بعدم تحطم البرنامج: giveacodicetagpre.

ما هو الخطأ في واجهة C ++ / CLI الخاصة بي؟

[ملاحظات]

لقد قمت بإنشاء مشاريع جديدة "نظيفة" جديدة للاختبار، أول واحد مكتبة فئة C ++ / CLI (مشروع جديد -> Visual C ++ -> CLR -> مكتبة الدرجة). أضف الأسطر التالية إلى ملف .h للمكتبة: giveacodicetagpre.

ثم قم بإنشاء مشروع تطبيق نموذج Windows (مشروع صافي -> Visual C # -> تطبيق Windows -> تطبيق نماذج Windows) وتعلن وجود متغير أشد في الوظيفة الرئيسية: giveacodicetagpre.

سيعمل البرنامج في جهاز الكمبيوتر التطوير (تثبيت 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