- 在线时间
- 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;
- . g4 q% u0 f7 ^9 S' S/ n3 J
- using System.Collections.Generic; _2 U, p\\" t3 I1 X; {
- using System.Linq;
- ( Q4 i% J; {3 l Y( Y9 s. d! d
- using System.Text;
- $ C. O: d& x7 J* H: }/ W
- using System.Runtime.InteropServices;, B) A# [, S( B/ Z; J$ B9 C3 n. J/ R
- , \. u' v1 z: `, O8 G0 ~
- public class forcal
- 9 o3 N4 l; q* b8 f' ~- E$ v. F) M
- {
- 8 s8 T; u& n8 i' f& D5 ^! E
- [DllImport("Forcal32W.dll")]
- 4 I& ]5 |+ ]4 ]3 D9 f' S1 y\\" L\\" U, l
- public static extern bool InitForcal();
- ; b. j. N& O6 Q3 |9 }
- [DllImport("Forcal32W.dll", CharSet = CharSet.Unicode)] //使用Unicode字符集
- ' H1 }& _/ r- A7 \ b( m
- public static extern int RealCom(string ForStr, int nModule, ref int hFor, ref int nPara, ref int Para, ref int ErrBegin, ref int ErrEnd);
- 2 o H. R3 h3 [\\" z
- [DllImport("Forcal32W.dll")]0 ]$ j+ A, d# ]8 t, B1 b2 I- O
- public static extern double RealCal(int hFor, double[] d);
- ' O- q/ B: h* p9 w
- [DllImport("Forcal32W.dll")]6 T6 |: c4 v2 h8 s! @
- public static extern void FreeForcal();3 C3 U1 P2 `' S! H: ~, c% ?2 k& r( w
- }! S# S\\" J# j2 A ?5 M, ?& _
- # M4 X1 m' E& m( Y. q# }; U
- namespace CsharpForcal
- 0 W/ n* G# z' ^ |5 L1 A
- {
- 3 |, R# D$ H% Z+ g
- class Program
- 3 M3 o/ x2 w% d$ z9 U
- {
- # R) g8 i8 l$ w% A- L- P) ~
- static void Main(string[] args)/ H+ M4 C' c) o% y: F2 Y& b
- {
- 9 @- k& I! g' F0 P7 ?
- bool flag = false;% N5 u' Y2 D# ~( o% {4 H. Q
- : A8 X, e+ N; t2 Q3 D
- int code = 0; {1 n6 _, [+ i/ V: m! v% O
- int hFor = 0; //必须为0,否则是一个加锁模块的函数指针- A7 } d\\" g5 L* [& P) @
- int nModule = 1;
- ) `% S9 [7 S. `! E\\" N- d4 s. F* n
- int len = 0;
- 5 r$ e0 }# ^% g' l6 h# c5 _
- int Para = 0;
- ; x- @4 p; a3 T7 ^
- int e1 = 0;
- 5 ]6 Z! \! `- |. X
- int e2 = 0;
- 0 h+ y5 R/ @# ?1 h9 N1 K$ y) u
- double[] MyArgs = new double[2] { 2, 3 };, d* g, F% X J7 { A. p8 n4 {6 A, m
- 0 W8 u n0 F1 K' g, f8 v& c
- flag = forcal.InitForcal();) S2 R% Q) @% G
- 5 T9 i3 e7 E, Z( {( Y
- string s = "f(x,y)=x+y";0 g' P# W4 B- g, r, x1 Q' B8 l
- code = forcal.RealCom(s, nModule, ref hFor, ref len, ref Para, ref e1, ref e2);
- 3 X% [$ s. D+ Z: P
- Console.Write(code);
- ; v+ o: x. N E2 ^) u: X4 X0 G
- ; Y! `7 \) C; r( T0 c- G7 L
- if (code == 0)
- 0 g; z c( f& m1 c3 W3 L' o
- {0 N& f6 }7 g# g6 U: M
- double dd = forcal.RealCal(hFor, MyArgs);
- 1 M! L8 V% l5 {1 S6 y! `
- Console.Write("\r\n结果=");( q& b0 U3 e& V5 c9 g. }4 v
- Console.Write(dd);6 W) o* H6 O3 a( {0 _
- Console.Write("\r\n");
- . X# T- i, L$ [/ {8 S' I# G
- }+ v4 P' P8 y$ X q6 h
- $ N$ _9 t( o0 E6 P
- forcal.FreeForcal();
- 6 m/ d1 I. y' K( T
- }
- $ s! ?. m9 W, A! o
- }
- ' d& d2 n; W0 C8 z+ F6 p+ ^1 {2 T
- }
|
|