---
title: P/Invoke 사용
product: Unity Editor
version: '6000.0'
latest_version: '7000.0'
status: outdated
canonical: https://docs.unity.com/ko-kr/engine/6000.0/manual/platform-specific/windows-store/uwp-developing/uwp-il2cpp-scripting/uwp-il2cpp-plugins/uwp-pinvoke
latest_url: https://docs.unity.com/ko-kr/engine/7000.0/manual/platform-specific/windows-store/uwp-developing/uwp-il2cpp-scripting/uwp-il2cpp-plugins/uwp-pinvoke.md
last_updated: 2026-10-30
generated_at: 2026-11-03T07:59:55.473Z
locale: ko-kr
---

# P/Invoke 사용

> **Note:** This page documents version 6000.0. The latest version is 7000.0: https://docs.unity.com/ko-kr/engine/7000.0/manual/platform-specific/windows-store/uwp-developing/uwp-il2cpp-scripting/uwp-il2cpp-plugins/uwp-pinvoke.md

> Learn the rules and limitations of using P/invoke.

P/Invoke는 관리되는 코드에서 네이티브 코드의 구조체, 콜백, 함수에 액세스할 수 있게 해주는 기술입니다. x86에서 플랫폼 호출을 위한 기본 호출 방법은 `__stdcall`입니다. 자세한 내용은 [P/Invoke](https://learn.microsoft.com/en-us/dotnet/standard/native-interop/pinvoke)에 관한 Microsoft 기술 자료를 참조하십시오.

## P/invoke 마셜링 규칙##p/invoke-marshaling-rules

P/Invoke 마셜링 규칙은 [.NET 마셜링](https://learn.microsoft.com/en-us/dotnet/standard/native-interop/type-marshalling) 규칙과 동일합니다. 그러나 Unity는 다음 유형을 지원하지 않습니다.

* AnsiBStr
* Currency
* SAFEARRAY
* IDispatch
* TBStr
* VBByRefStr

## P/Invoke 제한##p/invoke-limitations

UWP(유니버설 Windows 플랫폼)에서는 특정 시스템 라이브러리로 플랫폼 호출을 하기 위해 DLL(동적 링크 라이브러리) 이름을 지정할 수 없습니다. 프로젝트 외부의 DLL에 플랫폼 호출을 시도하면 런타임 시 DllNotFoundException이 발생합니다. 따라서 DLL 이름 대신 `__Internal` 키워드를 사용하면 런타임 시 함수를 로드할 때가 아닌 프로젝트를 빌드할 때 C++ 링커를 사용하여 함수를 확인하게 됩니다.

```
    [DllImport("__Internal")]
    private static extern int CountLettersInString([MarshalAs(UnmanagedType.LPWStr)]string str);
```

관리되는 코드에서 함수를 선언할 때 오류가 발생하면 런타임 시 오류가 발생하는 것이 아니라 링커 오류가 발생합니다. 즉, 런타임 중에 동적 로딩을 수행할 필요가 없고 함수가 직접 호출되므로 P/Invoke 호출의 오버헤드가 크게 감소합니다.

## 추가 리소스##additional-resources

* [P/Invoke에 대한 Microsoft 기술 자료](https://learn.microsoft.com/en-us/dotnet/standard/native-interop/pinvoke)
* [네이티브 UWP 플러그인 저작](/engine/6000.0/manual/platform-specific/windows-store/uwp-developing/uwp-il2cpp-scripting/uwp-il2cpp-plugins/uwp-native-plugins-author.md)
