- 在线时间
- 13 小时
- 最后登录
- 2013-12-8
- 注册时间
- 2010-5-13
- 听众数
- 3
- 收听数
- 0
- 能力
- 0 分
- 体力
- 399 点
- 威望
- 11 点
- 阅读权限
- 30
- 积分
- 282
- 相册
- 0
- 日志
- 0
- 记录
- 0
- 帖子
- 97
- 主题
- 45
- 精华
- 0
- 分享
- 0
- 好友
- 1
升级 91% TA的每日心情 | 难过 2012-8-27 18:22 |
---|
签到天数: 1 天 [LV.1]初来乍到
|
一个简单的c#调用Forcal的例子- using System;
- 1 u; q* n! z\\" @) o9 t8 a! U* ^# e
- using System.Collections.Generic;
- 9 h6 R, k' k0 a1 H; a3 U/ V9 W& @
- using System.Linq;
- * S8 t+ T' L& D! f6 o
- using System.Text;
- ! a8 ]+ x8 T' _9 ?2 c9 @( Z) d
- using System.Runtime.InteropServices;) f3 B* Y# j! _2 I+ E7 I8 J
- ' [# J- n1 ~$ a3 j) q
- public class forcal) @: N% L8 @, }' N. |% F/ t. e
- {
- & z: f4 Z0 r* V, I5 _; I. t7 w
- [DllImport("Forcal32W.dll")]
- 2 r# @1 G7 w: h$ l; l
- public static extern bool InitForcal();
- . f* z2 q; r* C- p5 e) i
- [DllImport("Forcal32W.dll", CharSet = CharSet.Unicode)] //使用Unicode字符集
- 1 j$ z) f1 U6 c$ t1 Y; f' D/ \4 n8 k
- public static extern int RealCom(string ForStr, int nModule, ref int hFor, ref int nPara, ref int Para, ref int ErrBegin, ref int ErrEnd);
- : j; i) h9 f6 C0 @+ n
- [DllImport("Forcal32W.dll")]
- & Q, H2 O3 |$ q$ n2 E. @' k( b! K
- public static extern double RealCal(int hFor, double[] d);4 v! O! u* n7 @( j
- [DllImport("Forcal32W.dll")]* T( o6 x! b( |: W2 l1 L
- public static extern void FreeForcal();$ q! A+ P( S/ R! N$ p
- }6 ^\\" x8 l8 I% h* m& {
- , [; ~; J0 D. R4 k% c4 ~' _3 b3 O; [
- namespace CsharpForcal; Y' y0 a- M9 g) y3 w) k
- {5 n6 Z7 m# F4 d2 ]
- class Program4 m8 Y/ D7 J7 e# T; y/ ~: b
- { Z U4 l5 H& d3 g
- static void Main(string[] args)- {5 H# A/ ?\\" M9 X0 g$ K\\" }. J: v( l
- {- Y7 \+ V/ ]& x5 [+ a
- bool flag = false;
- # R: N3 M# m# u+ O7 v
- 6 ^: i/ S' n9 i7 T) ]4 b( K3 r
- int code = 0;5 i6 Q! a$ l/ d
- int hFor = 0; //必须为0,否则是一个加锁模块的函数指针
- 9 U; y9 e5 w! K' t8 h0 M
- int nModule = 1;* b1 `* I3 Q\\" N) x2 L
- int len = 0;
- 1 Y6 r+ h2 e3 C9 [
- int Para = 0;
- % `% _3 U) V, S% V# D5 O9 s
- int e1 = 0;& Y5 f, `' ^0 u4 t
- int e2 = 0;
- 6 ^- i( k/ v4 S' x9 q
- double[] MyArgs = new double[2] { 2, 3 };
- # \$ q% N2 B% V8 v M0 U
- % F* k- I& p1 t/ R7 H6 i S
- flag = forcal.InitForcal();. |0 z F1 e\\" w7 e2 I3 N
- & Y+ X) n Z# r7 ^7 |
- string s = "f(x,y)=x+y";
- ) x+ b\\" M# o X! L( c' p) Z( [
- code = forcal.RealCom(s, nModule, ref hFor, ref len, ref Para, ref e1, ref e2);& V. @* |* V# ]\\" `/ O! g& L
- Console.Write(code);1 {# z. h\\" n6 {7 u' r8 W3 D2 ^6 X
- + ^5 t3 j$ r: e$ ]
- if (code == 0)5 p\\" S, W. o\\" z4 k; K, [+ t5 o& X
- {# \ ^2 Q; \' A4 d
- double dd = forcal.RealCal(hFor, MyArgs);
- / J5 Z7 S' Y) [# j% ^: ^7 @
- Console.Write("\r\n结果=");
- / _( q$ Z5 d+ U
- Console.Write(dd);. D$ N2 Q9 n6 t4 L* e
- Console.Write("\r\n");
- $ V4 f' ~+ C9 _9 X- ]- r9 i
- }
- ' T: | H\\" S3 Q4 S! u7 Q
- ) @' { R1 ?) R6 _
- forcal.FreeForcal();6 O\\" u% x. T0 ^( H
- }
- ' p* h2 B1 ~/ t/ @4 c m
- }
- 1 W4 I% O: n% c/ B7 ^\\" W
- }
|
|