小编Jac*_*jek的帖子

如何 P/Invoke os_log?

在 .NET Core 控制台应用程序中从 C# 调用 MacOS 的 os_log 的语法应该是什么

基于
https://developer.apple.com/documentation/os/os_log

如何将 iOS OSLog 与 Xamarin 一起使用?

https://opensource.apple.com/source/xnu/xnu-4903.221.2/libkern/os/log.h.auto.html
我期待这样的事情:

using System.Runtime.InteropServices;

namespace Foo 
{
 class Program
 {
  [DllImport("__Internal", EntryPoint = "os_log_create")]
  private static extern IntPtr os_log_create(string subsystem, string category);

  [DllImport("__Internal", EntryPoint = "os_log")]
  private static extern void os_log(IntPtr log, string format, string message);

  static void Main(string[] args)
  {  
   IntPtr log = os_log_create("some.bundle.id", "SomeCategory");
   os_log(log, "%s", "Test!");
  }
 }
}
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试在我的 Mac 上运行它时,我得到一个System.DllNotFoundExceptionUnable to …

c# macos pinvoke .net-core oslog

2
推荐指数
1
解决办法
655
查看次数

如何在.NET Core控制台应用程序中获取MacOS用户名?

我在 MacOS 上的 .NET Core 中有一个 (C#) 控制台应用程序。

\n\n

\xc2\xa0

\n\n

如何获取当前用户名?

\n\n

\xc2\xa0

\n\n

我试过

\n\n

环境.GetEnvironmentVariable(“用户”);

\n\n

\n\n

环境.GetEnvironmentVariable(“用户名”);

\n\n

但我什么也没得到。

\n\n

我想getpwuid()根据此处描述的提示尝试 P/Invoke:\xc2\xa0

\n\n

/sf/answers/1318942061/ \xc2\xa0

\n\n

但我不确定该passwd结构的 C# 语法应该是什么。

\n\n

对此表示赞赏的任何帮助,以及 P/Invoke 上资源的任何指示都可以帮助我了解 P/Invoke 从 .NET Core 到 MacOS 本机代码的诀窍。

\n

c# macos pinvoke .net-core

2
推荐指数
1
解决办法
1006
查看次数

标签 统计

.net-core ×2

c# ×2

macos ×2

pinvoke ×2

oslog ×1