광고


C# CLR string to C++ LPCTSTR 전달방법 C#



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// C++ Lib Defined
short PASCAL LoadCalibrationData(LPCTSTR pWaveName, LPCTSTR pSensName);
 
// CLR에서 lib Masking
// .h
using namespace System::Runtime::InteropServices;
#include <msclr/marshal.h>
 
short PMA_GetCalibrationData(System::String^ WaveName, System::String^ SensName);
 
// .Cpp    
short PMA12Net::PMA_GetCalibrationData(System::String^ WaveName, System::String^ SensName)
{    
    IntPtr wptr = System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(WaveName);
    LPCTSTR Wav = reinterpret_cast<LPCTSTR>(wptr.ToPointer());
 
    IntPtr sptr = System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(SensName);
    LPCTSTR Sens = reinterpret_cast<LPCTSTR>(sptr.ToPointer());
 
    // C# string to C++ LPCTSTR
    short ret = LoadCalibrationData(Wav, Sens);
 
    Marshal::FreeHGlobal(wptr);
    Marshal::FreeHGlobal(sptr);
 
    return ret;
}
 
// 최종적으로 C# 에서 호출
public short LoadCalibrationData(PMA_CalculationsFiles files)
{
    short result = -1;
    
    try
    {                
        result = gPMA.PMA_GetCalibrationData(files.WaveFilePath, files.SensFilePath);
    }
    catch (Exception e)
    {
        MessageBox.Show(e.ToString());
    }
 
    return result;
}
cs

덧글

댓글 입력 영역



통계 위젯 (화이트)

02
13
3101

메모장

이 이글루를 링크한 사람 (화이트)

1