473,322 Members | 1,287 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

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

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.     }
  10.  
  11. My structure in C++ DLL looks like this:
  12.  
  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
3 2089
kenobewan
4,871 Expert 4TB
Have you tried writing the values in c# before passing them?
Feb 22 '07 #2
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
kenobewan
4,871 Expert 4TB
What code are you currently using to pass the values?
Feb 23 '07 #4

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

Similar topics

6
by: Iain Bishop | last post by:
I'm trying to model objects for the following problem: A building site contains assemblies, each of which can contain other assemblies and/or materials. I have modelled this using a Site...
3
by: Steven Taylor | last post by:
Hope someone can assist. I'm trying to answer a book question. I'm going around in circles in relation to 'pointer-to-char'. Object : A short program is to be created, which involves a...
8
by: J Krugman | last post by:
There was a time when all I programmed was C. I thought I'd never forget it; not the basics anyway. Therefore I find it very upsetting that this is giving me a segfault: #include <stdio.h>...
2
by: James Radke | last post by:
Hello, I have a vb.net windows application that is calling an older DLL provided by a third party. They supplied a VB 6 application that, when run on my systemn successfully passes data to the...
2
by: ajikoe | last post by:
Hi, I tried to follow the example in swig homepage. I found error which I don't understand. I use bcc32, I already include directory where my python.h exist in bcc32.cfg. /* File : example.c...
4
by: sofeng | last post by:
The following link shows a chart I created about passing structures among functions. Would you review it and tell me if it requires any corrections? ...
11
by: abhiM | last post by:
I have a struct that has an array in it. I need to assign space to the array in a function and pass the corresponding struct by reference to another function so that it can store values into the...
14
by: ds | last post by:
Hi all, I have to pass an array of doubles to a legacy C function that copies some data using memcpy. The code would look like this: extern "C"{ void legacyCFunctionFill(void* arg); } .......
43
by: John | last post by:
Hi This .net is driving me crazy!! In VB6 I had a type which contained a couple of multi-dimentional arrays which i used to create and read records: Type AAA : Array1(10,10,2) as Integer
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.