2012-02-29 4 views
1

관리되는 클래스에서 사용하려는 관리되지 않는 라이브러리가 있습니다. 함수의 인터페이스는 다음과 같습니다 C++/CLI에서 관리되는 VS. 관리되지 않는 단락

GetProgress(short* value); 

그래서 내 관리되는 클래스에 쓴 :

short val = 0; 
GetProgress(&val); 

내가 가지고 다음과 같은 오류 :

Error C2664: 'GetProgress' : cannot convert parameter 1 from 'cli::interior_ptr' in 'short *' with [ Type=short ]

나는 this topic을 읽고, 내가 변경 내 코드 입력 :

short val = 0; 
pin_ptr<short*> pVal = &val; 
GetProgress(pVal); 

그리고 이전의 오류에 더하여

Error C2440: 'initialisation' : cannot convert from 'short *' to 'cli::pin_ptr' with [ Type=short * ]

어떻게 해결할 수 있습니까?

답변

1

흥미로운 점입니다. val가 관리되는 형식이 될 수 있기 때문에

다음 코드는 C2664을 생성합니다

using namespace System; 

void GetProgress(short* value) 
{ 
    // unmanaged goodness 
} 

ref class XYZ : System::Object 
{ 
    short val; 

    void foo() 
    { 
     GetProgress(&val); 
    } 
}; 

당신이 먼저 지역 변수를 선언하는 경우, 그것은 모두가 잘 작동 ...

using namespace System; 

void GetProgress(short* value) 
{ 
    // unmanaged goodness 
} 

ref class XYZ : System::Object 
{ 
    short val; 

    void foo() 
    { 
     short x; 
     GetProgress(&x); 
     val = x; 
    } 
}; 

정확하게 답을 찾지는 못했지만 간단한 픽스이기 때문에 포함시켜야한다고 생각했습니다.

+0

좋습니다. 감사! :) – gregseth

관련 문제