私は2つの機能を持つc++dllを持っています
const char* getVersionText1(void);
void        getVersionText2(const char** res);
どちらの関数も、製品のバージョンを説明する文字列を返します。最初の関数はそれをconstchar*として返し(つまり、内部で割り当ててディールで検索します)、2番目の関数はchar *へのポインターを取得し、バージョンを説明するchar*を指すように設定します。
これらの関数をC#から呼び出して、テキストを表示したいと思います。関数の呼び出し順序が重要なので、[dllimport...]スタイルを使用できません。最初にgetVersionよりコンストラクターを呼び出し、最後にデストラクタを呼び出します。したがって、dllを最初にメモリにロードする必要があります。
両方の機能のテキストを印刷する数行のコードを投稿してください。私はC#を初めて使用するので、コードに問題があると思われる場合は申し訳ありません。
static class NativeMethods{
    [DllImport("kernel32.dll")]
    public static extern IntPtr LoadLibrary(string dllToLoad);
    [DllImport("kernel32.dll")]
    public static extern IntPtr GetProcAddress(IntPtr hModule, string procedureName);
    [DllImport("kernel32.dll")]
    public static extern bool FreeLibrary(IntPtr hModule);
}
class Program{
    // Define function pointers to entires in DLL
    [UnmanagedFunctionPointer(CallingConvention.Cdecl)] private delegate IntPtr getVersionText1();
    [UnmanagedFunctionPointer(CallingConvention.Cdecl)] private delegate void getVersionText2(IntPtr );
    static void Main(string[] args){
        // Pointers to functions of DLL.
        getVersionText1 f1;
        getVersionText2 f2;
        IntPtr pDll = NativeMethods.LoadLibrary("p:\\my.dll");
        IntPtr pAddressOfFunctionToCall;
        pAddressOfFunctionToCall = NativeMethods.GetProcAddress(pDll, "getVersionText1 ");
        f1 = (getVersionText1)Marshal.GetDelegateForFunctionPointer(pAddressOfFunctionToCall, typeof(getVersionText1));
        pAddressOfFunctionToCall = NativeMethods.GetProcAddress(pDll, "getVersionText2 ");
        f2 = (getVersionText2)Marshal.GetDelegateForFunctionPointer(pAddressOfFunctionToCall, typeof(getVersionText2));
        // Here I don't know what to do. It doesn't work ????
        IntPtr verText = f1();
        String s = Marshal.PtrToStringAuto(verText);
        Console.WriteLine(s);   // Doesnt work
        // And how to use the second function. How do I sent a pointer to char* ???
    }
}