本帖最后由 kernel001 于 2011-12-07 09:33:11 编辑

解决方案 »

  1.   

    private const int EVENTDELAY = 3; //延时
            private const int XYRUNSPEED = 10;//x,y运动速度
            private const int IO_INPUT = 11; //输入IO检测
            private const int IO_OUTPUT = 12; //输出IO检测
            private const int LINECOORSPACE = 24; //运动到某位置 
            private const int ResetMethod = 29; //复位动作
            private const int ZUAxesSpeedS = 40;//Z,U轴速度        private const int XY_Move_Offset = 206; //相对位置移动
            private const int XYZ_Move_s = 208; //三轴联动移动        [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
            public struct WORKFILE
            {
                int filehead;
                uint x;//假如是文件索引,则保存序号
                uint y;//假如是文件索引,则保存WORKINS位置
                uint z;
                uint u;
            }        private const int Mac_Coor_LT = 0;
            private const int Mac_Coor_RT = 1;
            private const int Mac_Coor_LD = 2;
            private const int Mac_Coor_RD = 3;        [DllImport("DigOut.dll", CharSet = CharSet.Unicode, SetLastError = true)]
            public static extern bool YM_DataProcess(int method, string path, IntPtr lpData,
                double mapwi, double maphi, int coormethod);  
      

  2.   

    楼上的有几个小小的问题:
    1、C#结构体成员默认访问标识为private,需要改为public
    2、C语言默认的字符集为单字节的,不能使用Unicode
    3、WIN32的BOOL类型不能简单转换为bool,因为它是4个字节正确的转换:
            [StructLayout(LayoutKind.Sequential)]
            public struct WORKFILE
            {
                public int filehead;
                public uint x;//假如是文件索引,则保存序号
                public uint y;//假如是文件索引,则保存WORKINS位置
                public uint z;
                public uint u;
            }        [DllImport("DigOut.dll", CharSet = CharSet.Ansi)]
            [return : MarshalAs( UnmanagedType.Bool)]//4 字节布尔值(true != 0、false = 0)。这是 Win32 BOOL 类型。
            public static extern bool YM_DataProcess(int method, string path, IntPtr lpData,
                double mapwi, double maphi, int coormethod); 
      

  3.   

    感谢两位的回答另外我想咨询怎么样把我定义的WORKFILE 内存指针 传到 IntPtr lpData中来,要怎么样转换。
    WORKFILE wkf= new WORKFILE();
    wkf.filehead = 0;
    wkf.x = 0;
    YM_DataProcess(1, "r:\\1.dig", wkf,0, 0, 0);
      

  4.   

    使用 ref WORKFILE作为参数类型public static extern bool YM_DataProcess(int method, string path, ref WORKFILE wf, double mapwi, double maphi, int coormethod);  
      

  5.   

            [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
            public struct WORKFILE
            {
                public int filehead;
                public uint x;//假如是文件索引,则保存序号
                public uint y;//假如是文件索引,则保存WORKINS位置
                public uint z;
                public uint u;
            }        private const int Mac_Coor_LT = 0;
            private const int Mac_Coor_RT = 1;
            private const int Mac_Coor_LD = 2;
            private const int Mac_Coor_RD = 3;        [DllImport("DigOut.dll", CharSet = CharSet.Ansi)]
            [return: MarshalAs(UnmanagedType.Bool)]//4 字节布尔值(true != 0、false = 0)。这是 Win32 BOOL 类型。
            public static extern bool YM_DataProcess(int method, string path,
                ref WORKFILE lpData, double mapwi, double maphi, int coormethod);         static void Main(string[] args)
            {
                WORKFILE wf = new WORKFILE();
                wf.x = 0;
                wf.y = 0;
                wf.z = 0;
                bool ret = YM_DataProcess(1, "r:\\1.dig", ref wf, 0.0, 0.0, 0);
            }
    我就想传Intptr怎么老不对呢,原来是workfile的ref啊