Hi everybody,Here is my question. I have a native project with many headers and class that i try to wrap using c++/cli in order to have a dll that i could reference in my c# project.In some moment i only have headers file (without the corresponding class) that contains only mathematical functions and i use them by including them in my project. My native project work very well.When i have the header and the corresponding class i am able to wrap this. But when i only have the header with only many function i don't know how to wrap these.What is the way for wrap these headers file ?P.S : here is an example of headers that i try to wrap in C++/CLI#ifndef ASSIM_H#define ASSIM_H#include "et.h"// Changes the given model parameter based on current temperature.// k25 (model parameter at 25 deg. C), q10 (Q10 value),// lftemp (leaf temperature, deg. C)double Q10(double k25, double q10, double lftemp){ return (k25 * pow(q10, (lftemp - 25.0) / 10.0));}// Rubisco capacity rate (umol m-2 s-1)// lftemp (leaf temperature, deg. C)double Vcmax(double lftemp){ double const VCMAX = 200.0; // max rate double dExp = 1.0 + exp(0.128 * (lftemp - 40.0)); return (Q10(VCMAX, 2.4, lftemp) / dExp);}// CO2 compensation point (umol mol-1)// lftemp (leaf temperature, deg. C)double CO2CompensationPt(double lftemp){ double const TAU = 2600.0; // specificity factor double const OA = 210000.0; // O2 concentration double dTau = Q10(TAU, 0.57, lftemp); return (OA * 0.5 / dTau);}What I have tried:I try to create a ref class to encapsulate these functions/headers but i need use a pointer to the native class but the point is that this is not a class but only a list of functions that perform calculations. 解决方案 You cant avoid the work to write all declarations in C#. Take a look at my article Calling all Stations.The point is to declare the C functions as undecorated.Hi Karstenk,Thanks for your reply. My idea is build a C++/CLI wrapper. I try something some hours ago that it seems work without having to rewrite all declarations in c#.Here is the "possible" solution i wrote (i don't know if is correct).So what i did is the following :For my native header (assim.h) that is in my first message i defined a c++/cli class with :1) assimWrapper.h// PaSimWrapper.h#pragma once#include "Stdafx.h"namespace Wrapper{public ref class assimWrapper{public:double Q10Wrapped(double k25, double q10, double leafTemp);double CO2CompensationPtWrapped(double leafTemp);double VcmaxWrapped(double leafTemp);double LightLimitedWrapped(double par, double leafTemp, double ci);double RubiscoLimitedWrapped(double leafTemp, double ci);double SinkLimitedWrapped(double leafTemp);double LeafAssimWrapped(double par, double leafTemp);double HourCanopyAssimWrapped(double th, double leafTemp);double DayCanopyAssimWrapped();};}2) assimWrapper.cpp#include "Stdafx.h"//#include "etWrapper.h"#include "assim.h"#include "assimWrapper.h"namespace Wrapper{//////double assimWrapper::Q10Wrapped(double k25, double q10, double leafTemp){return Q10(k25, q10, leafTemp);}//////double assimWrapper::CO2CompensationPtWrapped(double leafTemp){return CO2CompensationPt(leafTemp);}//////double assimWrapper::VcmaxWrapped(double leafTemp){return Vcmax(leafTemp);}//////double assimWrapper::LightLimitedWrapped(double par, double leafTemp, double ci){return LightLimited(par, leafTemp, ci);}//////double assimWrapper::RubiscoLimitedWrapped(double leafTemp, double ci){return RubiscoLimited(leafTemp, ci);}//////double assimWrapper::SinkLimitedWrapped(double leafTemp){return SinkLimited(leafTemp);}//////double assimWrapper::LeafAssimWrapped(double par, double leafTemp){return LeafAssim(par, leafTemp);}//////double assimWrapper::HourCanopyAssimWrapped(double th, double leafTemp){return HourCanopyAssimWrapped(th, leafTemp);}//////double assimWrapper::DayCanopyAssimWrapped(){return DayCanopyAssim();}};It seems working because i have access to my native functions in my c# project.Do you think or other people that is correct ?SD 这篇关于在C#项目中使用本机头文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-20 09:39
查看更多