- 在线时间
- 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;
- . x, g% B }' ]; b, }: _( Q
- using System.Collections.Generic;, r9 R; X$ p: C7 l3 S- M
- using System.Linq;. h5 G2 K y3 Q' E1 @ C
- using System.Text;. Z# f/ Z+ {% i }
- using System.Runtime.InteropServices;. D9 p' p$ z0 s( W0 W
- 5 x4 X- D8 ]# b2 Y+ b9 f
- public class forcal
- - t$ t4 W6 i- d2 }
- {
- ) u' J6 y2 q m. I
- [DllImport("Forcal32W.dll")]
- ( J0 U1 Y- S8 K' x# a5 o
- public static extern bool InitForcal();) Z |4 X' J; c) Y3 f2 O
- [DllImport("Forcal32W.dll", CharSet = CharSet.Unicode)] //使用Unicode字符集8 k8 f. u& S1 z' \
- public static extern int RealCom(string ForStr, int nModule, ref int hFor, ref int nPara, ref int Para, ref int ErrBegin, ref int ErrEnd);1 i1 U1 Q6 U0 W7 y R
- [DllImport("Forcal32W.dll")]& U# }0 q* t$ r* q5 v
- public static extern double RealCal(int hFor, double[] d);/ } O- o! b: Q9 i5 U) I- p3 d
- [DllImport("Forcal32W.dll")]
- q0 b B/ @/ V
- public static extern void FreeForcal();$ y5 k# ^( g7 S' b4 K* q
- }! i) H% N1 W \2 l
- 7 l0 j2 O9 L4 k- Q- K
- namespace CsharpForcal
- . Q7 W# O7 ^8 x8 R) \! Y
- {
- 5 b) i2 j. e2 J5 t3 z& u
- class Program2 _6 [% K/ |3 y
- {
- 0 d. C7 g% y5 R9 I0 Y6 O, ]
- static void Main(string[] args)3 p. Z2 s. l5 T! P/ s; }9 f9 ?
- {
- & [6 w) N. ^* p2 t
- bool flag = false;
- 2 t3 {4 i, G H% \
- : F) t' B0 X0 i& h
- int code = 0;
- 9 L: ?, A, u0 b
- int hFor = 0; //必须为0,否则是一个加锁模块的函数指针: i4 h: f1 {# P: ]\\" Y
- int nModule = 1;7 ^5 |9 N! w! [3 W
- int len = 0;5 s- x( R4 V0 b2 l8 V8 u# g1 s
- int Para = 0;
- 0 W, }& D6 a' v% F4 A7 j( p* u
- int e1 = 0;
- ( @& t, \4 o0 ^: Z/ {( U
- int e2 = 0;
- / e7 [9 p1 j/ D- x: A% K2 @
- double[] MyArgs = new double[2] { 2, 3 };( G! g\\" K4 c6 a: `, Y, ^
- $ D- }. a- T% ?, U3 [
- flag = forcal.InitForcal();4 j( U1 v' K! _2 k F% n
- 3 A! v( {6 I) s9 q0 u9 r0 T8 x! ~
- string s = "f(x,y)=x+y";
- 8 O1 A' x$ v3 a! V
- code = forcal.RealCom(s, nModule, ref hFor, ref len, ref Para, ref e1, ref e2);\\" O# c9 A$ O6 m( ~, o7 ]1 x
- Console.Write(code);6 h1 ~! T6 h; @4 K! C0 @; ~
- 1 o: ?6 d; ~+ t2 `$ Q
- if (code == 0)
- ( k% C- I( M* y3 W% b
- {
- ; x4 n/ b/ y+ v
- double dd = forcal.RealCal(hFor, MyArgs);
- % D& q, \3 k5 b$ U
- Console.Write("\r\n结果=");
- , s\\" `: j* R. v# {
- Console.Write(dd);
- 4 u9 {. \$ n\\" x3 m. w
- Console.Write("\r\n");
- g% R( t( n1 o6 S! E/ l( Z2 M
- }9 f+ i* P7 ?+ d/ ] e
- 7 t3 N+ q- J/ M/ Y
- forcal.FreeForcal();$ P. S9 i9 U# M1 ? N' l
- }
- * C; `( T/ i) I/ o) V+ z* y
- }
- + h0 K# d$ U+ J% M3 I9 D; E
- }
|
|