By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,771 Members | 1,709 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,771 IT Pros & Developers. It's quick & easy.

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

P: 3
Hi Everyone,

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:

Expand|Select|Wrap|Line Numbers
  1. [StructLayout(LayoutKind.Sequential)]
  2. public struct InputPurchaseOrder
  3.     {
  4.         public System.String poJobName;
  5.         public System.String poTradeName;
  6.         public System.Int32 poItemQty;
  7.         public double poDiscount;
  8.         public double poItemRateTaxExclusive;
  9.     }
  11. My structure in C++ DLL looks like this:
  13. struct  InputPurchaseOrder
  14. {
  15.    LPSTR poJobName;
  16.    LPSTR poTradeName;
  17.    int poItemQty ;
  18.    double poDiscount;
  19.    double poItemRateTaxExclusive;
  20. }
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.
I am passing the structure in C# as value type. Even I tried passing as ref .but It did not work.

What may be the reason for this type of behaviour?

Please suggest me with your valuable comments ASAP.
Feb 21 '07 #1
Share this Question
Share on Google+
3 Replies

Expert 2.5K+
P: 4,871
Have you tried writing the values in c# before passing them?
Feb 22 '07 #2

P: 3
Have you tried writing the values in c# before passing them?
Yes It is writing the values properly before passing them to DLL. When I debugged the DLL, as soon as the values are passed to DLL, the double values are writing as 0.00
I am passing my structure as value type from C#. some people told that I have to pass it as reference because the double values are not Marshalled by passing them as values in .Net. I am not so much confident about it. Please suggest me which method I have to use to pass structure as a paramater.
Feb 22 '07 #3

Expert 2.5K+
P: 4,871
What code are you currently using to pass the values?
Feb 23 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.