C++ & .NET, garbage pointer

My UI source is constructed with .NET

Also, I'm trying to connect the function of engine source(which is constructed with C++) to the UI.

One of the parameter in the function is Structure : stOutput

In my UI source I defined this Structure like below. (All the data type of member variables is Integer and Double)

Public Structure stOutput
        Public lDate As Integer
        ...
        Public dMoney As Double
End Structure

Also In my engine source(dll), I defined this struct like below (All the data type of member variables is Long and Double)

#pragma pack(8)
typedef struct  stOutput
{ 
        long lDate;
        ...
        Double dMoney;
}stOutput;
#pragma pop

I defined the function in the UI source(.NET) like this,

Public Declare Function Calc_Salary Lib "Salary" _
        (ByRef Output As stOutput) as Integer

I wrote it as 'ByRef' because the dll receive this Output as parameter, then it modifies values in the structure 'Output' then return the outcome that is calculated in the dll to UI.

And I defined the function in the engine source(dll) like this,

extern "C" long FuncExport __stdcall Calc_Salary(stOutput *Output);

The Main Problem is after the function conveys the value from dll to UI source, the value becomes garbage value.

when I debug it in the UI source, before calling the function 'Calc_Salary', The variables have correct value ,for example.

lDate = 20210927
dMoney = 30000.00

When I debug it in the dll source, Input value is like below.

lDate = 20210927
dMoney = 30000.00

And, before returning the value from the function 'Calc_Salary', Again the variables have correct value, for example.

lDate = 20210930
dMoney = 30200.05

Finally, when the function returns value to the UI source then the value becomes garbage like this

lDate = 20180230 (it seems like correct however, totally not reasonable value considering my logic)
dMoney = 5.7824553468304092E-254

I tried to match the name of variables in the struct. And corrects all the typos one by one. Also matches all the sequence of the variable and parameter.

But I totally don't know what is the reason.

**p.s. the parameter is like grid, I mean, 'Output' is Array of struct! for example

Output(0) :
lDate = 20200801
dMoney = 30000.00

Output(1) :
lDate = 20200901
dMoney = 40000.00

Output(2) :
lDate = 20201001
dMoney = 35000.00

... 
How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum