Тип const в импортированной dll - C#

Узнай цену своей работы

Формулировка задачи:

Добрый день. Есть DLL от некоего чудака. Документация говорит, что там есть такая функция:
int libAddPosition(const char* goodsName, const char* barcode, long quantity, long price, unsigned char taxNumber, int numGoodsPos, unsigned char numDepart);
Пытаюсь ее импортировать в C#:
    [DllImport("PiritLib.dll", CallingConvention = CallingConvention.Winapi)]
    public static extern int libAddPosition(
            string goodsName,
            string barcode,
            long quantity,
            long price,
            sbyte taxNumber,
            int numGoodsPos,
            int numDepart
    );
Аналогичные функции работают, а эта нет. Я виду отличие только в неком "const" перед первыми двумя параметрами. Как мне передать из C# в dll эти значения по-правильному? Но вообще, есть куча версий документаций, файлов, примеров для этой чудной dll. Везде все не совпадает, но для начала нужно правильно передать const.

Решение задачи: «Тип const в импортированной dll»

textual
Листинг программы
#pragma comment(lib, "PiritLib.lib")
#define IMPORTDLL extern "C" __declspec(dllimport)
#define PIRITLIB_CALL __stdcall
 
#define CORRECTION_INDEPENDENT 0x00
#define CORRECTION_PRESCRIPTION 0x01
#define CORRECTION_INCOMING 0x00
#define CORRECTION_OUTGOING 0x02
#define CORRECTION_TAX_1 0x00
#define CORRECTION_TAX_2 0x04
#define CORRECTION_TAX_4 0x08
#define CORRECTION_TAX_8 0x0C
#define CORRECTION_TAX_16 0x10
#define CORRECTION_TAX_32 0x14
 
#define DEVICE_MODE_DATA_ENCRYPTION 0x01
#define DEVICE_MODE_OFFLINE 0x02
#define DEVICE_MODE_AUTOMATIC 0x04
#define DEVICE_MODE_SERVICE_SIGN 0x08
#define DEVICE_MODE_BSO_SING 0x10
#define DEVICE_MODE_PAYING_AGENT 0x20
#define DEVICE_MODE_BANK_AGENT 0x40
#define DEVICE_MODE_CALC_ONLINE_SIGN 0x80
 
enum CoefficientTypes
{
    NONE = 0, DISCOUNT_PERCENT, DISCOUNT_SUM, MARGIN_PERCENT, MARGIN_SUM
};
 
typedef struct tagDateTime {
    int year;
    unsigned char month;
    unsigned char day;
    unsigned char hour;
    unsigned char min;
    unsigned char sec;
}DateTime;
 
typedef struct tagMData {
    int errCode;
    char data[256];
    int dataLength;
}MData;
 
typedef struct tagMPiritDate {
    int year;
    unsigned char month;
    unsigned char day;
}MPiritDate;
 
typedef struct tagMPiritTime {
    unsigned char hour;
    unsigned char minute;
    unsigned char second;
}MPiritTime;
 
IMPORTDLL int PIRITLIB_CALL openPort(char *fileName, long speed);
IMPORTDLL int PIRITLIB_CALL closePort();
IMPORTDLL int PIRITLIB_CALL commandStart();
IMPORTDLL MData PIRITLIB_CALL libGetStatusFlags();
IMPORTDLL int PIRITLIB_CALL getStatusFlags(int *fatalStatus, int *currentFlagsStatus, int *documentStatus);
IMPORTDLL MData PIRITLIB_CALL libGetCountersAndRegisters(unsigned char numRequest);
IMPORTDLL MData PIRITLIB_CALL libGetKKTInfo(unsigned char numRequest);
IMPORTDLL int PIRITLIB_CALL getKKTInfo(unsigned char numRequest, char *data);
IMPORTDLL MData PIRITLIB_CALL libGetReceiptData(unsigned char numRequest);
IMPORTDLL MData PIRITLIB_CALL libGetPrinterStatus();
IMPORTDLL MData PIRITLIB_CALL libGetServiceInfo(unsigned char numRequest);
IMPORTDLL MData PIRITLIB_CALL libGetExErrorInfo(unsigned char numRequest);
IMPORTDLL int PIRITLIB_CALL scrollPaper();
IMPORTDLL int PIRITLIB_CALL libCommandStart(MPiritDate mpDate, MPiritTime mpTime);
IMPORTDLL MData PIRITLIB_CALL libReadSettingsTable(unsigned char number, int index);
IMPORTDLL int PIRITLIB_CALL libWriteSettingsTable(unsigned char number, int index, const char* data);
IMPORTDLL MData PIRITLIB_CALL libGetPiritDateTime();
IMPORTDLL int PIRITLIB_CALL libSetPiritDateTime(MPiritDate mpDate, MPiritTime mpTime);
IMPORTDLL int PIRITLIB_CALL libLoadLogo(int size, unsigned char* data);
IMPORTDLL int PIRITLIB_CALL libDeleteLogo();
IMPORTDLL int PIRITLIB_CALL libLoadReceiptDesign(int size, unsigned char* data);
IMPORTDLL int PIRITLIB_CALL libLoadPicture(int width, int height, int sm, const char* name, int number, unsigned char* data);
IMPORTDLL int PIRITLIB_CALL libPrintXReport(const char* nameCashier);
IMPORTDLL int PIRITLIB_CALL libPrintZReport(const char* nameCashier, int options);
IMPORTDLL int PIRITLIB_CALL libOpenDocument(unsigned char type, unsigned char numDepart, char* nameCashier, long docNumber);
IMPORTDLL unsigned long PIRITLIB_CALL libSetBuyerAddress(const char *buyerAddress);
IMPORTDLL unsigned long PIRITLIB_CALL libGetBuyerAddress(char *buyerAddress, unsigned long baLength);
IMPORTDLL void PIRITLIB_CALL libCleanBuyerAddress();
IMPORTDLL MData PIRITLIB_CALL libCloseDocument(unsigned char cutPaper);
IMPORTDLL int PIRITLIB_CALL libCancelDocument();
IMPORTDLL int PIRITLIB_CALL libPostponeDocument(const char* info);
IMPORTDLL int PIRITLIB_CALL libCutDocument();
IMPORTDLL int PIRITLIB_CALL libPrintString(char* textStr, unsigned char attribute);
IMPORTDLL int PIRITLIB_CALL libPrintBarCode(unsigned char posText, unsigned char widthBarCode, unsigned char heightBarCode, unsigned char typeBarCode, const char* barCode);
IMPORTDLL int PIRITLIB_CALL libAddPosition(const char* goodsName, const char* barcode, double quantity, double price, unsigned char taxNumber, int numGoodsPos, unsigned char numDepart, unsigned char coefType, const char *coefName, double coefValue);
IMPORTDLL int PIRITLIB_CALL libDelPosition(const char* goodsName, const char* barcode, double quantity, double price, unsigned char taxNumber, int numGoodsPos, unsigned char numDepart);
IMPORTDLL int PIRITLIB_CALL libSubTotal();
IMPORTDLL int PIRITLIB_CALL libAddDiscount(unsigned char typeDiscount, const char* nameDiscount, long sum);
IMPORTDLL int PIRITLIB_CALL libAddMargin(unsigned char typeMargin, const char* nameMargin, long sum);
IMPORTDLL int PIRITLIB_CALL libAddPayment(unsigned char typePayment, long long sum, const char* infoStr);
IMPORTDLL int PIRITLIB_CALL libCashInOut(const char* infoStr, long long sum);
IMPORTDLL int PIRITLIB_CALL libPrintRequsit(unsigned char codeReq, unsigned char attributeText, const char* str1, const char* str2, const char* str3, const char* str4);
IMPORTDLL int PIRITLIB_CALL libRegisterSumToDepart(unsigned char typeOperation, unsigned char numberDepart, long sum);
IMPORTDLL int PIRITLIB_CALL libRegisterTaxSum(unsigned char numberTax, long sum);
IMPORTDLL int PIRITLIB_CALL libCompareSum(long sum);
IMPORTDLL int PIRITLIB_CALL libOpenCopyReceipt(unsigned char type, unsigned char numDepart, const char* nameCashier, int numCheck, int numCash, MPiritDate mpDate, MPiritTime mpTime);
IMPORTDLL int PIRITLIB_CALL libSetToZeroCashInCashDrawer();
IMPORTDLL int PIRITLIB_CALL libPrintPictureInDocument(int width, int height, int sm, unsigned char* data);
IMPORTDLL int PIRITLIB_CALL libPrintPreloadedPicture(int sm, int number);
IMPORTDLL int PIRITLIB_CALL libTechnologicalReset(const DateTime *dateTime);
IMPORTDLL int PIRITLIB_CALL libFiscalization(const char *oldPassword, const char *regNumber, const char *INN, const char *newPassword);
IMPORTDLL int PIRITLIB_CALL libPrintFiscalReportByShifts(unsigned char typeReport, int startShiftNumber, int endShiftNumber, const char *password);
IMPORTDLL int PIRITLIB_CALL libPrintFiscalReportByDate(unsigned char typeReport, MPiritDate startDate, MPiritDate endDate, const char *password);
IMPORTDLL int PIRITLIB_CALL libActivizationECT();
IMPORTDLL int PIRITLIB_CALL libCloseArchiveECT();
IMPORTDLL int PIRITLIB_CALL libCloseFN(const char *cashierName);
IMPORTDLL int PIRITLIB_CALL libPrintControlTapeFromECT(int shiftNumber);
IMPORTDLL int PIRITLIB_CALL libPrintDocumentFromECT(int KPKNumber);
IMPORTDLL int PIRITLIB_CALL libPrintReportFromECTByShifts(unsigned char typeReport, int startShiftNumber, int endShiftNumber);
IMPORTDLL int PIRITLIB_CALL libPrintReportFromECTByDate(unsigned char typeReport, MPiritDate startDate, MPiritDate endDate);
IMPORTDLL int PIRITLIB_CALL libPrintReportActivizationECT();
IMPORTDLL int PIRITLIB_CALL libPrintReportFromECTByShift(int shiftNumber);
IMPORTDLL MData PIRITLIB_CALL libGetInfoFromECT(unsigned char number, long dataL1, long dataL2);
IMPORTDLL int PIRITLIB_CALL libOpenCashDrawer(int pulseDuration);
IMPORTDLL MData PIRITLIB_CALL libGetCashDrawerStatus();
IMPORTDLL int PIRITLIB_CALL getCashDrawerStatus(int *drawerStatus);
IMPORTDLL int PIRITLIB_CALL libBeep(int duration);
IMPORTDLL int PIRITLIB_CALL libAuthorization(MPiritDate mpDate, MPiritTime mpTime, const char *numKKT);
IMPORTDLL MData PIRITLIB_CALL libReadMemoryBlock(unsigned char type, long startAdress, long numBytes);
IMPORTDLL int PIRITLIB_CALL libSetSpeed(unsigned char numSpeed);
IMPORTDLL int PIRITLIB_CALL libPrintServiceData();
IMPORTDLL int PIRITLIB_CALL command0x9A();
IMPORTDLL int PIRITLIB_CALL command0x9B();
IMPORTDLL int PIRITLIB_CALL libEmergencyCloseShift();
IMPORTDLL int PIRITLIB_CALL libPrintCopyLastZReport();
IMPORTDLL int PIRITLIB_CALL libEnableServiceChannelToECT();
IMPORTDLL int PIRITLIB_CALL libPrintCopyReportFiscalization();
IMPORTDLL int PIRITLIB_CALL getCurMPTime(MPiritDate *mpDate, MPiritTime *mpTime);
IMPORTDLL int PIRITLIB_CALL saveLogoToFile(wchar_t *fileName);
IMPORTDLL void PIRITLIB_CALL setDebugLevel(int level);
IMPORTDLL long long PIRITLIB_CALL getDriverVersion();
IMPORTDLL int PIRITLIB_CALL libPrintDocsFromECTSDByNumberDoc(int startNumber, int endNumber);
IMPORTDLL int PIRITLIB_CALL libPrintDocsFromECTSDByNumberShift(int startNumber, int endNumber);
IMPORTDLL int PIRITLIB_CALL libPrintDocsFromECTSDByDate(MPiritDate mpDateStart, MPiritDate mpDateEnd);
IMPORTDLL int PIRITLIB_CALL libGetInfoFromECT_NumberDoc(int *numDoc);
IMPORTDLL int PIRITLIB_CALL libBLRPrintControlTapeFromECT();
IMPORTDLL int PIRITLIB_CALL getCountersAndRegisters(int requestNumber, int *data);
IMPORTDLL void PIRITLIB_CALL setAmountDecimalPlaces(int decimalPlaces);
IMPORTDLL void PIRITLIB_CALL setQuantityDecimalPlaces(int decimalPlaces);
IMPORTDLL void PIRITLIB_CALL setPercentageDecimalPlaces(int decimalPlaces);
IMPORTDLL int PIRITLIB_CALL getAmountDecimalPlaces();
IMPORTDLL int PIRITLIB_CALL getQuantityDecimalPlaces();
IMPORTDLL int PIRITLIB_CALL getPercentageDecimalPlaces();
IMPORTDLL int PIRITLIB_CALL libGetCountersAndRegisters_12(int data[], int maxElement, char *str);
IMPORTDLL int PIRITLIB_CALL getPrinterStatus(int* result);
IMPORTDLL int PIRITLIB_CALL getPiritDateTime(int* cDate, int* cTime);
IMPORTDLL int PIRITLIB_CALL libOpenShift(const char* nameCashier);
IMPORTDLL int PIRITLIB_CALL libDoCheckCorrection(char* nameCashier, double cash, double cashless, unsigned char correctionFlags);
IMPORTDLL int PIRITLIB_CALL libDoCheckCorrectionEx(char* nameCashier, double cash, double cashless, double sum1, double sum2, double sum3, unsigned char correctionFlags, MPiritDate docDate, char *docNumber, char *correctionName, double sum_18, double sum_10, double sum_0, double sum_WT, double sum_18_118, double sum_10_110);
IMPORTDLL int PIRITLIB_CALL libCurrentStatusReport(char* nameCashier);
IMPORTDLL int PIRITLIB_CALL libAddPaymentD(unsigned char typePayment, double sum, const char* infoStr);
IMPORTDLL int PIRITLIB_CALL libRegistration(unsigned char type, const char *regNumber, const char *INN, int systemTax, int rej, const char *cashierName);
IMPORTDLL int PIRITLIB_CALL libGetInfoFromECT_NumberFP(char *data);
IMPORTDLL int PIRITLIB_CALL libGetInfoFromECT_FP(int numDoc, char *data);
IMPORTDLL unsigned long PIRITLIB_CALL libFormatMessage(int errorCode, char *msgBuffer, unsigned long cbBuffer);

ИИ поможет Вам:


  • решить любую задачу по программированию
  • объяснить код
  • расставить комментарии в коде
  • и т.д
Попробуйте бесплатно

Оцени полезность:

8   голосов , оценка 3.75 из 5
Похожие ответы