C#

2017-11-27 20 views
-1

나는 아래와 같은 DLL에서 API를 호출하기 위해 노력 해왔다로 C++에서 *의 wchar_t를 검색 할 수 없습니다 : DLL을C#

에서 C# 코드에서

[DllImport(@"TELCompress.dll", EntryPoint = "TELMonDecode", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)] 
    public static extern int TELMonDecode(ref bool a, ref bool b, byte[] ab, System.IntPtr pDestBuf, int j, int byteCount); 

전화

int returnval = TELMonDecode(ref a, ref b, bytes, destPnt, k, bytesRec); 

C++ 코드

__declspec(dllexport) int TELMonDecode(bool *bUnicode, bool *bCompress, BYTE *pSourceBuf, wchar_t* pDestBuf, int pDestBufSize,int byteCount) 

{ 
... 
    CString decodedMsg = _T("<Empty>"); 
    int erc = DecodeByteStream(bUnicode, bCompress, pSourceBuf, &decodedMsg); 

    ::MessageBox(NULL,L"Decoding byte done",L"Caption",0); 
    pDestBuf = decodedMsg.GetBuffer(); 
    ::MessageBox(NULL,pDestBuf,L"Caption in TELMonDecode",0); 
... 
} 

여기 많은 링크를 언급했지만 아직도 내가하고있는 잘못을 파악할 수 없습니다. 안내하십시오.

+0

코드가 "작동하지 않는 방법"에 대해 자세히 설명해 주시겠습니까? 당신은 무엇을 기대하고 있었고 실제로 무슨 일이 일어 났습니까? 예외/오류가있는 경우 발생한 행을 게시하고 예외/오류 세부 정보를 게시하십시오. 이 세부 정보를 입력하거나 편집하지 않으면 도움이되지 않을 수 있습니다. 그게 없기 때문에 [mcve]를 보아라. – rene

+0

스 니펫이 불완전하게 불완전 해지고 아무도'destPnt'가 어디서 왔는지 알 수 없습니다. 선언을 고쳐라. 인자 타입은 IntPtr 대신에'StringBuilder'이어야한다. ** pDestBufSize'를 체크하지 않은 ** ** 빌더의 용량이 너무 낮을 때 얻을 수있는 GC 힙 손상은 진단하기가 너무 어렵습니다. –

답변

-1

사용 BSTR * 대신 wchar_t를에 * 당신은 C#을 측면에서 문자열심판을 사용할 수 있어야합니다.

0

의견에 감사드립니다. 도움이되었다.

이제 코드는 C#을 코드 TELCompress.dll

__declspec(dllexport) int TELMonDecode(bool *bUnicode, bool *bCompress, BYTE *pSourceBuf, BSTR* pDestBuf, int pDestBufSize,int byteCount) 
{ 
    CString decodedMsg = _T("<Empty>"); 
    //Code to copy data in decodedMsg 
    CComBSTR tempBstrString(decodedMsg.GetBuffer()); //test 
    tempBstrString.CopyTo(pDestBuf); 
.... //Some more code 
return 0; 
} 

에서

[DllImport(@"TELCompress.dll", EntryPoint = "TELMonDecode", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)] 
    public static extern int TELMonDecode(ref bool a, ref bool b, byte[] ab, ref String pDestBuf, int j, int byteCount); 
... //Some code here 
//Call to the C++ function 
int returnval = TELMonDecode(ref a, ref b, bytes, ref receiveStr, k, bytesRec); 

C++ 코드를 다음과 같이 작동합니다 그리고 그것은 문자열이 보여주는 이전이었다 C# 코드에서 볼 수있다, 작동 빈 문자열

귀중한 의견과 의견을 보내 주셔서 감사합니다. -Megha