Skip to content

Commit

Permalink
configure: display version number
Browse files Browse the repository at this point in the history
  • Loading branch information
32th-System committed Aug 31, 2023
1 parent 55cc889 commit b087e61
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions thcrap_configure_v3/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
Click Next to continue, or click "Configure Settings" to change settings.
</TextBlock>
<Button Content="Configure Settings" HorizontalAlignment="Left" VerticalAlignment="Bottom" Click="SettingsWindow_Open" />
<TextBlock Name="VersionText" HorizontalAlignment="Right" VerticalAlignment="Bottom"></TextBlock>
</Grid>
</xctk:WizardPage>
<xctk:WizardPage x:Name="Page1" PageType="Interior"
Expand Down
14 changes: 14 additions & 0 deletions thcrap_configure_v3/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ namespace thcrap_configure_v3
/// </summary>
public partial class MainWindow : Window
{
[DllImport("kernel32", CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true)]
static extern IntPtr GetProcAddress(IntPtr hModule, string procName);
[DllImport("kernel32", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern IntPtr GetModuleHandle([MarshalAs(UnmanagedType.LPWStr)] string lpModuleName);

public MainWindow()
{
InitializeComponent();
Expand All @@ -43,6 +48,15 @@ private void Window_Loaded(object sender, RoutedEventArgs e)
ThcrapDll.exception_load_config();
ThcrapDll.log_init(ThcrapDll.globalconfig_get_boolean("console", false));

// C# doesn't have global variables, or the ability to import global variables from DLL files.
// This is a workaround.
IntPtr p = GetProcAddress(GetModuleHandle(ThcrapDll.DLL), "PROJECT_VERSION_STRING");
if (p != IntPtr.Zero)
{
string version = ThcrapHelper.PtrToStringUTF8(p);
VersionText.Text = "Version " + version;
}

string startUrl = null;
var cmdline = Environment.GetCommandLineArgs();

Expand Down

1 comment on commit b087e61

@brliron
Copy link
Member

@brliron brliron commented on b087e61 Sep 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was going to yell at the use of GetModuleHandle / GetProcAddress instead of DllImport on thcrap.dll, and then I noticed the comment.
Yeah, this sucks, and I think I changed a global variable to a function at some point just because I wanted to use it from C#.

Please sign in to comment.