저는 C# 응용 프로그램에서 이전 C++ .dll에서 외부 메서드를 호출 할 수없는 이유를 알아 내려고 노력하고 있습니다.C#에서 관리되지 않는 DLL을 호출하는 데 어려움이 있습니다.
int __export FAR PASCAL SimplePGPEncryptFile(
HWND hWnd1,
LPSTR InputFileName,
LPSTR OutputFileName,
BOOL SignIt,
BOOL Wipe,
BOOL Armor,
BOOL TextMode,
BOOL IDEAOnly,
BOOL UseUntrustedKeys,
LPSTR RecipientList,
LPSTR SignerKeyID,
int SignerBufferLen,
LPSTR SignerPassphrase,
int SignerPwdBufferLen,
LPSTR IDEAPassphrase,
int IDEAPwdBufferLen,
LPSTR PublicKeyRingName,
LPSTR PrivateKeyRingName);
여기 내 C# 선언입니다 : 여기
함수 헤더의 [DllImport("smplpgp_32.dll", CallingConvention = CallingConvention.StdCall)]
public static extern int SimplePGPEncryptFile(
IntPtr hWnd1,
[MarshalAs(UnmanagedType.LPStr)] string InputFileName,
[MarshalAs(UnmanagedType.LPStr)] string OutputFileName,
bool SignIt,
bool Wipe,
bool Armor,
bool TextMode,
bool IDEAOnly,
bool UseUntrustedKeys,
[MarshalAs(UnmanagedType.LPStr)] string RecipientList,
[MarshalAs(UnmanagedType.LPStr)] string SignerKeyID,
int SignerBufferLen,
[MarshalAs(UnmanagedType.LPStr)] string SignerPassphrase,
int SignerPwdBufferLen,
[MarshalAs(UnmanagedType.LPStr)] string IDEAPassphrase,
int IDEAPwdBufferLen,
[MarshalAs(UnmanagedType.LPStr)] string PublicKeyRingName,
[MarshalAs(UnmanagedType.LPStr)] string PrivateKeyRingName);
나는 다음 두 가지 오류 중 하나가 (헤더에 선언)을 얻고,이 메소드를 호출 할 때 :
#define SIMPLEPGPENCRYPTFILE_RECIPIENTLISTDOESNOTENDWITHNEWLINE 408
#define SIMPLEPGPENCRYPTFILE_RECIPIENTLISTDOESNOTSTARTWITHGOODCODECHAR 409
이
또한 헤더 상수로 정의된다#define INCLUDE_ONLYUSERIDS 1
이이 기능을 호출 작동하는 것으로 알려져 C++ 코드 :
string recipientList = "1CA\n\0";
합격 다음 'RecipientList'매개 변수에 대해이 전달
이char recipients[512];
recipients[0] = INCLUDE_ONLYUSERIDS;
strcat(strcpy(&recipients[1], rID), "\n"); \\ rID is equal to "CA"
return 0 == SimplePGPEncryptFile(INI.m_hWnd,
(char*)plain, (char*)cipher,
0,
0,
1,
0,
0,
1, // UseUntrustedKeys
recipients,
0, 0,
0, 0,
0, 0,
PGPKM.pub, 0); //PGPKM.pub is declared earlier
나에게 '409'오류를 제공을 이 'RecipientList'매개 변수에 대해 '408 '오류가 발생합니다.
char[] recipients = new char[512];
recipients[0] = '1';
recipients[1] = 'C';
recipients[2] = 'A';
recipients[3] = '\n'; // also tried '\r', then '\n'
recipients[4] = Char.MinValue;
string paramValue = recipients.ToString();
누구든지 내 부분에 명백한 감독을 할 수 있습니까? 이 문제를 해결하는 데 필요한 모든 것이있는 것 같지만 예상대로 작동하는 것은 없습니다.
사이드 노트 : 동일한 .dll에서 다른 함수를 성공적으로 호출하고 있습니다. 또한 StringBuilder를 사용하여 RecipientList 매개 변수를 구성하는 방법을 실험했습니다.
의견을 보내 주셔서 감사합니다.
수신자 [0] = INCLUDE_ONLYUSERIDS; - 수신자가 아닙니다. [0] = 1; 받는 사람 [0] = '1'과 다른; - C#은 수신자가됩니다. [0] = (char) 1; – jeffora
받는 사람의 목적은 무엇입니까 [4] = Char.MinValue; –
작동하는 코드에서 strcpy (strcpy (& recipients [1], rID), "\ n") : 결과 문자열은 어떻게 생깁니 까? 512 바이트 후? 또는받는 사람 []이 사용되지 않은 부분을 잘라낼만큼 똑똑합니까? 내 C++ 일 이후로 잠시만 기다려주세요. –