본문 바로가기

Dev::DotNet/C#

DLL 레지스트리 등록 API

API 로 DLL 등록


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
using System.Runtime.InteropServices;
 
...
 
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate void _DLLPROC();
 
[DllImport("kernel32.dll", EntryPoint = "LoadLibrary")]
private extern static int LoadLibrary(string librayName);
 
 
[DllImport("kernel32.dll", EntryPoint = "GetProcAddress", CharSet = CharSet.Ansi)]
private extern static IntPtr GetProcAddress(int hwnd, string procedureName);
 
...
 
public void DLLRegister(string DLLPath)
{
 
    if (System.IO.File.Exists(DLLPath))
    {
        int hMod = LoadLibrary(DLLPath);
 
        if (hMod != 0)
        {
            _DLLPROC dllProc;
 
            IntPtr pfnDllProc = GetProcAddress(hMod, "DllRegisterServer");
 
            if (pfnDllProc != IntPtr.Zero)
            {
                dllProc = (_DLLPROC)Marshal.GetDelegateForFunctionPointer(pfnDllProc, typeof(_DLLPROC));
                dllProc();
            }
        }
    }
}
cs