- 在线时间
- 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;& V$ P; u# j4 l5 [; \( w+ O
- using System.Collections.Generic;! j1 Y' [) |$ S+ z/ _: r
- using System.Linq;
- : d- F* a6 w4 G2 I( t8 D: [
- using System.Text;# a5 J4 V$ F) [8 b
- using System.Runtime.InteropServices;/ t# w2 D. M. m X+ o- d' p
- ; \: z\\" g# h6 p3 L5 L, z- Z R1 T
- public class forcal
- . S5 a0 x- `# Z: x+ L1 a1 @
- {
- % s1 x9 ~\\" G. z) Z
- [DllImport("Forcal32W.dll")]
- . \0 H) u6 ^- N2 x7 Q
- public static extern bool InitForcal();
- 5 V* U) y4 E& z' y4 E+ t% @
- [DllImport("Forcal32W.dll", CharSet = CharSet.Unicode)] //使用Unicode字符集
- 5 P; x3 d3 f8 T2 \9 x: [2 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);
- ; C6 m1 b* w8 s |& u
- [DllImport("Forcal32W.dll")]
- ) R+ W- L5 Z1 |: G$ a, T% |! k
- public static extern double RealCal(int hFor, double[] d);7 ]' ]( o+ I, _
- [DllImport("Forcal32W.dll")]' f5 e8 Z. r: B( r
- public static extern void FreeForcal();
- & _% y2 d4 ~0 s: g8 j
- }* p+ h8 ~- i# B0 x
- & m1 W2 `( r$ d+ N
- namespace CsharpForcal% {0 B1 O N1 L6 T* N
- {
- 6 _/ J5 N8 g0 {7 \9 u! V
- class Program! H3 c9 _! c% K. k
- {% O4 T! d: Y! v
- static void Main(string[] args)/ |6 m2 H2 x2 {1 @
- {4 |6 g8 S9 h! U+ z7 L% v5 _' ]
- bool flag = false;2 I+ G, _! r8 L) m4 P$ k
- 5 ~ R/ r& ^, Z+ v7 p% g# n
- int code = 0;
- 1 {( h6 x- }& S6 K6 s& {) M
- int hFor = 0; //必须为0,否则是一个加锁模块的函数指针- [$ ^ L% [2 _5 P9 j# w! s\\" a
- int nModule = 1;: U! N ^3 F* u* `4 f. `9 q
- int len = 0;. b% {* b1 Y: }, X
- int Para = 0;# x+ R9 j+ G; ?$ S* X
- int e1 = 0;
- $ m: p! p: o) `+ l' R
- int e2 = 0;
- % `4 G- y/ b% E2 J; X
- double[] MyArgs = new double[2] { 2, 3 };
- ' N( e\\" V- \5 \0 q) F$ h
- , N$ |& k3 {8 _' Q
- flag = forcal.InitForcal();) [+ B* [6 \! Q3 j
- ( i9 G& ]& P! Z2 t: l6 t4 C
- string s = "f(x,y)=x+y";, ~\\" |1 x; q8 h& d7 x
- code = forcal.RealCom(s, nModule, ref hFor, ref len, ref Para, ref e1, ref e2);
- . Z |5 @+ a6 u- ]4 S
- Console.Write(code);
- ' ?0 D4 q+ l6 g6 q
- - m A* O2 f\\" J* \* C3 g( C
- if (code == 0)
- . r0 } P) Q' |3 v3 _% o
- {7 Y2 l8 a\\" f- {
- double dd = forcal.RealCal(hFor, MyArgs);! B, M( n# W( j5 c. G, o, ?' O
- Console.Write("\r\n结果=");) ^- T: L. d' i' L3 S
- Console.Write(dd);/ O: T! U% Y# I [! b+ y. S5 K
- Console.Write("\r\n");
- ! p8 ]; h- S. u# `- @/ W4 k
- }
- 4 F/ z$ l8 t8 d2 | F+ p% {! k\\" T
- . z4 {; F: M3 _8 H7 a' |
- forcal.FreeForcal();
- - B6 r0 D! h a4 }/ Y
- }
- ; B\\" Z/ u0 E' _' y0 [6 p
- }
- , r9 r0 \! _0 \0 w\\" x' @
- }
|
|