Skip to content

Commit 6d2ff55

Browse files
committed
Explicit charset defintions on P/Invoke calls
Closes #10
1 parent 762457e commit 6d2ff55

3 files changed

Lines changed: 20 additions & 6 deletions

File tree

Dockerfile

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
1-
# https://hub.docker.com/_/microsoft-dotnet-runtime/
2-
FROM mcr.microsoft.com/dotnet/runtime:6.0
1+
#
2+
# This docker can be used to test the linux implementation of FindExecutable
3+
#
4+
# On a Windows dev PC run:
5+
# docker build -t sgr/findexecutabletest .
6+
# docker run --rm -v ".\bin\Debug\net10.0:/myapp" -t sgr/findexecutabletest
7+
#
8+
# Adjust path of the volume mount if you are to test other build flavors.
9+
#
10+
11+
# https://hub.docker.com/_/microsoft-dotnet-runtime/
12+
FROM mcr.microsoft.com/dotnet/runtime:10.0
13+
314
RUN apt-get update && apt-get install -y git
4-
COPY --chmod=444 *.* /myapp/
15+
16+
VOLUME /myapp
17+
518
WORKDIR /myapp
19+
620
ENTRYPOINT ["dotnet", "FindExecutable.dll"]

FindExecutable.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net8.0</TargetFramework>
5+
<TargetFramework>net10.0</TargetFramework>
66
<ImplicitUsings>disable</ImplicitUsings>
77
<Nullable>enable</Nullable>
88
</PropertyGroup>

FindExecutable/FindExecutable.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public static class FindExecutable
145145
#region Test if File is Executable
146146

147147
#region Windows P/Invoke
148-
[DllImport("shell32.dll")]
148+
[DllImport("shell32.dll", CharSet = CharSet.Unicode)]
149149
private static extern IntPtr SHGetFileInfo(string pszPath, uint dwFileAttributes, IntPtr psfi, uint cbSizeFileInfo, uint uFlags);
150150
private const uint SHGFI_EXETYPE = 0x000002000;
151151
#endregion
@@ -185,7 +185,7 @@ private static bool IsExecutableOnWindow(string path)
185185
}
186186

187187
#region Linux P/Invoke
188-
[DllImport("libc", SetLastError = true)]
188+
[DllImport("libc", CharSet = CharSet.Ansi, SetLastError = true)]
189189
private static extern int access(string pathname, int mode);
190190
// https://codebrowser.dev/glibc/glibc/posix/unistd.h.html#283
191191
private const int X_OK = 1;

0 commit comments

Comments
 (0)