C#에서 C#으로 문자열의 배열을 전달하려고 시도하는 중이 오류가 발생합니다. 이 오류는 항상 나타나는 것은 아니지만 때로 나타납니다. C#에서보호 된 메모리를 읽거나 쓰려고 시도했습니다. 이것은 종종 다른 메모리가 손상되었다는 표시입니다.
이선언 C에서
[DllImport(READER_DLL,
CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern void InstalledRooms(string[] rooms,int length);
++
가 C#을에서 호출되는 방법void InstalledRooms(wchar_t const* const* values, int length);
void DetectorImpl::InstalledRooms(wchar_t const* const* values, int length)
{
LogScope scope(log_, Log::Level::Full, _T("DetectorImpl::InstalledRooms"),this);
std::vector<std::wstring> vStr(values, values + length);
m_installedRooms=vStr;
}
?
//List<string> installedRooms = new List<string>();
//installedRooms.add("r1");
//installedRooms.add("r1"); etc
NativeDetectorEntryPoint.InstalledRooms(installedRooms.ToArray(),installedRooms.Count);
오류가 어떤 도움이 정말 이건 그냥 추측이지만 오류가 간헐적이기 때문에 나는이가 string
관련 메모리 문제라고 생각
그것은 수있을 당신의 P/(그러나 이것은 완전한 추측!)을 모두 StringBuilder를 사용해야 선언을 호출 : 공공 정적 통근 무효 InstalledRooms (StringBuilder의 [] 객실, INT 길이); –
[MarshalAs (UnmanagedType.LPArray)] string [] rooms – TheMathemagician
@MatthewWatson을 추가하십시오.이 http://stackoverflow.com/questions/1713288/c-passing-array- of-strings-to-ac-dll –