当前位置:编程学习 > C#/ASP.NET >>

新手请教c#调用vc的dll中的函数 int test1(int flag ,void(*ast)=NULL)

dll的名称为“test.dll”
dll的函数为: int test1(int flag ,void(*ast)=NULL);
在c#中怎么调用这个函数?

目前知道大概下面这样的格式:
    [DllImport("test.dll")]
    public static extern int test1(????);
  
具体怎么做?请高手赐教 --------------------编程问答--------------------
ast是void * 指针?看起来别扭,

这样就可以了,

[DllImport("test.dll")]
  public static extern int test1(int flag,IntPtr ast); --------------------编程问答-------------------- 这样声明:

public delegate void Ast();
[ DllImport( "xxxx.dll" )]
public static extern void test1(int flag,Ast ast);
--------------------编程问答-------------------- 自己顶一下
希望高手指导 --------------------编程问答-------------------- 自己顶一下
希望高手指导 --------------------编程问答-------------------- 我在vc中是这么用的
 int test1(28,receive);
void receive()

.....

在c#中怎么用?
也可以自己定义一个函数名
例如:[DllImport("test.dll")]
  public static extern int test1(int flag,IntPtr receive);
void receive()
{
.....
} --------------------编程问答-------------------- 这样的话,应该是:

public delegate void Receive();

[DllImport("test.dll")]
public static extern int test1(int flag,Receive ast);

void receive()
{
.....
}

xxx.test1(28,receive);
--------------------编程问答-------------------- lz,你用到了回调函数,C#要用委托对应!MSDN的例子如下:
C++:

void TestCallBack(FPTR pf, int value);


C#:

public delegate bool FPtr( int value );
[DllImport( "..\\LIB\\PinvokeLib.dll" )]
public static extern void TestCallBack( FPtr cb, int value );   


public class App
{
   public static void Main()
   {
      FPtr cb = new FPtr( App.DoSomething );
      LibWrap.TestCallBack( cb, 99 );
   }
   
   public static bool DoSomething( int value )
   {
      Console.WriteLine( "\nCallback called with param: {0}", value );
      …
   }
}
 

补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,