タグ

Programmingとunsafeに関するItisangoのブックマーク (2)

  • string型とsbyte*型の変換 - OKWAVE

    C++」というのは「C++/CLI」のことですか? 処理系がVC 2005以降だと仮定して話を進めます。 例えば下記のようなC++/CLIの参照クラスを含むクラス ライブラリ プロジェクト「CppCliString」があったとして、 // CppCliString.h #pragma once #include <cstdio> #include <locale.h> #include <vcclr.h> // http://support.microsoft.com/kb/311259/ja using namespace System; using namespace System::Runtime::InteropServices; namespace CppCliString { public ref class Class1 { public: static void SetL

    string型とsbyte*型の変換 - OKWAVE
    Itisango
    Itisango 2020/10/26
    IntPtr ptr = Marshal.StringToHGlobalAnsi(strText); CppCliString.Class1.PutsA((sbyte*)ptr); // unsafe #dotNet
  • コンパイラ エラー CS0227 - C#

    アンセーフ コードは /unsafe でコンパイルした場合のみ有効です。 ソース コードに unsafe キーワードが含まれている場合、AllowUnsafeBlocks コンパイラ オプションも使用する必要があります。 詳細については、「アンセーフ コードとポインター」を参照してください。 Visual Studio 2012 で unsafe オプションを設定するには、メイン メニューで [プロジェクト] をクリックして、 [ビルド] ウィンドウを選択し、[アンセーフ コードの許可] チェック ボックスをオンにします。 次の例で、 /unsafe なしでコンパイルすると、CS0227 が生成されます。 // CS0227.cs public class MyClass { unsafe public static void Main() // CS0227 { } } 関連項目 C#

    Itisango
    Itisango 2020/10/26
    "If source code contains the unsafe keyword, then the -unsafe compiler option must also be used. For more information, see Unsafe Code and Pointers. To set the unsafe option in Visual Studio 2012, click on Project in the main menu, select the Build pane, and check the box that says..." #dotNET
  • 1