0

friends and comrades!

I have program that was created in Borland C++ Builder. This program uses several dll libraries that was created in Borland C++ Builder too. But now we use Microsoft Visual Studio.

I have task to rewrite existing dll. I need to add several new strings with math-formulas. Chief gave me cpp-file, that was written in Borland C++ Builder. I have included needed formulas, but I'm not sure that i made correct preprocessor directives. Must I build only cpp-file? Are there needed any other files?

Original cpp-file

#include <windows.h>
#include <stdio.h>
#include <math.h>
#pragma argsused
void  FAR PASCAL _export userdll(float *x,char *c1,char *c2,char *c3,char *c4,char *c5)
{
x[501]=x[115]*9.81;    // -- Mdv v Nm
x[502]=x[501]*x[122]/7023.5;      //-- Ndv v lc
x[503]=x[502]*0.7355;      // -- Ndv v kW
if(x[502]>1.0&&x[123]>4.0)x[510]=x[123]/x[502];     //  -- Ce v kg/lc*h
else x[510]=0;
if(x[502]>1.0&&x[123]>4.0)x[511]=x[123]/x[503];     //  -- Ce v kg/kW*h
else x[511]=0;
x[520]=x[34]*7.50064;       //  -- Pbar  v  mmHg
return;
}

Rewritten cpp-file

#define STRUCT
#include <windows.h>
#include <stdio.h>
#include <math.h>
#pragma argsused

__declspec(dllexport)
void  FAR PASCAL userdll(float *x, char *c1, char *c2, char *c3, char *c4, char *c5)
{
    x[501] = x[115] * 9.81;    // -- Mdv v Nm
    x[502] = x[501] * x[122] / 7023.5;      //-- Ndv v lc
    x[503] = x[502] * 0.7355;      // -- Ndv v kW
    if (x[502] > 1.0 && x[123] > 4.0)
        x[510] = x[123] / x[502];    //  -- Ce v kg/lc*h
    else x[510] = 0;
    if (x[502] > 1.0 && x[123] > 4.0)
        x[511] = x[123] / x[503];     //  -- Ce v kg/kW*h
    else x[511] = 0;
    x[520] = x[34] * 7.50064;       //  -- Pbar  v  mmHg


    int chooseStr, chooseCol;
    float temp; // temp - ТЕМПЕРАТУРА по датчику
    float DAVLENIE; // ДАВЛЕНИЕ по таблице из ГОСТ Р 52517-2005

    float massiv[61][9] =
    {
        //      --------------------------------------------------------------------------------------
        //      |                      Влажность, %                    |                             |
        //      -------------------------------------------------------|  Температура, град. Цельсия |
        //      | 100  | 90  | 80  | 70  | 60  | 50  | 40  | 30  | 20  |                             |
        //      --------------------------------------------------------------------------------------
        { 0.30, 0.27, 0.24, 0.21, 0.18, 0.15, 0.12, 0.09, 0.06 }, //    -10
        { 0.33, 0.29, 0.26, 0.23, 0.20, 0.16, 0.13, 0.10, 0.07 }, //    -9
        { 0.35, 0.32, 0.28, 0.25, 0.21, 0.18, 0.14, 0.11, 0.07 }, //    -8
        { 0.38, 0.34, 0.30, 0.27, 0.23, 0.19, 0.15, 0.11, 0.08 }, //    -7
        { 0.41, 0.36, 0.32, 0.28, 0.24, 0.20, 0.16, 0.12, 0.08 }, //    -6
        { 0.43, 0.39, 0.35, 0.30, 0.26, 0.22, 0.17, 0.13, 0.09 }, //    -5
        { 0.46, 0.41, 0.37, 0.32, 0.28, 0.23, 0.18, 0.14, 0.09 }, //    -4
        { 0.49, 0.44, 0.39, 0.34, 0.30, 0.25, 0.20, 0.15, 0.10 }, //    -3
        { 0.53, 0.47, 0.42, 0.37, 0.32, 0.26, 0.21, 0.16, 0.10 }, //    -2
        { 0.56, 0.50, 0.45, 0.39, 0.34, 0.28, 0.22, 0.17, 0.11 }, //    -1
        { 0.60, 0.54, 0.48, 0.42, 0.36, 0.30, 0.24, 0.18, 0.12 }, //    0
        { 0.64, 0.58, 0.51, 0.45, 0.39, 0.32, 0.26, 0.19, 0.13 }, //    1
        { 0.69, 0.62, 0.55, 0.48, 0.41, 0.34, 0.28, 0.21, 0.14 }, //    2
        { 0.74, 0.66, 0.59, 0.52, 0.44, 0.37, 0.30, 0.22, 0.15 }, //    3
        { 0.79, 0.71, 0.63, 0.55, 0.47, 0.40, 0.32, 0.24, 0.16 }, //    4
        { 0.85, 0.76, 0.68, 0.59, 0.51, 0.42, 0.34, 0.25, 0.17 }, //    5
        { 0.91, 0.82, 0.73, 0.64, 0.55, 0.46, 0.36, 0.27, 0.18 }, //    6
        { 0.98, 0.88, 0.78, 0.68, 0.59, 0.49, 0.39, 0.29, 0.20 }, //    7
        { 1.05, 0.94, 0.84, 0.73, 0.63, 0.52, 0.42, 0.31, 0.21 }, //    8
        { 1.12, 1.01, 0.90, 0.78, 0.67, 0.56, 0.45, 0.34, 0.22 }, //    9
        { 1.20, 1.08, 0.96, 0.84, 0.72, 0.60, 0.48, 0.36, 0.24 }, //    10
        { 1.28, 1.16, 1.03, 0.90, 0.77, 0.64, 0.51, 0.39, 0.26 }, //    11
        { 1.37, 1.24, 1.10, 0.96, 0.82, 0.69, 0.55, 0.41, 0.27 }, //    12
        { 1.47, 1.32, 1.17, 1.03, 0.88, 0.73, 0.59, 0.44, 0.29 }, //    13
        { 1.57, 1.41, 1.25, 1.10, 0.94, 0.78, 0.63, 0.47, 0.31 }, //    14
        { 1.67, 1.51, 1.34, 1.17, 1.00, 0.84, 0.67, 0.50, 0.33 }, //    15
        { 1.79, 1.61, 1.43, 1.25, 1.07, 0.89, 0.71, 0.54, 0.36 }, //    16
        { 1.90, 1.71, 1.52, 1.33, 1.14, 0.95, 0.76, 0.57, 0.38 }, //    17
        { 2.03, 1.83, 1.62, 1.42, 1.22, 1.01, 0.81, 0.61, 0.41 }, //    18
        { 2.16, 1.94, 1.73, 1.51, 1.30, 1.08, 0.86, 0.65, 0.43 }, //    19
        { 2.30, 2.07, 1.84, 1.61, 1.38, 1.15, 0.92, 0.69, 0.46 }, //    20
        { 2.45, 2.20, 1.96, 1.71, 1.47, 1.22, 0.98, 0.73, 0.49 }, //    21
        { 2.60, 2.34, 2.08, 1.82, 1.56, 1.30, 1.04, 0.78, 0.52 }, //    22
        { 2.77, 2.49, 2.21, 1.94, 1.66, 1.38, 1.11, 0.83, 0.55 }, //    23
        { 2.94, 2.65, 2.35, 2.06, 1.76, 1.47, 1.18, 0.88, 0.59 }, //    24
        { 3.12, 2.81, 2.50, 2.19, 1.87, 1.56, 1.25, 0.94, 0.62 }, //    25
        { 3.32, 2.98, 2.65, 2.32, 1.99, 1.66, 1.33, 0.99, 0.66 }, //    26
        { 3.52, 3.17, 2.82, 2.46, 2.11, 1.76, 1.41, 1.06, 0.70 }, //    27
        { 3.73, 3.36, 2.99, 2.61, 2.24, 1.87, 1.49, 1.12, 0.75 }, //    28
        { 3.96, 3.56, 3.17, 2.77, 2.38, 1.98, 1.58, 1.19, 0.79 }, //    29
        { 4.20, 3.78, 3.36, 2.94, 2.52, 2.10, 1.68, 1.26, 0.84 }, //    30
        { 4.45, 4.01, 3.56, 3.12, 2.67, 2.23, 1.78, 1.34, 0.89 }, //    31
        { 4.72, 4.25, 3.78, 3.30, 2.83, 2.36, 1.89, 1.42, 0.94 }, //    32
        { 5.00, 4.50, 4.00, 3.50, 3.00, 2.50, 2.00, 1.50, 1.00 }, //    33
        { 5.29, 4.76, 4.24, 3.71, 3.18, 2.65, 2.12, 1.59, 1.06 }, //    34
        { 5.60, 5.04, 4.48, 3.92, 3.36, 2.80, 2.24, 1.68, 1.12 }, //    35
        { 5.93, 5.34, 4.74, 4.15, 3.56, 2.97, 2.37, 1.78, 1.19 }, //    36
        { 6.27, 5.64, 5.02, 4.39, 3.76, 3.14, 2.51, 1.88, 1.25 }, //    37
        { 6.63, 5.97, 5.30, 4.64, 3.98, 3.32, 2.65, 1.99, 1.33 }, //    38
        { 7.01, 6.31, 5.61, 4.90, 4.20, 3.50, 2.80, 2.10, 1.40 }, //    39
        { 7.40, 6.66, 5.92, 5.18, 4.44, 3.70, 2.96, 2.22, 1.48 }, //    40
        { 7.81, 7.03, 6.25, 5.47, 4.69, 3.91, 3.12, 2.34, 1.56 }, //    41
        { 8.24, 7.42, 6.59, 5.77, 4.94, 4.12, 3.30, 2.47, 1.65 }, //    42
        { 8.69, 7.82, 6.95, 6.08, 5.21, 4.34, 3.47, 2.61, 1.74 }, //    43
        { 9.15, 8.24, 7.32, 6.41, 5.49, 4.58, 3.66, 2.75, 1.83 }, //    44
        { 9.63, 8.67, 7.71, 6.74, 5.78, 4.82, 3.85, 2.89, 1.93 }, //    45
        { 10.13, 9.12, 8.11, 7.09, 6.08, 5.07, 4.05, 3.04, 2.03 }, //   46
        { 10.65, 9.58, 8.52, 7.45, 6.39, 5.33, 4.26, 3.20, 2.13 }, //   47
        { 11.18, 10.07, 8.95, 7.83, 6.71, 5.59, 4.47, 3.36, 2.24 }, //  48
        { 11.73, 10.56, 9.39, 8.21, 7.04, 5.87, 4.69, 3.52, 2.35 }, //  49
        { 12.30, 11.07, 9.84, 8.61, 7.38, 6.15, 4.92, 3.69, 2.46 }  //  50
    };

    temp = x[33];
    chooseStr = roundf(temp) + 10; // Округляем для получения номера строки в массиве massiv

    if (x[32] <= 100 && x[32] > 95)
        chooseCol = 0;
    if (x[32] <= 95 && x[32] > 85)
        chooseCol = 1;
    if (x[32] <= 85 && x[32] > 75)
        chooseCol = 2;
    if (x[32] <= 75 && x[32] > 65)
        chooseCol = 3;
    if (x[32] <= 65 && x[32] > 55)
        chooseCol = 4;
    if (x[32] <= 55 && x[32] > 45)
        chooseCol = 5;
    if (x[32] <= 45 && x[32] > 35)
        chooseCol = 6;
    if (x[32] <= 35 && x[32] > 25)
        chooseCol = 7;
    if (x[32] <= 25)
        chooseCol = 8;

    DAVLENIE = massiv[chooseStr][chooseCol]; // Давление по таблице из ГОСТ Р 52517-2005

    x[530] = ((x[34] - DAVLENIE) / 100.26)*sqrt(288 / (273 + x[33])); // Коэффициент индикаторной мощности К (формула 3)
    x[531] = 1.15*x[530] - 0.15; // Коэффициент приведения Аи (формула 2)
    x[535] = x[502] / x[531]; // Приведенная мощность, л.с. (формула 1)
    x[536] = x[503] / x[531]; // Приведенная мощность, кВт (формула 1)
    x[533] = x[501] / x[531]; // Приведенный крутящий момент, Н*м (формула 4)
    x[537] = x[123] / x[530]; // Приведенный расход топлива, кг/ч (формула 5)
    x[539] = (x[123] * 1000 * x[531]) / (x[503] * x[530]); // Приведенный удельный расход топлива Ceи, г/(кВТ*ч) (формула 6)

    return;
}

If it's possible, check this code. I obtained several errors after copying dll-file to program folder and executing program. Program (written in Borland C++) can't use my dll file (created in Visual Studio). One of the error is something like this

"...Missing MSVCR120D.dll file..."

Thank you in advance, friends!

Arcosha
  • 1
  • 5
  • That is part of the Visual Studio 2013 debug runtime. You need to deploy release binaries. – drescherjm Jan 28 '20 at 18:51
  • @drescherjm I'm not so pro in programming. What does this mean? Something like file with definition of created dll-library? How does it look? – Arcosha Jan 28 '20 at 19:07
  • This file indicates `MSVCR120D.dll` a debug runtime dependency. This dll is only included with Visual Studio and is not supposed to be used on machines that don't have Visual Studio installed. Your situation is basically the same as this question from yesturday: [https://stackoverflow.com/questions/59939744/0xc000007b-the-application-was-unable-to-start-correctly-error#comment106001006_59939744](https://stackoverflow.com/questions/59939744/0xc000007b-the-application-was-unable-to-start-correctly-error#comment106001006_59939744) – drescherjm Jan 28 '20 at 19:11
  • Ohhh, so i just need to install **"Visual C++ Redistributable Packages for Visual Studio 2013"** on the computer with those program as I understand. I thought, that i need to create additional files for my cpp-file. Thank you, I will try. – Arcosha Jan 28 '20 at 19:16
  • You also need to build your `dll` in the `Release` configuration and deploy only that. – drescherjm Jan 28 '20 at 19:17
  • Release = option from top menu of Visual Studio? (Debug, Release) Those settings? I used Debug option. Deploy = I need to copy dll-file that was built with activated Release option? (sorry for my english, i don't know several programming terms in english). – Arcosha Jan 28 '20 at 19:22
  • Correct you need to select `Release` in Visual Studio. – drescherjm Jan 28 '20 at 19:24
  • ***I need to copy dll-file that was built with activated Release option?*** Yes exactly copy and use the `dll` from the `Release` configuration. – drescherjm Jan 28 '20 at 19:29
  • I will try tomorrow and will write result. Thank you very much. – Arcosha Jan 28 '20 at 19:32
  • 1
    @drescherjm Hello. I have tried today Build project as Release. Then I have installed **"Visual C++ Redistributable Packages for Visual Studio 2013"**. Error "...Missing MSVCR120D.dll file..." disappeared. But we obtained other error =) I read several themes about my question and now i think we need create additional file with like **.def**. My co-workers said that my task is too hard and better to crete **dll-file** in **Borland C++ Builder** not in **Microsoft Visual Studio**. =( – Arcosha Jan 29 '20 at 15:34

0 Answers0