繁体   English   中英

如何导入Powerflex函数以在C#中使用?

[英]How should I import Powerflex functions for use in C#?

我已获得在Visual Studio 2010 C#中使用pfxlibn.dll的任务, 所知 ,这是一个Powerflex库。 http://pfxcorp.com/clib-fns.htm

我尝试了一些导入PclGetField函数的变体,例如:

[DllImport("pfxlibn.dll", SetLastError = true)]
public static extern void PclGetField(
    Int32 iHandle, 
    Int32 iFieldNum, 
    [MarshalAs(UnmanagedType.LPStr)] string Date
    ); 

[DllImport("pfxlibn.dll",
    CallingConvention = CallingConvention.StdCall,
    CharSet = CharSet.Ansi,
    EntryPoint = "PclGetField")]
public static extern int PclGetField(Int32 iHandle, Int32 iFieldNum, string Data)

[DllImport("pfxlibn.dll", EntryPoint = "PclGetField",
    ExactSpelling = true,
    CharSet = CharSet.Ansi,
    CallingConvention = CallingConvention.Cdecl)]
public static extern Int32 PclGetField(Int32 iHandle, Int32 iFieldNum,[MarshalAs(UnmanagedType.VBByRefStr)] ref string input);

到目前为止,以上方法均无效。 还是以上的变化。

在Delphi中,代码看起来像

pTmpBuf           : PChar;

iLastErr := PclGetField(fHandle,iField,pTmpBuf);

您链接到的文档非常稀少,因此要回答我们需要猜测的问题。

您需要的功能如下:

aResult PCLENTRY PclGetField (aDHandle fdh, anInt eno, aString data);
//Retrieves the formatted value of a field from a file buffer.

aResult PCLENTRY PclGetFieldLen (aDHandle fdh, anInt eno, anInt *length); 
//Gets the length of a field.

为了确定如何处理此问题,我们需要更多信息:

  • PCLENTRY宏会评估什么? 我将假设__stdcall ,但是您将需要检查头文件。
  • 什么是aResult 我将假定为int但您需要检查头文件。
  • 什么是aDHandle 我将假定为void*INT_PTR但您需要检查头文件。
  • 什么是anInt 我将假定为int但您需要检查头文件。
  • 使用什么字符集? ANSI还是Unicode? 我将假设使用ANSI。

您将需要调用PclGetFieldLen来找出所需的缓冲区大小。 然后,您将分配该缓冲区并调用PclGetField进行填充。 您将需要找出PclGetFieldLen返回的值是否包含零终止符。 我假设事实并非如此。

基于这些假设,您可以这样编写pinvoke:

[DllImport("pfxlibn.dll", CallingConvention=CallingConvention.Stdcall)]
public static extern int PclGetFieldLen(fdh IntPtr, int eno, out int length); 

[DllImport("pfxlibn.dll", CallingConvention=CallingConvention.Stdcall,
    CharSet=CharSet.Ansi)]
public static extern int PclGetField(fdh IntPtr, int eno, StringBuilder data);

然后,您可以像下面这样调用函数:

IntPtr fdh = .... // whatever function creates the database handle
int eno = .... // get the field number from somewhere
int length;
int res = PclGetFieldLen(fdh, eno, out length);
//check res for errors
StringBuilder data = new StringBuilder(length);
res = PclGetFieldLen(fdh, eno, data);
string field = data.ToString();

由于我们不了解所有详细信息,因此此答案中有一堆未知数。 您具有头文件,并且可以与图书馆供应商联系以解决未知问题。 但希望上面的概述告诉您需要回答什么问题。

感谢David Heffernan,但是,我没有提供足够的信息或没有足够研究delphi代码。

缺少的主要项目是PclClear,PclPutField和PclFind。 此后,我发现了以下作品:

    [DllImport("pfxlibn.dll")]
    public static extern Int32 PclOpen(Int32 iHandle, String sName, Int32 iIndex);

    [DllImport("pfxlibn.dll")]
    public static extern Int32 PclClear(Int32 iHandle);

    [DllImport("pfxlibn.dll")]
    public static extern Int32 PclPutField(Int32 iHandle, Int32 iFieldNum, String sData);

    [DllImport("pfxlibn.dll")]
    public static extern Int32 PclFind(Int32 iHandle, Int32 iRelOp, Int32 iIndex);

    [DllImport("pfxlibn.dll")]
    public static extern Int32 PclGetFieldLen(Int32 iHandle, Int32 iField, out int length);



        error = CLib.PclOpen(_handle, path, 0);
        error = CLib.PclClear(_handle);
        error = CLib.PclPutField(_handle, 0, "10");  //searching for recnum 10
        error = CLib.PclFind(_handle, 1, 0);  // 0 = recnum index
        error = CLib.PclGetFieldLen(_handle, iField, out flenght);
        StringBuilder data = new StringBuilder(flenght);
        CLib.PclGetField(_handle, iField, data);

        if (error == 0)
        {
            return data.ToString();  
        }

我知道上面有废话错误捕获,我将很快修复。 我只想回复并感谢大卫的帮助。 另外,如果其他任何人都无法使用pfxlibn.dll导出数据,他们可能会发现这很有用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM