のC#の問題は、私はこのエラーにネイティブC++のdll /メモリ
追加情報を持っている:読み取りまたは書き込み保護されているメモリをしようとしました。これはしばしば、他のメモリが壊れていることを示します。
あなたはその理由を知っていますか?
ネイティブC++
extern "C" void __declspec(dllexport) Mafonc(string nom);
void __declspec(dllexport) Mafonc(string nom)
{
string tom = nom;
}
C#の
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Security;
namespace TradeInterface
{
static class Program
{
[DllImport("TradeEngine.dll", CharSet = CharSet.Ansi,
CallingConvention = CallingConvention.StdCall,
ExactSpelling = true),
SuppressUnmanagedCodeSecurity]
public static extern void Mafonc(string nom);
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Mafonc("E:\\DossierProjet");
Application.Run(new Form1());
}
}
}
アンマネージDLLのstringの定義は何ですか?私が推測しているように文字ポインタであれば、ポインタをコピーして後で使用することはできませんが、文字列自体(strcpyなど)をコピーする必要があります。 –
あなたの言っていることを理解できません。私のC++コードでは、文字列はString.hから来る実際の文字列です。 – Nazka