当前位置: 代码迷 >> ASP.NET >> 请教怎么在asp.net中调用vc编写的mfc dll文件
  详细解决方案

请教怎么在asp.net中调用vc编写的mfc dll文件

热度:669   发布时间:2013-02-25 00:00:00.0
请问如何在asp.net中调用vc编写的mfc dll文件
mfc dll提供一个函数add(int a, int b),希望通过网页传递参数,完成计算。请问如何在asp.net(c#)编写的网页中调用吗?请问如何调用。希望能有例子,或则链接也可以。

------解决方案--------------------------------------------------------
[DllImport("mfc.dll")]
------解决方案--------------------------------------------------------
把vc写的dll文件放到bin目录下
然后[DllImport("文件全名")]
放在你用的函数的头上

格式:
C# code
                [DllImport("example.dll")]        public static extern int ExampleFun(ref IntPtr parameter);
------解决方案--------------------------------------------------------
然后在后面的函数里调用函数ExampleFun
建议:
最好是新建一个dll项目,在那个项目里调用mfc的dll文件
------解决方案--------------------------------------------------------
我的是直接将mstest.DLL放在system32/文件夹下
C# code
 [DllImport("mstest.dll", CharSet = CharSet.Ansi)]        public static unsafe extern int Test(int pBuf, int nSize, byte nKey);
------解决方案--------------------------------------------------------
把mstest.DLL放到你项目的bin目录就可以了
然后使用类似这样定义MFC dll中的方法
[DllImport("segment.dll")]
public static extern int SegmentA(IntPtr handle,string psrcbuf,int srclen,System.Text.StringBuilder pdstbuf,int dstlen,SEGMENT_OPT opt,ref SEGMENT_TOKEN tokens,ref int tokencount);

然后就可以在你自己的C#方法里面调用SegmentA了
------解决方案--------------------------------------------------------
用楼上的就行!!
up!!
------解决方案--------------------------------------------------------
5楼正解
  相关解决方案