Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to compile c++ code at run time in c#
    primarykey
    data
    text
    <p>I want to compile some c++ code to a dll at runtime using c#. Is that possible? And how do I proceed? Is it possible to simply translate the c++ code to c#? I am new to c++ and do not know if it is even possible. The dll is used in an other application, thus the input and output for the dll is fixed and can not be changed.</p> <p>I have been looking at cppcodeprovider, however, I does not seem to work.</p> <p>Would it be possible to build a c++ wrapper for c#?</p> <p>Here is the c++ code that I want to compile at runtime:</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;string.h&gt; #define NINT(a) ((a) &gt;= 0.0 ? (int)((a)+0.5) : (int)((a)-0.5)) extern "C" //avoid mangled names { void __declspec(dllexport) __cdecl cDISCON(float *avrSwap, int *aviFail, char *accInfile, char *avcOutname, char *avcMsg); } //Main DLL routine void __declspec(dllexport) __cdecl cDISCON(float *avrSwap, int *aviFail, char *accInfile, char *avcOutname, char *avcMsg) { char Message[257], InFile[257], OutName[1025]; float rTime, rMeasuredSpeed, rMeasuredPitch; int iStatus, iFirstLog; static float rPitchDemand; //Take local copies of strings memcpy(InFile,accInfile, NINT(avrSwap[49])); InFile[NINT(avrSwap[49])+1] = '\0'; memcpy(OutName,avcOutname, NINT(avrSwap[50])); OutName[NINT(avrSwap[50])+1] = '\0'; //Set message to blank memset(Message,' ',257); //Set constants SetParams(avrSwap); //Load variables from Bladed (See Appendix A) iStatus = NINT (avrSwap[0]); rTime = avrSwap[1]; rMeasuredPitch = avrSwap[3]; rMeasuredSpeed = avrSwap[19]; //Read any External Controller Parameters specified in the User Interface if (iStatus == 0) { *aviFail = ReadData(InFile, Message); //User to supply this routine rPitchDemand = rMeasuredPitch; //Initialise } //Set return values using previous demand if a sample delay is required avrSwap[44] = rPitchDemand; //Main calculation //User to supply calcs routine if (iStatus &gt;= 0 &amp;&amp; *aviFail &gt;= 0) *aviFail = calcs(iStatus, rMeasuredSpeed, rMeasuredPitch, &amp;rPitchDemand, OutName, Message); //Logging output - example avrSwap[64] = 2; //No of outputs iFirstLog = NINT(avrSwap[62])-1; //Address of first output strcpy(OutName, "Speed:A/T;Pitch:A"); //Names and units avrSwap[iFirstLog] = rMeasuredSpeed; //First Value avrSwap[iFirstLog+1] = rMeasuredPitch; //Second value //Return strings memcpy(avcOutname,OutName, NINT(avrSwap[63])); memcpy(avcMsg,Message,MIN(256,NINT(avrSwap[48]))); return; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload