Microsoft MVP성태의 닷넷 이야기
글쓴 사람
슬픈단잠
홈페이지
첨부 파일
 

C++에서의 함수의 원형은
__declspec(dllexport)
int __stdcall FileHandling( DWORD uid, const char *cId, const char *pSrcFilePath, const char *pDestFolder, char szOutFiles[][260], int iStartTime, int iTimeLimit, BOOL bSkipVideo )

그리고 C#에서 선언한 함수의 원형은
[DllImport(DllName, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
public unsafe extern static int FileHandling(System.UInt32 uid, string cid, string srcFilePath, string destFolder, IntPtr outFiles, int startTime = 0, int timeLimit = 0, System.Boolean skipVideo = true);

말씀주신 IntPtr을 이용하여 위와 같이 선언했습니다.
그리고 사용하는 곳에서는...

char[,] outFiles = new char[3, 260];
fixed(char* outFilesPtr = outFiles)
{
  try
  {
    IntPtr ptr = new IntPtr(outFilesPtr);

    bool succeed = FileHandling(uid, cid, filePath, dnaTargetPath, ptr, 0, 0, true) >= 0;
    File.Move(filePath, $"{outPath}\\{fileName}");
  }
}

이론상 2차원 배열이라 해도 단순히 연속된 메모리이니 예제 코드 등을 참고하면 충분히 될 것 같아 보였습니다.
그래서 위와 같은 코드를 작성한 다음에 확인을 해보았는데...

'System.BadImageFormatException: '프로그램을 잘못된 형식으로 로드하려고 했습니다. (0x8007000B)'

와 같은 에러를 뱉어내다보니 마샬링 이슈로 보여집니다.
혹시 다른 방법이 있을까요? 마샬링 이슈 하나로 계속 고생을 하고 있네요.








[최초 등록일: ]
[최종 수정일: 10/25/2022]


비밀번호

댓글 작성자
 



2022-10-25 01시00분
System.BadImageFormatException은 호출 측과 피호출 측 모듈의 플랫폼이 다른 것입니다. 예를 들어, c dll은 32비트로 빌드되었는데, c# 응용 프로그램은 64비트로 빌드된 경우입니다. 그걸 맞춰보세요.
정성태
2022-10-25 01시08분
[슬픈단잠] 전부 x86으로 빌드를 하기는 했는데... 어렵군요. ㄷㄷ
조언에 감사드립니다. 나머지는 제가 해결해야할 부분인 것 같네요. ㅠ
[guest]

NoWriterDateCnt.TitleFile(s)