2014-10-20 12 views
1

내 컴파일러에서 kernel32.dll을 가져올 수 없다는 문제가 있습니다. 필자는 System.Runtime.InteropServices를 사용하고 있습니다. 여기에 코드입니다 : ". 현재 컨텍스트에서"컨텍스트에서 C# DllImport가 발견되지 않지만 Interpor Services가 바인딩됩니다.

using System; 
    ... 
    using System.Runtime.InteropServices; 

    namespace server 
    { 
     class Debugconsole 
     { 
      public void Initialise() 
      { 
       [DllImport("kernel32.dll")] 
       ... 
      } 
     } 
    } 

그것은 syntaxerrors의 전체 무리를 던져 같이 DllImport "를 찾을 수 없습니다"는

도움 주셔서 감사합니다.

+2

당신은 그것이 외부에 배치해야하는 방법, 내부의'DllImport'을 잘못했습니다. [이 답변] (http://stackoverflow.com/questions/6076717/where-to-put-dllimport)을 확인하십시오. – Vlad

답변

2

메서드 내에서 특성을 사용할 수 없습니다.
당신은 당신의 방법 밖으로 이동해야합니다 :

class Debugconsole 
{ 
    [DllImport("kernel32.dll")] 
    ... the static extern method declaration ... 

    public void Initialise() 
    { 
     ... 
    } 
} 
+1

아, 고마워, 이제는 효과가있다. 나를 허용 할 때 나는 정확한 답을 줄 것이다. –