crpe32.dll C# - 无法向Report添加/获取参数

时间:2012-11-19 10:46:49

标签: c# types crystal-reports dllimport

我在使用crpe32.dll打印Crystal Reports时遇到问题(出于某些原因,我们无法使用CrystalDecisions.CrystalReports.Engine中的ReportDocument clss)。当我尝试打印没有参数的报告时,没有任何错误。它应该使用导入的DLL中的方法:
- PEOpenEngine
- PEOpenPrintJob
- PEOutputToPrinter
- PEStartPrintJob
- PEClosePrintJob
- PECloseEngine

但我遇到必须传递结构的方法有问题,例如PEGetNthParameterField或PEAddParameterCurrentValue。结果我仍然“假”,我的结构没有改变。

private static void PrintTest()
    {
        int o1 = PEOpenEngine();
        if (o1 == 0)
        {
            return;
        }

        int o2 = PEOpenPrintJob("someReport.rpt");

        short paramCounts = PEGetNParameterFields(o2); // I've got here 4 in one of my real reports

        PEParameterFieldInfo paramInfo = new PEParameterFieldInfo();
        paramInfo.StructSize = 316;
        bool isParamCorrect = PEGetNthParameterField(o2, 0, ref paramInfo); // false :( and unchanged paramInfo

        int o3 = PEOutputToPrinter(o2, 1);
        int o4 = PEStartPrintJob(o2, true);
        int o5 = PEClosePrintJob(o2);

        int oLast = PECloseEngine();
    }

    [DllImport("crpe32.dll")]
    static extern short PEGetNParameterFields(int PrintJob);
    [DllImport("crpe32.dll")]
    static extern bool PEGetNthParameterField(int PrintJob, int parameterN, ref PEParameterFieldInfo parameterInfo);

可能是我的问题的根源 - PEParameterFieldInfo结构

    public struct PEParameterFieldInfo
    {
        public int StructSize;
        public int ValueType;
        public int DefaultValueSet;
        public int CurrentValueSet;
        public string Name;
        public string Prompt;
        public string DefaultValue;
        public string CurrentValue;
        public string ReportName;
        public int needsCurrentValue;
        public int isLimited;
        public double MinSize;
        public double MaxSize;
        public string EditMask;
        public int isHidden;
    }

你知道这里有什么问题吗?

1 个答案:

答案 0 :(得分:0)

这是我使用的结构声明的一个例子,也许它可能是错误的原因?

    private struct PESubreportInfo
    {
        public short StructSize;
        [MarshalAs(UnmanagedType.ByValArray, SizeConst = PE_SUBREPORT_NAME_LEN)]
        public char[] Name;       
    }