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

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

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

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

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

textual
Листинг программы
  1. #pragma comment(lib, "PiritLib.lib")
  2. #define IMPORTDLL extern "C" __declspec(dllimport)
  3. #define PIRITLIB_CALL __stdcall
  4.  
  5. #define CORRECTION_INDEPENDENT 0x00
  6. #define CORRECTION_PRESCRIPTION 0x01
  7. #define CORRECTION_INCOMING 0x00
  8. #define CORRECTION_OUTGOING 0x02
  9. #define CORRECTION_TAX_1 0x00
  10. #define CORRECTION_TAX_2 0x04
  11. #define CORRECTION_TAX_4 0x08
  12. #define CORRECTION_TAX_8 0x0C
  13. #define CORRECTION_TAX_16 0x10
  14. #define CORRECTION_TAX_32 0x14
  15.  
  16. #define DEVICE_MODE_DATA_ENCRYPTION 0x01
  17. #define DEVICE_MODE_OFFLINE 0x02
  18. #define DEVICE_MODE_AUTOMATIC 0x04
  19. #define DEVICE_MODE_SERVICE_SIGN 0x08
  20. #define DEVICE_MODE_BSO_SING 0x10
  21. #define DEVICE_MODE_PAYING_AGENT 0x20
  22. #define DEVICE_MODE_BANK_AGENT 0x40
  23. #define DEVICE_MODE_CALC_ONLINE_SIGN 0x80
  24.  
  25. enum CoefficientTypes
  26. {
  27.     NONE = 0, DISCOUNT_PERCENT, DISCOUNT_SUM, MARGIN_PERCENT, MARGIN_SUM
  28. };
  29.  
  30. typedef struct tagDateTime {
  31.     int year;
  32.     unsigned char month;
  33.     unsigned char day;
  34.     unsigned char hour;
  35.     unsigned char min;
  36.     unsigned char sec;
  37. }DateTime;
  38.  
  39. typedef struct tagMData {
  40.     int errCode;
  41.     char data[256];
  42.     int dataLength;
  43. }MData;
  44.  
  45. typedef struct tagMPiritDate {
  46.     int year;
  47.     unsigned char month;
  48.     unsigned char day;
  49. }MPiritDate;
  50.  
  51. typedef struct tagMPiritTime {
  52.     unsigned char hour;
  53.     unsigned char minute;
  54.     unsigned char second;
  55. }MPiritTime;
  56.  
  57. IMPORTDLL int PIRITLIB_CALL openPort(char *fileName, long speed);
  58. IMPORTDLL int PIRITLIB_CALL closePort();
  59. IMPORTDLL int PIRITLIB_CALL commandStart();
  60. IMPORTDLL MData PIRITLIB_CALL libGetStatusFlags();
  61. IMPORTDLL int PIRITLIB_CALL getStatusFlags(int *fatalStatus, int *currentFlagsStatus, int *documentStatus);
  62. IMPORTDLL MData PIRITLIB_CALL libGetCountersAndRegisters(unsigned char numRequest);
  63. IMPORTDLL MData PIRITLIB_CALL libGetKKTInfo(unsigned char numRequest);
  64. IMPORTDLL int PIRITLIB_CALL getKKTInfo(unsigned char numRequest, char *data);
  65. IMPORTDLL MData PIRITLIB_CALL libGetReceiptData(unsigned char numRequest);
  66. IMPORTDLL MData PIRITLIB_CALL libGetPrinterStatus();
  67. IMPORTDLL MData PIRITLIB_CALL libGetServiceInfo(unsigned char numRequest);
  68. IMPORTDLL MData PIRITLIB_CALL libGetExErrorInfo(unsigned char numRequest);
  69. IMPORTDLL int PIRITLIB_CALL scrollPaper();
  70. IMPORTDLL int PIRITLIB_CALL libCommandStart(MPiritDate mpDate, MPiritTime mpTime);
  71. IMPORTDLL MData PIRITLIB_CALL libReadSettingsTable(unsigned char number, int index);
  72. IMPORTDLL int PIRITLIB_CALL libWriteSettingsTable(unsigned char number, int index, const char* data);
  73. IMPORTDLL MData PIRITLIB_CALL libGetPiritDateTime();
  74. IMPORTDLL int PIRITLIB_CALL libSetPiritDateTime(MPiritDate mpDate, MPiritTime mpTime);
  75. IMPORTDLL int PIRITLIB_CALL libLoadLogo(int size, unsigned char* data);
  76. IMPORTDLL int PIRITLIB_CALL libDeleteLogo();
  77. IMPORTDLL int PIRITLIB_CALL libLoadReceiptDesign(int size, unsigned char* data);
  78. IMPORTDLL int PIRITLIB_CALL libLoadPicture(int width, int height, int sm, const char* name, int number, unsigned char* data);
  79. IMPORTDLL int PIRITLIB_CALL libPrintXReport(const char* nameCashier);
  80. IMPORTDLL int PIRITLIB_CALL libPrintZReport(const char* nameCashier, int options);
  81. IMPORTDLL int PIRITLIB_CALL libOpenDocument(unsigned char type, unsigned char numDepart, char* nameCashier, long docNumber);
  82. IMPORTDLL unsigned long PIRITLIB_CALL libSetBuyerAddress(const char *buyerAddress);
  83. IMPORTDLL unsigned long PIRITLIB_CALL libGetBuyerAddress(char *buyerAddress, unsigned long baLength);
  84. IMPORTDLL void PIRITLIB_CALL libCleanBuyerAddress();
  85. IMPORTDLL MData PIRITLIB_CALL libCloseDocument(unsigned char cutPaper);
  86. IMPORTDLL int PIRITLIB_CALL libCancelDocument();
  87. IMPORTDLL int PIRITLIB_CALL libPostponeDocument(const char* info);
  88. IMPORTDLL int PIRITLIB_CALL libCutDocument();
  89. IMPORTDLL int PIRITLIB_CALL libPrintString(char* textStr, unsigned char attribute);
  90. IMPORTDLL int PIRITLIB_CALL libPrintBarCode(unsigned char posText, unsigned char widthBarCode, unsigned char heightBarCode, unsigned char typeBarCode, const char* barCode);
  91. 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);
  92. IMPORTDLL int PIRITLIB_CALL libDelPosition(const char* goodsName, const char* barcode, double quantity, double price, unsigned char taxNumber, int numGoodsPos, unsigned char numDepart);
  93. IMPORTDLL int PIRITLIB_CALL libSubTotal();
  94. IMPORTDLL int PIRITLIB_CALL libAddDiscount(unsigned char typeDiscount, const char* nameDiscount, long sum);
  95. IMPORTDLL int PIRITLIB_CALL libAddMargin(unsigned char typeMargin, const char* nameMargin, long sum);
  96. IMPORTDLL int PIRITLIB_CALL libAddPayment(unsigned char typePayment, long long sum, const char* infoStr);
  97. IMPORTDLL int PIRITLIB_CALL libCashInOut(const char* infoStr, long long sum);
  98. IMPORTDLL int PIRITLIB_CALL libPrintRequsit(unsigned char codeReq, unsigned char attributeText, const char* str1, const char* str2, const char* str3, const char* str4);
  99. IMPORTDLL int PIRITLIB_CALL libRegisterSumToDepart(unsigned char typeOperation, unsigned char numberDepart, long sum);
  100. IMPORTDLL int PIRITLIB_CALL libRegisterTaxSum(unsigned char numberTax, long sum);
  101. IMPORTDLL int PIRITLIB_CALL libCompareSum(long sum);
  102. IMPORTDLL int PIRITLIB_CALL libOpenCopyReceipt(unsigned char type, unsigned char numDepart, const char* nameCashier, int numCheck, int numCash, MPiritDate mpDate, MPiritTime mpTime);
  103. IMPORTDLL int PIRITLIB_CALL libSetToZeroCashInCashDrawer();
  104. IMPORTDLL int PIRITLIB_CALL libPrintPictureInDocument(int width, int height, int sm, unsigned char* data);
  105. IMPORTDLL int PIRITLIB_CALL libPrintPreloadedPicture(int sm, int number);
  106. IMPORTDLL int PIRITLIB_CALL libTechnologicalReset(const DateTime *dateTime);
  107. IMPORTDLL int PIRITLIB_CALL libFiscalization(const char *oldPassword, const char *regNumber, const char *INN, const char *newPassword);
  108. IMPORTDLL int PIRITLIB_CALL libPrintFiscalReportByShifts(unsigned char typeReport, int startShiftNumber, int endShiftNumber, const char *password);
  109. IMPORTDLL int PIRITLIB_CALL libPrintFiscalReportByDate(unsigned char typeReport, MPiritDate startDate, MPiritDate endDate, const char *password);
  110. IMPORTDLL int PIRITLIB_CALL libActivizationECT();
  111. IMPORTDLL int PIRITLIB_CALL libCloseArchiveECT();
  112. IMPORTDLL int PIRITLIB_CALL libCloseFN(const char *cashierName);
  113. IMPORTDLL int PIRITLIB_CALL libPrintControlTapeFromECT(int shiftNumber);
  114. IMPORTDLL int PIRITLIB_CALL libPrintDocumentFromECT(int KPKNumber);
  115. IMPORTDLL int PIRITLIB_CALL libPrintReportFromECTByShifts(unsigned char typeReport, int startShiftNumber, int endShiftNumber);
  116. IMPORTDLL int PIRITLIB_CALL libPrintReportFromECTByDate(unsigned char typeReport, MPiritDate startDate, MPiritDate endDate);
  117. IMPORTDLL int PIRITLIB_CALL libPrintReportActivizationECT();
  118. IMPORTDLL int PIRITLIB_CALL libPrintReportFromECTByShift(int shiftNumber);
  119. IMPORTDLL MData PIRITLIB_CALL libGetInfoFromECT(unsigned char number, long dataL1, long dataL2);
  120. IMPORTDLL int PIRITLIB_CALL libOpenCashDrawer(int pulseDuration);
  121. IMPORTDLL MData PIRITLIB_CALL libGetCashDrawerStatus();
  122. IMPORTDLL int PIRITLIB_CALL getCashDrawerStatus(int *drawerStatus);
  123. IMPORTDLL int PIRITLIB_CALL libBeep(int duration);
  124. IMPORTDLL int PIRITLIB_CALL libAuthorization(MPiritDate mpDate, MPiritTime mpTime, const char *numKKT);
  125. IMPORTDLL MData PIRITLIB_CALL libReadMemoryBlock(unsigned char type, long startAdress, long numBytes);
  126. IMPORTDLL int PIRITLIB_CALL libSetSpeed(unsigned char numSpeed);
  127. IMPORTDLL int PIRITLIB_CALL libPrintServiceData();
  128. IMPORTDLL int PIRITLIB_CALL command0x9A();
  129. IMPORTDLL int PIRITLIB_CALL command0x9B();
  130. IMPORTDLL int PIRITLIB_CALL libEmergencyCloseShift();
  131. IMPORTDLL int PIRITLIB_CALL libPrintCopyLastZReport();
  132. IMPORTDLL int PIRITLIB_CALL libEnableServiceChannelToECT();
  133. IMPORTDLL int PIRITLIB_CALL libPrintCopyReportFiscalization();
  134. IMPORTDLL int PIRITLIB_CALL getCurMPTime(MPiritDate *mpDate, MPiritTime *mpTime);
  135. IMPORTDLL int PIRITLIB_CALL saveLogoToFile(wchar_t *fileName);
  136. IMPORTDLL void PIRITLIB_CALL setDebugLevel(int level);
  137. IMPORTDLL long long PIRITLIB_CALL getDriverVersion();
  138. IMPORTDLL int PIRITLIB_CALL libPrintDocsFromECTSDByNumberDoc(int startNumber, int endNumber);
  139. IMPORTDLL int PIRITLIB_CALL libPrintDocsFromECTSDByNumberShift(int startNumber, int endNumber);
  140. IMPORTDLL int PIRITLIB_CALL libPrintDocsFromECTSDByDate(MPiritDate mpDateStart, MPiritDate mpDateEnd);
  141. IMPORTDLL int PIRITLIB_CALL libGetInfoFromECT_NumberDoc(int *numDoc);
  142. IMPORTDLL int PIRITLIB_CALL libBLRPrintControlTapeFromECT();
  143. IMPORTDLL int PIRITLIB_CALL getCountersAndRegisters(int requestNumber, int *data);
  144. IMPORTDLL void PIRITLIB_CALL setAmountDecimalPlaces(int decimalPlaces);
  145. IMPORTDLL void PIRITLIB_CALL setQuantityDecimalPlaces(int decimalPlaces);
  146. IMPORTDLL void PIRITLIB_CALL setPercentageDecimalPlaces(int decimalPlaces);
  147. IMPORTDLL int PIRITLIB_CALL getAmountDecimalPlaces();
  148. IMPORTDLL int PIRITLIB_CALL getQuantityDecimalPlaces();
  149. IMPORTDLL int PIRITLIB_CALL getPercentageDecimalPlaces();
  150. IMPORTDLL int PIRITLIB_CALL libGetCountersAndRegisters_12(int data[], int maxElement, char *str);
  151. IMPORTDLL int PIRITLIB_CALL getPrinterStatus(int* result);
  152. IMPORTDLL int PIRITLIB_CALL getPiritDateTime(int* cDate, int* cTime);
  153. IMPORTDLL int PIRITLIB_CALL libOpenShift(const char* nameCashier);
  154. IMPORTDLL int PIRITLIB_CALL libDoCheckCorrection(char* nameCashier, double cash, double cashless, unsigned char correctionFlags);
  155. 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);
  156. IMPORTDLL int PIRITLIB_CALL libCurrentStatusReport(char* nameCashier);
  157. IMPORTDLL int PIRITLIB_CALL libAddPaymentD(unsigned char typePayment, double sum, const char* infoStr);
  158. IMPORTDLL int PIRITLIB_CALL libRegistration(unsigned char type, const char *regNumber, const char *INN, int systemTax, int rej, const char *cashierName);
  159. IMPORTDLL int PIRITLIB_CALL libGetInfoFromECT_NumberFP(char *data);
  160. IMPORTDLL int PIRITLIB_CALL libGetInfoFromECT_FP(int numDoc, char *data);
  161. IMPORTDLL unsigned long PIRITLIB_CALL libFormatMessage(int errorCode, char *msgBuffer, unsigned long cbBuffer);

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


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

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

8   голосов , оценка 3.75 из 5

Нужна аналогичная работа?

Оформи быстрый заказ и узнай стоимость

Бесплатно
Оформите заказ и авторы начнут откликаться уже через 10 минут
Похожие ответы