大家好,我用c#调用OCX控件(contourOCX)时出现以下异常:
    “灾难性故障 (异常来自 HRESULT:0x8000FFFF (E_UNEXPECTED))”,谁知道这个问题怎么解决啊?我是新手,希望有经验人士帮帮忙啊!!!
代码如下:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace WindowsApplicationTest
{
    
    public partial class Form1 : Form
    {
        CONTOUROCXLib.ContourOCXClass mycontour = new CONTOUROCXLib.ContourOCXClass();
        //CONTOUROCXLib.ContourOCX mycontour = new CONTOUROCXLib.ContourOCX();
        public Form1()
        {
            InitializeComponent();
            
        }
        void SetContourLinesColor()
{
            mycontour.ClearColorClass();
            mycontour.AddNewElementToColorClass(0xff0000);
            mycontour.AddNewElementToColorClass(0x00ff00);
            mycontour.AddNewElementToColorClass(0x0000ff);
            mycontour.ResetContoursColor();


        void SetPolygonsColor()
        {
            
            // change color from red to green,then from green to blue
            mycontour.ClearColorClass();
            mycontour.AddNewElementToColorClass(0xff0000);
            mycontour.AddNewElementToColorClass(0x00ff00);
            mycontour.AddNewElementToColorClass(0x0000ff);
            mycontour.ResetPolygonsColor(0xffffff);        }        private void button1_Click(object sender, EventArgs e)
        {
            int Smooth = 5;
            
            
            mycontour.SetDefaultPositionValus(800, 800, 0, 800, 0, 800);
            mycontour.InitialRandom(4, 5, 1, 5);
            mycontour.FreeData();
            mycontour.SetDefaultPositionValus(100, 100, 0, 800, 0, 800);
            mycontour.InitialRandomKrigingOK(-1, 30, 1, Smooth, -1);
           
            //读取文本中数据
            string path1 = "E:\\Surfer\\等值线表.txt";
            int PointCount = mycontour.AddRandomPointsFromFile(ref path1);
            
            SetContourLinesColor();
            //set position values
            mycontour.ResetContourPosition();
            
            
            //绘制等值线
            string path2 = "E:\\Surfer\\等值线表.txt";
            mycontour.AddRandomPointsFromFile(ref path2);
            mycontour.CalculateRandom();
            mycontour.SetDefaultPositionValus(800,800,1,800,0,800);            //生成等值面
            int suc=0;
            mycontour.ConvertToPolygon(ref suc);
            //set the color
            SetPolygonsColor();
            //转换成.shp文件
            string path3="E:\\Surfer";
            string type1 = "line";
            string type2 = "polygon";
            string newFieldName = "newField";
            string FieldType = "float";
            mycontour.InitializeSHPFile(ref path3,ref type1);//.shp文件
            mycontour.AddAppendedField(ref type1,ref newFieldName, ref FieldType, 10);
            mycontour.CreateShapeFile();            mycontour.InitializeSHPFile(ref path3,ref type2);
            mycontour.CreateShapeFile();          
        }
    }
}

解决方案 »

  1.   

    mycontour.SetDefaultPositionValus(800, 800, 0, 800, 0, 800); 
    从这行开始,只要是控件相关联的都抛出异常。
      

  2.   

    大家没有你手中OCX控件,所以最好的办法就是告诉调试运行找出那行出错了,这样方便大家判断原因。
      

  3.   

    mycontour.SetDefaultPositionValus(800, 800, 0, 800, 0, 800);
    从这行开始,只要是与ocx控件相关联的都抛出异常。
      

  4.   

    上次我调用一个控件时也试过同样的情况,处理不了,后能我把这个组件当作是可视化组件插入就可以了..用引入方式就不行,不知道为什么...你可以试试,在工具箱中添加组件,然后选择你注册了的那个OCX组件,然后在工具箱中把组件添加到程序中,应该就可以了.