Problem in Passing double values from a C# Structure to a legacy C++ DLL

Feb 22 2007 12:52 AM
Hi Friends,
I have a .Net Application, through which I am invoking a function from a legacy DLL developed in C++. My structure in C# contains some data of type double which I need to pass to to the DLL to get some results back from it.

My Structure In C# looks like this:

[StructLayout(LayoutKind.Sequential)]
public struct InputPurchaseOrder
    {
        public System.String poJobName;
        public System.String poTradeName;
        public System.Int32 poItemQty;
        public double poDiscount;
        public double poItemRateTaxExclusive;

    }


My structure in C++ DLL looks like this:

struct  InputPurchaseOrder
{
   LPSTR poJobName;
   LPSTR poTradeName;
   int poItemQty ;
   double poDiscount;
   double poItemRateTaxExclusive
;
}

When I pass the structure through C#, everything is passing to DLL, except the two double values. It is paasing these values as 0.00 rather than the exact values passed.

The other values like string, int are passing with their respected values.

I am passing the structure in C# as value type. 

Pls help in understanding:
1. How to Marshal double values from C# to a C++ DLL.
2. What are the possible steps to be taken care while passing double values to a C++ DLL