易截截图软件、单文件、免安装、纯绿色、仅160KB

c编写dll供c#调用

1.新建dll工程,在函数前面增加 extern "C" __declspec(dllexport) double __stdcall
double 为函数返回值类型
// log.cpp : Defines the exported functions for the DLL application.
//
#include "stdafx.h"
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <time.h>
#define PI 3.14159
double AverageRandom(double min,double max)//产生(min,max)之间均匀分布的随机数
{
int MINnteger = (int)(min*10000);
int MAXnteger = (int)(max*10000);
int aa=rand();
int bb=rand();
int randInteger = aa*bb;
int diffInteger = MAXnteger - MINnteger;
int resultInteger = randInteger % diffInteger + MINnteger;
return resultInteger/10000.0;
}
double LogNormal(double x,double miu,double sigma) //对数正态分布概率密度函数
{
return 1.0/(x*sqrt(2*PI)*sigma) * exp(-1*(log(x)-miu)*(log(x)-miu)/(2*sigma*sigma));
}
extern "C" __declspec(dllexport) double __stdcall Random_LogNormal(double miu,double sigma,double min,double max)//产生对数正态分布随机数
{

double x;
double dScope;
double y;
do
{
x = AverageRandom(min,max);
y = LogNormal(x, miu, sigma);
dScope = AverageRandom(0, LogNormal(miu,miu,sigma));
}while( dScope > y);
return x;
}
2.C#中代码
  //通过DllImport引用log.dll类。Random_LogNormal来自于log.dll类
    [DllImport("log.dll", EntryPoint = "Random_LogNormal")]
    public static extern double Random_LogNormal(double miu, double sigma, double min, double max);
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;
class Program
{
///****************************************************
/// 产生N=100个在(0,50)区间内满足对数正态分布的随机数
///*****************************************************/
const int N = 100;
const int MAX = 30;
const double MIN = 0.5;


相关文档:

C#与Flash交互

C#与Flash交互 (转自小磊在线)
C#与Flash交互
前段日子公司要求做一个C#与Flash交互的东西,用来C#与短信猫通讯将数据传到Flash上显示与操作的应用。
第一步C#添加组件
打开VS2005-工具-选择工具箱项-COM组件-选择Shockwave Flash Object-确定
添加好组件往场景上拖放,如果提示注册需求注册
c# 注册控件-在运行输 ......

extern "C" 阅读笔记 zz

发信人: RoachCock (反动学术权威), 信区: CPlusPlus
标  题: extern "C" 阅读笔记
发信站: 水木社区 (Fri Mar  7 00:22:47 2008), 站内
本以为很简单,仔细阅读了一下 C++ 标准,发现内容还不少。总结了一下。
要点:
函数类型,函数名,变量名具有语言链接性,language linkage。
语言链接性可能会影响到 ......

keil C 从零学起 教训1

#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar num;
void main()
{
 TMOD=0x01;
 TH0=(65536-45872)/256;
 TL0=(65536-45872)%256;
 EA=1;
 ET0=1;
 TR0=1;
 P1=0xFF;
 while(1);
}
void T0_time() interrupt 1
{
  ......

我的C实践(7):位计数

  位计数就是对一个数中具有某些特征的位进行计数。看下面实现:
/* bitscount.c:位计数 */
/* 计算x中1位的数目:方案1,采用分治策略 */
inline int pop(unsigned x){
/* 对每个2位字段,先析出其右端的1位,再析出其左端的1位,然后让这两个位相加 */
x=(x & 0x55555555)+((x>>1) & 0x555555 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号