0

c# を使用して、実行時にいくつかの c++ コードを dll にコンパイルしたいと考えています。それは可能ですか?そして、どうすれば進めますか?C++ コードを単純に C# に変換することは可能ですか? 私はC ++が初めてで、それが可能かどうかさえわかりません。dll は他のアプリケーションで使用されるため、dll の入力と出力は固定されており、変更できません。

私はcppcodeproviderを見てきましたが、うまくいかないようです。

c# 用の c++ ラッパーをビルドすることは可能でしょうか?

実行時にコンパイルする C++ コードは次のとおりです。

#include <stdio.h>
#include <string.h>

#define NINT(a) ((a) >= 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 >= 0 && *aviFail >= 0) 
        *aviFail = calcs(iStatus, rMeasuredSpeed, rMeasuredPitch, &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;

}
4

0 に答える 0