libFLAC库是否有.net c#包装器?如果没有,我如何在.net框架c#应用程序中使用libFLAC读取FLAC标记?如果没有,是否有其他开源库来读取c#中的flac标签?
谢谢!
我有一个用c ++编写的dll.我正在调用函数调用.
我有这个c ++声明.
int dll_registerAccount(char* username, char* password);
Run Code Online (Sandbox Code Playgroud)
我做了这个dllimport声明:
[DllImport("pjsipDlld")]
static extern int dll_registerAccount(IntPtr username, IntPtr password);
Run Code Online (Sandbox Code Playgroud)
我的DllImport是否相当于使用IntPtr的c ++?
非常感谢任何建议,
根据我的学习,在F#中使用P/Invoke,必须首先使用DllImport声明函数签名,如下所示:
[<DllImport("kernel32.dll", EntryPoint="CopyFile")>]
extern bool copyfile(char[] lpExistingFile, char[] lpNewFile, bool bFailIfExists);
Run Code Online (Sandbox Code Playgroud)
在编译时知道DLL名称时,这一切都很好.如果我只能在运行时发现名称,如何与非托管C/C++ DLL接口?
我编写了一个C DLL和一些C#代码来测试包含这个DLL并从中执行函数.我对这个过程并不太熟悉,每当从C#源代码调用DLL函数时,我都会收到PInvokeStackImbalance异常.代码如下(我已经评论了大多数代码来隔离这个问题):
C#包含代码:
using System;
using System.Runtime.InteropServices;
using System.IO;
namespace TestConsoleGrids
{
class Program
{
[DllImport("LibNonthreaded.dll", EntryPoint = "process")]
public unsafe static extern void process( long high, long low);
static void Main(string[] args)
{
System.Console.WriteLine("Starting program for 3x3 grid");
process( (long)0, (long)0 );
System.Console.ReadKey();
}
}
}
Run Code Online (Sandbox Code Playgroud)
C++ DLL函数代码
extern "C" __declspec(dllexport) void process( long high, long low );
void process( long high, long low )
{
// All code commented out
}
Run Code Online (Sandbox Code Playgroud)
Visual Studio生成了dllmain代码(我不明白这个构造,所以我包括它)
// dllmain.cpp : Defines the …Run Code Online (Sandbox Code Playgroud) 我正在研究一个F#控制台应用程序.在属性中,我将应用程序的输出类型设置为Windows应用程序以隐藏控制台.我还创建了一个在其位置运行的表单.目前我只有一个没有控件的简单表单.为了使形式我添加referances到System.Windows.Forms并System.Drawing把包裹打开一起System.Runtime.InteropServices.
我不知道怎么做的部分是扩展航空玻璃.如何在C#中做到这一点有很多问题.例如,这是API调用和MARGINS结构:
[StructLayout(LayoutKind.Sequential)]
public struct MARGINS
{
public int cxLeftWidth;
public int cxRightWidth;
public int cyTopHeight;
public int cyBottomHeight;
}
[DllImport("dwmapi.dll")]
pubic static extend int DwmExtendFrameIntoClientArea(IntPtr hWnd, ref MARGINS pMarInset);
Run Code Online (Sandbox Code Playgroud)
来自Form_Load事件的API调用:
MARGINS margins = new MARGINS();
margins.cxLeftWidth = 0;
margins.cxRightWidth = 100;
margins.cyTopHeight = 0;
margins.cyBottomHeight = 0;
int result = DwmExtendFrameIntoClientArea(this.Handle, ref margins);
Run Code Online (Sandbox Code Playgroud)
这是我到目前为止在F#中得到的:
API调用和MARGINS结构:
[<StructLayout(LayoutKind.Sequential)>]
type MARGINS =
struct
val cxLeftWidth : int
val cxRightWidth : int
val cyTopHeight : …Run Code Online (Sandbox Code Playgroud) 我正在使用Delphi构建DLL,它需要与Windows API的工作方式类似.这个DLL只有一个导出函数......
function DoSomething(var MyRecord: TMyRecord): Integer; stdcall;
Run Code Online (Sandbox Code Playgroud)
... where TMyRecord=我的记录我需要在C#中重新创建.如果我没有弄错,这正是标准Windows API的工作原理.此记录还包含对另一种记录类型的引用...
TMyOtherRecord = record
SomeDC: HDC;
SomeOtherInt: Integer;
end;
TMyRecord = record
SomeInteger: Integer;
SomeColor: TColor;
SomeText: PChar;
SomeTextSize: Integer;
MyOtherRecord: TMyOtherRecord;
end;
Run Code Online (Sandbox Code Playgroud)
问题第1部分:
我想看看我是否可以避免使用PChar,如果可能的话.我不希望传递超过255个字符的内容.是否有其他类型我可以使用而不需要我使用size of string?
问题第2部分:
我需要仔细检查我是否正确地声明了这个C#struct类,因为它需要完全匹配Delphi中声明的Record ...
public struct MyOtherRecord
{
public IntPtr SomeDC;
public int SomeOtherInt;
}
public struct MyRecord
{
public int SomeInteger;
public Color SomeColor;
public string SomeText;
public int SomeTextSize;
public MyOtherRecord OtherReord = new MyOtherRecord();
}
Run Code Online (Sandbox Code Playgroud)
问题第3部分:
在这种情况下,在记录(或结构内部的结构)中有记录是否安全?很确定它是,但我需要确定.
在浏览SWig生成的包装器时,我发现PInvokes没有定义任何入口点,但有些地方确实有入口点.那么他们之间有什么区别?我什么时候需要定义一个EntryPoint,什么时候不需要?
定义没有EntryPoint:
[DllImport("Kernel32.dll", CharSet = CharSet.Unicode)]
public static extern bool ReadFile(
HandleRef hndRef,
StringBuilder buffer,
int numberOfBytesToRead,
out int numberOfBytesRead,
int flag);
Run Code Online (Sandbox Code Playgroud)
定义为Entrypoint:
[DllImport("Kernel32.dll", CharSet = CharSet.Unicode, EntryPoint = "ReadFile")]
public static extern bool ReadFile2(
HandleRef hndRef,
StringBuilder buffer,
int numberOfBytesToRead,
out int numberOfBytesRead,
Overlapped2 flag);
Run Code Online (Sandbox Code Playgroud)
为什么功能必须static如此public static extern?我假设这extern告诉编译器这个方法是在外部定义的吗?
我正在尝试围绕用本机代码编写的第三方库编写ac#wrapper,以便在我们的应用程序中使用,这些应用程序几乎都是用.NET编写的,我正在努力保持对C#模式的忠诚.这个库中的几乎所有调用本质上都是异步的,将所有异步调用包装到Task <T>对象中似乎是合适的.这是一个过于简单的示例,说明了本机库的结构:
delegate void MyCallback(string outputData);
class MyNativeLibrary
{
public int RegisterCallback(MyCallback callback); // returns -1 on error
public int RequestData(string inputData); // returns -1 on error
}
Run Code Online (Sandbox Code Playgroud)
现在,我通过事件订阅提供了我的返回值,但我相信这将是一个更好的方法来返回我的数据:
class WrapperAroundNativeCode
{
public async Task<string> RequestData(string inputData);
}
Run Code Online (Sandbox Code Playgroud)
到目前为止,我一直未能找到适当的方法来实现这一点,而且我正在接触那些在使用Task <T>对象和async/await模式方面比我更有经验的人.
我昨天发布了关于如何将C程序转换为C#作为我的第一个C#项目:从C转换为C#,还是制作DLL?.我已经取得了很大的进步,但我被困在了一个部分.我不知道如何重新创建这个unsigned char数组
C代码:
unsigned char state_buf[5125];
//--------------------------------------------------------------------------
// Main of iSerial64
//
void main(int argc, char **argv)
{
char refresh,buf[200];
short flag,i,didsetup=0;
short ROM[9];
short PortNum,PortType;
long SHandle;
char serialtmp[2], serial[10][17];
int j = -1;
Run Code Online (Sandbox Code Playgroud)
....
这是C#中使用PInvoke获取state_buf的函数http://files.maximintegrated.com/sia_bu/licensed/docs/1-wire_sdk_win/TMEX/romm1rxq.html
我用来从api导入函数的C#代码:
[DllImport("IBFS64.dll")]
public static extern short TMRom(
int session_handle,
byte state_buf,
[MarshalAs(UnmanagedType.LPStr)]StringBuilder ROM
);
Run Code Online (Sandbox Code Playgroud)
我看到那个字节是C#的等价物,但我不完全确定如何使用它.
到目前为止,你们都非常乐于助人,我对我在这方面所取得的进展感到非常满意.
这是我昨天以来在C#中所做的事情:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
namespace PInvokeTest {
class Program {
static void Main(string[] args)
{
int session_handle …Run Code Online (Sandbox Code Playgroud) EnumWindows 的文档强调:
注意对于Windows 8及更高版本,EnumWindows仅枚举桌面应用程序的顶级窗口.
"桌面应用"和"非桌面应用"有什么区别?
这与metro应用程序有关吗?
我问,因为与Win7相比,EnumWindows在Win10中的表现有所不同.
pinvoke ×10
c# ×8
dllimport ×2
f# ×2
windows ×2
async-await ×1
c ×1
c++ ×1
delphi ×1
delphi-7 ×1
dll ×1
interop ×1
marshalling ×1
native ×1
windows-10 ×1