EDN Admin
Well-known member
Hi-
Im working on creating a C++ DLL that is being used with a VB6 program. I used a msdn support article 194609 to figure out how to pass my array of UDT from VB6 to my DLL, but am now struggling to simple add some of the array elements together.
My VB MessageBox says "Finished TFA Calc =-9.25596411572893E+61" I thought it might be dereferencing so I tried adding a * like this "so->B1a += *(ft+1)->Area;" which gave me a "error C2100: illegal indirection" when I try to compile my DLL. Any idea
how to make the C++ for loop work?
Thanks in advance!
Here is my .cpp file:
<div style="color:Black;background-color:White; <pre>
#include <windows.h>
#include <oleauto.h>
#include <iostream>
#define WIN32_LEAN_AND_MEAN
#include <stdio.h>
#<span style="color:Blue; using <mscorlib.dll>
#<span style="color:Blue; using <system.dll>
<span style="color:Blue; using <span style="color:Blue; namespace std;
<span style="color:Blue; using <span style="color:Blue; namespace System;
<span style="color:Blue; using <span style="color:Blue; namespace System::Collections;
<span style="color:Green; ///////////////////////////////////////////////////////////
<span style="color:Green; // Defining Floor Table - //
<span style="color:Green; // This is the data from the Floor Table. //
<span style="color:Green; // //
<span style="color:Green; ///////////////////////////////////////////////////////////
<span style="color:Blue; typedef <span style="color:Blue; struct FloorTableTemplate
{
BSTR Description;
<span style="color:Blue; short Type;
<span style="color:Blue; short Construction;
<span style="color:Blue; double Area;
<span style="color:Blue; double LivingArea;
<span style="color:Blue; double UValue;
<span style="color:Blue; short Storey;
} FloorTable;
<span style="color:Green; ///////////////////////////////////////////////////////////
<span style="color:Green; // Defining SAP_Rtn - //
<span style="color:Green; // This is the data that is returned from the DLL. //
<span style="color:Green; // Each Box from the Worksheet. //
<span style="color:Green; ///////////////////////////////////////////////////////////
<span style="color:Blue; typedef <span style="color:Blue; struct SAPOutputTemplate
{
<span style="color:Blue; double B1a;
<span style="color:Blue; double B1b;
<span style="color:Blue; double B1c;
<span style="color:Blue; double B1d;
<span style="color:Blue; double B1e;
} SAP_Rtn;
<span style="color:Blue; void __stdcall CalculateTFA(<span style="color:Blue; struct FloorTableTemplate *ft, <span style="color:Blue; struct SAPOutputTemplate *so , <span style="color:Blue; long nTotalItem)
{
<span style="color:Green; // Adjust the total number of elements in the array
<span style="color:Blue; long i = nTotalItem - 1; <span style="color:Green; // the array begins from 0
<span style="color:Green; // Calculate Total Floor Area
<span style="color:Blue; for (i = 0; i < nTotalItem; i++)
{
so->B1a += (ft+i)->Area;
}
}
[/code]
And my .odl file
<br/>
<div style="color:Black;background-color:White; <pre>
[
<span style="color:Blue; uuid(0DCDB972-6865-47cb-AE40-B88CD23294EC),
helpstring(<span style="color:#A31515; "Pass Array of UDTs Helper")
]
library PassUDTLib
{
<span style="color:Green; //definition of the UDT
<span style="color:Green; ///////////////////////////////////////////////////////////
<span style="color:Green; // Defining Floor Table - //
<span style="color:Green; // This is the data from the Floor Table. //
<span style="color:Green; // //
<span style="color:Green; ///////////////////////////////////////////////////////////
<span style="color:Blue; typedef <span style="color:Blue; struct FloorTableTemplate
{
BSTR Description;
<span style="color:Blue; short Type;
<span style="color:Blue; short Construction;
<span style="color:Blue; double Area;
<span style="color:Blue; double LivingArea;
<span style="color:Blue; double UValue;
<span style="color:Blue; short Storey;
} FloorTable;
<span style="color:Green; ///////////////////////////////////////////////////////////
<span style="color:Green; // Defining SAP_Rtn - //
<span style="color:Green; // This is the data that is returned from the DLL. //
<span style="color:Green; // Each Box from the SAP Worksheet. //
<span style="color:Green; ///////////////////////////////////////////////////////////
<span style="color:Blue; typedef <span style="color:Blue; struct SAPOutputTemplate
{
<span style="color:Blue; double B1a;
<span style="color:Blue; double B1b;
<span style="color:Blue; double B1c;
<span style="color:Blue; double B1d;
<span style="color:Blue; double B1e;
<span style="color:Blue; double B1n;
<span style="color:Blue; double B2a;
<span style="color:Blue; double B2b;
<span style="color:Blue; double B2c;
<span style="color:Blue; double B2d;
<span style="color:Blue; double B2e;
<span style="color:Blue; double B2n;
} SAP_Rtn;
[
helpstring(<span style="color:#A31515; "test"),
dllname(<span style="color:#A31515; "C:UsersAlaineDesktopudtUDTArray.dll")
]
module structDLL
{
[
helpstring(<span style="color:#A31515; "Calculate the Total Floor Area"),
entry(<span style="color:#A31515; "CalculateTFA")
]
<span style="color:Blue; void _stdcall CalculateTFA
(
[<span style="color:Blue; in, out] FloorTable* ft,
[<span style="color:Blue; in, out] SAP_Rtn* so,
[<span style="color:Blue; in] <span style="color:Blue; long nTotalItem
);
};
};
[/code]
And my VB6:
<br/>
<pre>Private Sub Command0_Click()
Calc tfa
Dim ft(0 To 3) As FloorTableTemplate
ft(0).Area = 51
ft(1).Area = 12.4
ft(2).Area = 5
ft(3).Area = 50
Dim so As SAPOutputTemplate
i = UBound(ft) - LBound(ft) + 1
CalculateTFA ft(0), so, i
MsgBox "Finished TFA Calc =" & so.B1a
End Sub
[/code]
<br/>
<br/>
View the full article
Im working on creating a C++ DLL that is being used with a VB6 program. I used a msdn support article 194609 to figure out how to pass my array of UDT from VB6 to my DLL, but am now struggling to simple add some of the array elements together.
My VB MessageBox says "Finished TFA Calc =-9.25596411572893E+61" I thought it might be dereferencing so I tried adding a * like this "so->B1a += *(ft+1)->Area;" which gave me a "error C2100: illegal indirection" when I try to compile my DLL. Any idea
how to make the C++ for loop work?
Thanks in advance!
Here is my .cpp file:
<div style="color:Black;background-color:White; <pre>
#include <windows.h>
#include <oleauto.h>
#include <iostream>
#define WIN32_LEAN_AND_MEAN
#include <stdio.h>
#<span style="color:Blue; using <mscorlib.dll>
#<span style="color:Blue; using <system.dll>
<span style="color:Blue; using <span style="color:Blue; namespace std;
<span style="color:Blue; using <span style="color:Blue; namespace System;
<span style="color:Blue; using <span style="color:Blue; namespace System::Collections;
<span style="color:Green; ///////////////////////////////////////////////////////////
<span style="color:Green; // Defining Floor Table - //
<span style="color:Green; // This is the data from the Floor Table. //
<span style="color:Green; // //
<span style="color:Green; ///////////////////////////////////////////////////////////
<span style="color:Blue; typedef <span style="color:Blue; struct FloorTableTemplate
{
BSTR Description;
<span style="color:Blue; short Type;
<span style="color:Blue; short Construction;
<span style="color:Blue; double Area;
<span style="color:Blue; double LivingArea;
<span style="color:Blue; double UValue;
<span style="color:Blue; short Storey;
} FloorTable;
<span style="color:Green; ///////////////////////////////////////////////////////////
<span style="color:Green; // Defining SAP_Rtn - //
<span style="color:Green; // This is the data that is returned from the DLL. //
<span style="color:Green; // Each Box from the Worksheet. //
<span style="color:Green; ///////////////////////////////////////////////////////////
<span style="color:Blue; typedef <span style="color:Blue; struct SAPOutputTemplate
{
<span style="color:Blue; double B1a;
<span style="color:Blue; double B1b;
<span style="color:Blue; double B1c;
<span style="color:Blue; double B1d;
<span style="color:Blue; double B1e;
} SAP_Rtn;
<span style="color:Blue; void __stdcall CalculateTFA(<span style="color:Blue; struct FloorTableTemplate *ft, <span style="color:Blue; struct SAPOutputTemplate *so , <span style="color:Blue; long nTotalItem)
{
<span style="color:Green; // Adjust the total number of elements in the array
<span style="color:Blue; long i = nTotalItem - 1; <span style="color:Green; // the array begins from 0
<span style="color:Green; // Calculate Total Floor Area
<span style="color:Blue; for (i = 0; i < nTotalItem; i++)
{
so->B1a += (ft+i)->Area;
}
}
[/code]
And my .odl file
<br/>
<div style="color:Black;background-color:White; <pre>
[
<span style="color:Blue; uuid(0DCDB972-6865-47cb-AE40-B88CD23294EC),
helpstring(<span style="color:#A31515; "Pass Array of UDTs Helper")
]
library PassUDTLib
{
<span style="color:Green; //definition of the UDT
<span style="color:Green; ///////////////////////////////////////////////////////////
<span style="color:Green; // Defining Floor Table - //
<span style="color:Green; // This is the data from the Floor Table. //
<span style="color:Green; // //
<span style="color:Green; ///////////////////////////////////////////////////////////
<span style="color:Blue; typedef <span style="color:Blue; struct FloorTableTemplate
{
BSTR Description;
<span style="color:Blue; short Type;
<span style="color:Blue; short Construction;
<span style="color:Blue; double Area;
<span style="color:Blue; double LivingArea;
<span style="color:Blue; double UValue;
<span style="color:Blue; short Storey;
} FloorTable;
<span style="color:Green; ///////////////////////////////////////////////////////////
<span style="color:Green; // Defining SAP_Rtn - //
<span style="color:Green; // This is the data that is returned from the DLL. //
<span style="color:Green; // Each Box from the SAP Worksheet. //
<span style="color:Green; ///////////////////////////////////////////////////////////
<span style="color:Blue; typedef <span style="color:Blue; struct SAPOutputTemplate
{
<span style="color:Blue; double B1a;
<span style="color:Blue; double B1b;
<span style="color:Blue; double B1c;
<span style="color:Blue; double B1d;
<span style="color:Blue; double B1e;
<span style="color:Blue; double B1n;
<span style="color:Blue; double B2a;
<span style="color:Blue; double B2b;
<span style="color:Blue; double B2c;
<span style="color:Blue; double B2d;
<span style="color:Blue; double B2e;
<span style="color:Blue; double B2n;
} SAP_Rtn;
[
helpstring(<span style="color:#A31515; "test"),
dllname(<span style="color:#A31515; "C:UsersAlaineDesktopudtUDTArray.dll")
]
module structDLL
{
[
helpstring(<span style="color:#A31515; "Calculate the Total Floor Area"),
entry(<span style="color:#A31515; "CalculateTFA")
]
<span style="color:Blue; void _stdcall CalculateTFA
(
[<span style="color:Blue; in, out] FloorTable* ft,
[<span style="color:Blue; in, out] SAP_Rtn* so,
[<span style="color:Blue; in] <span style="color:Blue; long nTotalItem
);
};
};
[/code]
And my VB6:
<br/>
<pre>Private Sub Command0_Click()
Calc tfa
Dim ft(0 To 3) As FloorTableTemplate
ft(0).Area = 51
ft(1).Area = 12.4
ft(2).Area = 5
ft(3).Area = 50
Dim so As SAPOutputTemplate
i = UBound(ft) - LBound(ft) + 1
CalculateTFA ft(0), so, i
MsgBox "Finished TFA Calc =" & so.B1a
End Sub
[/code]
<br/>
<br/>
View the full article