VC写的DLL,C#调用 本帖最后由 hjm1980_2004 于 2011-04-11 15:49:08 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 楼主可以到本站的下载中用关键词搜搜,有不少关于这方面的资料的下面小例子楼主可以看看c#调用方法using System;using System.Collections.Generic;using System.Text;using System.Runtime.InteropServices;namespace ConsoleApplication1{ class Program { [DllImport("CalcuExpDll.dll")] public static extern double CalculateExp(string exp, int length); static void Main(string[] args) { string s = "15+24*(3-1)"; double a = CalculateExp(s, s.Length); Console.WriteLine(a); Console.Read(); } }}源代码/////////////////////////////////////////////////////#include <stdio.h>#include <stdlib.h>#include <malloc.h>const int MAXL = 25;const int MAXZH = 10;struct duzhN{ double* elem; int pos;};struct duzhS{ char* elem; int pos;};double popN(duzhN* dzh);void pushN(duzhN* dzh, double e);char popS(duzhS* dzh);void pushS(duzhS* dzh, char e);double Calculate(char* exp, int length);double Calcu(char* exp, int length, int* Pos, int isKuo);int isNum(char c);int BankSign(char c);double Comp(char s, double a, double b);double zhOpe(duzhN *N, duzhS *S);//////////////////////////////////////#include "Calcu.h"double popN(duzhN* dzh){ return dzh->elem[--dzh->pos];}void pushN(duzhN* dzh, double e){ dzh->elem[dzh->pos++] = e;}char popS(duzhS* dzh){ return dzh->elem[--dzh->pos];}void pushS(duzhS* dzh, char e){ dzh->elem[dzh->pos++] = e;}int isNum(char c){ return (c >= '0' && c <= '9') || c == '.';}int BankSign(char c){ switch(c) { case '+': case '-': return 0; case '*': case '/': return 1; } return -1;}double Comp(char s, double a, double b){ switch(s) { case '+': return a + b; case '-': return a - b; case '*': return a * b; case '/': return a / b; default: printf("Find a error operator!"); system("pause"); exit(0); }}double zhOpe(duzhN *N, duzhS *S){ double b = popN(N); double a = popN(N); return Comp(popS(S), a, b);}double Calculate(char* exp, int length){ int Pos = 0, isKuo = 0; return Calcu(exp, length, &Pos, isKuo);}double Calcu(char* exp, int length, int* Pos, int isKuo){ char tempN[MAXL]; int tempPos = 0; tempN[0] = '\0'; duzhN Num; duzhS Sign; Num.elem = (double*)malloc(MAXZH * sizeof(double)); Num.pos = 0; Sign.elem = (char*)malloc(MAXZH * sizeof(char)); Sign.pos = 0; if(exp[*Pos] == '-') { tempN[tempPos++] = exp[*Pos]; tempN[tempPos] = '\0'; *Pos = *Pos + 1; } while(1) { if(isNum(exp[*Pos])) { tempN[tempPos++] = exp[*Pos]; tempN[tempPos] = '\0'; } else if(exp[*Pos] == '(') { *Pos = *Pos + 1; pushN(&Num, Calcu(exp, length, Pos, 1)); } else if(exp[*Pos] != ')') { if(exp[*Pos - 1] != ')') { pushN(&Num, atof(tempN)); tempN[0] = '\0'; tempPos = 0; } if(Sign.pos == 0) { pushS(&Sign, exp[*Pos]); } else { if(BankSign(exp[*Pos]) <= BankSign(Sign.elem[Sign.pos - 1])) { pushN(&Num,zhOpe(&Num, &Sign)); pushS(&Sign, exp[*Pos]); } else { pushS(&Sign, exp[*Pos]); } } } if(*Pos == length - 1) { if(exp[*Pos] != ')') { pushN(&Num, atof(tempN)); tempN[0] = '\0'; tempPos = 0; } while(Num.pos > 1) { pushN(&Num,zhOpe(&Num, &Sign)); } return popN(&Num); } else if(isKuo && exp[*Pos + 1] == ')') { if(exp[*Pos] != ')') { pushN(&Num, atof(tempN)); tempN[0] = '\0'; tempPos = 0; } while(Num.pos > 1) { pushN(&Num,zhOpe(&Num, &Sign)); } *Pos = *Pos + 1; return popN(&Num); } else { *Pos = *Pos + 1; } } return 0;} 类似这样,你的说明不全 [DllImport("c:\\1.dll")] private static extern void SessionEventCallBack(MT_NETSDK_HDVSSESSION session,IntPtr callbackParam,ESSIONEVENT e,ref eventParam);callbackParam,你可以声明一个同样的方法作为回调,eventParam不知道类型,所以你需要加上 SVG - Netron 再问个简单的问题 请问:vf 制作安装程序时如何创建桌面快捷方式 PictureBox控件为什么在工具箱里看不到? c#里用什么类型来对应LPCTSTR呢? 禁止关闭 系统 看看该如何写 关于电子商务(一直不明白) 如何实现在OA系统中的任务传递 C#接收消息的问题!! C# ------------------> vb.net C#,没点保存按钮时,提示先保存。 c# crc16
下面小例子楼主可以看看
c#调用方法
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;namespace ConsoleApplication1
{
class Program
{
[DllImport("CalcuExpDll.dll")]
public static extern double CalculateExp(string exp, int length); static void Main(string[] args)
{
string s = "15+24*(3-1)";
double a = CalculateExp(s, s.Length);
Console.WriteLine(a);
Console.Read();
}
}
}
源代码
/////////////////////////////////////////////////////
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
const int MAXL = 25;
const int MAXZH = 10;
struct duzhN
{
double* elem;
int pos;
};
struct duzhS
{
char* elem;
int pos;
};
double popN(duzhN* dzh);
void pushN(duzhN* dzh, double e);
char popS(duzhS* dzh);
void pushS(duzhS* dzh, char e);
double Calculate(char* exp, int length);
double Calcu(char* exp, int length, int* Pos, int isKuo);
int isNum(char c);
int BankSign(char c);
double Comp(char s, double a, double b);
double zhOpe(duzhN *N, duzhS *S);
//////////////////////////////////////
#include "Calcu.h"
double popN(duzhN* dzh)
{
return dzh->elem[--dzh->pos];
}
void pushN(duzhN* dzh, double e)
{
dzh->elem[dzh->pos++] = e;
}
char popS(duzhS* dzh)
{
return dzh->elem[--dzh->pos];
}
void pushS(duzhS* dzh, char e)
{
dzh->elem[dzh->pos++] = e;
}
int isNum(char c)
{
return (c >= '0' && c <= '9') || c == '.';
}
int BankSign(char c)
{
switch(c)
{
case '+':
case '-':
return 0;
case '*':
case '/':
return 1;
}
return -1;
}
double Comp(char s, double a, double b)
{
switch(s)
{
case '+':
return a + b;
case '-':
return a - b;
case '*':
return a * b;
case '/':
return a / b;
default:
printf("Find a error operator!");
system("pause");
exit(0);
}
}
double zhOpe(duzhN *N, duzhS *S)
{
double b = popN(N);
double a = popN(N);
return Comp(popS(S), a, b);
}
double Calculate(char* exp, int length)
{
int Pos = 0, isKuo = 0;
return Calcu(exp, length, &Pos, isKuo);
}
double Calcu(char* exp, int length, int* Pos, int isKuo)
{
char tempN[MAXL];
int tempPos = 0;
tempN[0] = '\0';
duzhN Num;
duzhS Sign; Num.elem = (double*)malloc(MAXZH * sizeof(double));
Num.pos = 0; Sign.elem = (char*)malloc(MAXZH * sizeof(char));
Sign.pos = 0; if(exp[*Pos] == '-')
{
tempN[tempPos++] = exp[*Pos];
tempN[tempPos] = '\0';
*Pos = *Pos + 1;
} while(1)
{
if(isNum(exp[*Pos]))
{
tempN[tempPos++] = exp[*Pos];
tempN[tempPos] = '\0';
}
else if(exp[*Pos] == '(')
{
*Pos = *Pos + 1;
pushN(&Num, Calcu(exp, length, Pos, 1));
}
else if(exp[*Pos] != ')')
{
if(exp[*Pos - 1] != ')')
{
pushN(&Num, atof(tempN));
tempN[0] = '\0';
tempPos = 0;
} if(Sign.pos == 0)
{
pushS(&Sign, exp[*Pos]);
}
else
{
if(BankSign(exp[*Pos]) <= BankSign(Sign.elem[Sign.pos - 1]))
{
pushN(&Num,zhOpe(&Num, &Sign));
pushS(&Sign, exp[*Pos]);
}
else
{
pushS(&Sign, exp[*Pos]);
}
}
} if(*Pos == length - 1)
{
if(exp[*Pos] != ')')
{
pushN(&Num, atof(tempN));
tempN[0] = '\0';
tempPos = 0;
} while(Num.pos > 1)
{
pushN(&Num,zhOpe(&Num, &Sign));
}
return popN(&Num);
}
else if(isKuo && exp[*Pos + 1] == ')')
{
if(exp[*Pos] != ')')
{
pushN(&Num, atof(tempN));
tempN[0] = '\0';
tempPos = 0;
} while(Num.pos > 1)
{
pushN(&Num,zhOpe(&Num, &Sign));
}
*Pos = *Pos + 1;
return popN(&Num);
}
else
{
*Pos = *Pos + 1;
}
} return 0;
}
private static extern void SessionEventCallBack(MT_NETSDK_HDVSSESSION session,IntPtr callbackParam,ESSIONEVENT e,ref eventParam);callbackParam,你可以声明一个同样的方法作为回调,eventParam不知道类型,所以你需要加上