在DLL文件中有定义这种的变量:  int I2C_position;    我如何在C#中引用呢?     希望大家支持啊.

解决方案 »

  1.   

    我在调用时候还是用
     [ DllImport ("I2C_HOST_DLL.dll")]
    public static extern int I2C_position;
    调试后报错Error 1 The modifier 'extern' is not valid for this item 请问大哥怎么使用啊 
      

  2.   

    楼上的先谢谢你了 
    如果定义的是 int I2C_position(); 是函数, [DllImport ("I2C_HOST_DLL.dll")] 
                                            public static extern int I2C_position();  这样引用没有问题关键现在int I2C_position;不是函数,是个变量啊,后面没有(), 不知道如何使用啊.
     
      

  3.   

    不能直接访问变量的在DLL里面写个方法返回这个变量就行了
      

  4.   

    比如DLL里面有个函数 int p=0;然后你写个DLL的函数 WINAPI int GetP()
                        {
                             return p;
                         }
    在C#里面[ DllImport("I2C_HOST_DLL.dll")] 
    public static extend int GetP();就可以得到P了
      

  5.   

    比如DLL里面有个变量 int p=0; 然后你写个DLL的函数 WINAPI int GetP() 
                        { 
                            return p; 
                        } 
    在C#里面 [ DllImport("I2C_HOST_DLL.dll")] 
    public static extend int GetP(); 就可以得到P了口误。。
      

  6.   

    [ DllImport ("I2C_HOST_DLL.dll")] 
    public static extern int I2C_position(); Deathsign已经说的很清楚了啊。你要的值其实就是int a=I2C_position();这里a就是你要的变量。
      

  7.   

    如果不使用编写个DLL的函数 WINAPI int GetP() 
                        { 
                            return p; 
                        }   直接引用DLL的这个变量:  int I2C_position; 
      是不是不能直接用啊 ???
      小弟还不会编写DLL程序,有没有方法可以直接引用啊??