C# 응용 프로그램에서 c dll을 사용하는 데 약간의 문제가 있습니다. 나에게 오류를 제공 기능은이 같은 DLL의 헤더 파일에 정의되어 C에서 DLL을 C DLL로 전달 #
int __stdcall DDC_CreateFilePropertyString (DDCFileHandle file,
const char *property,
const char *value);
은 내가 DLL을 액세스 내 클래스에 다음 코드를 추가했다.
[DllImport("nilibddc.dll", CallingConvention = CallingConvention.Cdecl, CharSet=CharSet.Ansi)]
private static extern int DDC_CreateFilePropertyString(IntPtr file,
[MarshalAs(UnmanagedType.LPStr)]string property,
[MarshalAs(UnmanagedType.LPStr)]string value);
유형 DDCFileHandle은 다음과 같이 헤더 파일에 정의되어 있습니다
typedef struct _DDCFile DDCFile;
typedef DDCFile* DDCFileHandle;
난에서 다른 파일이없는 (헤더 파일에서 _DDCFile 구조체에 대한 추가 정보가 없습니다 라이브러리 메신저 사용).
DDC_CreateFilePropertyString() 함수를 호출하기 전에 다음 함수를 호출하여 파일을 만들고 파일 핸들을 가져옵니다.
[DllImport("nilibddc.dll", CallingConvention = CallingConvention.Cdecl, CharSet=CharSet.Ansi]
private static extern int DDC_CreateFile(char[] filePath,
char[] fileType,
char[] name,
char[] description,
char[] title,
char[] author,
ref IntPtr file);
헤더 파일의 정의는 다음과 같습니다. 내가 DDC_CreateFilePropertyString 함수를 호출 할 때
int __stdcall DDC_CreateFile (const char *filePath,
const char *fileType,
const char *name,
const char *description,
const char *title,
const char *author,
DDCFileHandle *file);
지금 항상 내가 전달 일부 잘못된 매개 변수가 있음을 말해 나에게 오류를 반환합니다. 내가 도대체 뭘 잘못하고있는 겁니까? 내가 사용하고있는 라이브러리는 National Instruments의 TDMS C API입니다.
도움 주셔서 감사합니다.
'DDC_CreateFile '에 대한 호출이 실제로 성공합니까? 어떻게 알았어? 그리고 그것의'const char *'매개 변수도'char []'보다는'string' ('DDC_CreateFilePropertyHandle'와 동일)로서 전달되어야합니까? DLL 함수도'stdcall'으로 선언되므로 pinvoke 선언에서'cdecl' 호출 규칙을 변경해야합니다. – shambulator
예. 성공합니다. 반환 코드는 괜찮습니다. 방금 'DDC_CreateFile'함수를 호출하면 파일 시스템에 파일이 제대로 작성됩니다. 'char []'을 'string'으로 변경하고 'cdec1'을 'stdcall'으로 변경했지만 여전히 오류가 발생합니다. – Devkev