KO CSharp Keyword extern - LIHACHTETAN/ClassicUO-Bad-Newbie-CSharp-Scripts-IDE GitHub Wiki

ะฃะบั€ะฐั—ะฝััŒะบะฐ ยท ะ ัƒััะบะธะน ยท English ยท Deutsch ยท Franรงais ยท Italiano ยท Espaรฑol ยท ็น้ซ”ไธญๆ–‡ ยท ๆ—ฅๆœฌ่ชž ยท ํ•œ๊ตญ์–ด

C#: extern

ํ•ธ๋“œ๋ถ C# ยท ์‹ค์šฉ ๊ฐ€์ด๋“œ

C# ์ฝ”๋“œ ์™ธ๋ถ€์—์„œ ๊ตฌํ˜„๋œ ๋ฉค๋ฒ„๋ฅผ ์„ ์–ธํ•ฉ๋‹ˆ๋‹ค. DllImport์„ ํ†ตํ•œ ๊ธฐ๋ณธ ์ƒํ˜ธ ์šด์šฉ์„ฑ์˜ ๊ฒฝ์šฐ ์ผ๋ฐ˜์ ์ž…๋‹ˆ๋‹ค. ์™ธ๋ถ€ ๋ณ„์นญ์€ ์™ธ๋ถ€ ์–ด์…ˆ๋ธ”๋ฆฌ ๋ณ„์นญ์„ ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค.

๊ฐ„๋‹จํ•œ ์˜ˆ์ œ (Example.cs)

์ด ์˜ˆ์ œ๋ฅผ Example.cs๋กœ ๋”ฐ๋กœ ์ €์žฅํ•˜๊ณ  ์ด ํŽ˜์ด์ง€์˜ ๋‹ค๋ฅธ ์˜ˆ์ œ์™€ ๋…๋ฆฝ์ ์œผ๋กœ ์‹คํ–‰ํ•˜์„ธ์š”.

Example.cs:

// PROJECT-EXAMPLE
class NativeMethods
{
    [System.Runtime.InteropServices.DllImport("kernel32.dll")]
    public static extern uint GetCurrentProcessId();
}

์„ ์–ธ๋งŒ ํฌํ•จํ•ฉ๋‹ˆ๋‹ค. ์ด ์ฝ”๋“œ๋Š” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋กœ ์ปดํŒŒ์ผ๋˜๋ฉฐ ์‹คํ–‰ํ•˜๋ ค๋ฉด Main์—์„œ ํ˜ธ์ถœํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

ํ†ต์‚ฌ๋ก 

[DllImport(...)] public static extern ReturnType Method(...);

์ด ๋‘ ๊ฐ€์ง€ ๊ธฐ๋ณธ ์˜ˆ์ œ๋Š” Windows์šฉ์ž…๋‹ˆ๋‹ค. ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์ด๋ฆ„, ABI ๋ฐ ๊ธฐ๋Šฅ ๊ฐ€์šฉ์„ฑ์€ ํ”Œ๋žซํผ์— ๋”ฐ๋ผ ๋‹ค๋ฆ…๋‹ˆ๋‹ค. ์ปดํŒŒ์ผ ์ž์ฒด์—์„œ๋Š” ํ•ด๋‹น ํ•ญ๋ชฉ์˜ ์กด์žฌ๋ฅผ ํ™•์ธํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

์˜ˆ์‹œ 1: ๊ธฐ๋ณธ ํ˜•ํƒœ

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.IO;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;

public static class Program
{
    public static async Task Main(string[] args)
    {
        Console.WriteLine(Native.GetCurrentProcessId());
    }
}
public static class Native { [DllImport("kernel32.dll")] public static extern uint GetCurrentProcessId(); }

์˜ˆ 2: ๋˜ ๋‹ค๋ฅธ ์‹ค์ œ ํ˜•์‹

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.IO;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;

public static class Program
{
    public static async Task Main(string[] args)
    {
        Console.WriteLine(Native.GetTickCount64());
    }
}
public static class Native { [DllImport("kernel32.dll")] public static extern ulong GetTickCount64(); }

๊ณต์‹ ์ถœ์ฒ˜: Microsoft ํ•™์Šต.