0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

自分用 C#+SDL2 libpng16-16.dll: 指定されたモジュールが見つかりません。

Last updated at Posted at 2023-03-18

エラー内容

SDL_image.IMG_Initで、Failed loading libpng16-16.dll: 指定されたモジュールが見つかりません。といったエラーが出る。

解決策

SDL_image.IMG_Initを実行する前にSetDllDirectroryでdllの検索場所をプログラムのあるパスにすれはよい
以下コード。

using System.Runtime.InteropServices;
using SDL2;

[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern bool SetDllDirectory(string lpPathName);

void Init()
{
    // 初期化する前にSetDllDirectoryでdllの検索場所をプログラムのあるパスに設定する
    SetDllDirectory(AppContext.BaseDirectory);

    if (SDL_image.IMG_Init(SDL_image.IMG_InitFlags.IMG_INIT_PNG) == 0)
        Console.WriteLine(SDL_image.IMG_GetError());
    
    ...
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?