C++로 DLL을 작성했습니다. 함수 중 하나가 문자 배열에 씁니다.네이티브 C++ DLL에서 C# App으로 문자열 전달
C++ 기능
EXPORT int xmain(int argc, char argv[], char argv2[])
{
char pTypeName[4096];
...
//Other pTypeName ends up populated with "Portable Network Graphics"
//This code verifies that pTypeName is populated with what I think it is:
char szBuff[64];
sprintf(szBuff, pTypeName, 0);
MessageBoxA(NULL, szBuff, szBuff, MB_OK);
//The caption and title are "Portable Network Graphics"
...
//Here, I attempt to copy the value in pTypeName to parameter 3.
sprintf(argv2, szBuff, 0);
return ret;
}
C# 오기
//I believe I have to use CharSet.Ansi because by the C++ code uses char[],
[DllImport("FirstDll.dll", CharSet=CharSet.Ansi)]
public static extern int xmain(int argc, string argv, ref string zzz);
I 참조로 C 번호에서 파라미터를 전달하는 시도 및 C++ DLL이있다
private void button2_Click(object sender, EventArgs e)
{
string zzz = "";
int xxx = xmain(2, @"C:\hhh.bmp", ref zzz);
MessageBox.Show(zzz);
//The message box displays
//MessageBox.Show displays "IstuÈst¼ÓstÄstlÄstwÄstiÑstõÖstwÍst\
// aÖst[ÖstÃÏst¯ÄstÐstòÄstŽÐstÅstpÅstOleMainThreadWndClass"
}
C# 1 함수 파라미터를 채우는 . DLL에서 값이 올바른지 확인했지만 횡설수설이 C# 응용 프로그램에 전달됩니다.
올바른 문자열 값을 C# 문자열에 쓰려면 어떻게해야합니까?
시도는 C# 프로젝트에서 "안전하지 않은"공간을 만들 수 있습니다. – dotTutorials