473,233 Members | 1,703 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,233 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 2085
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
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
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...

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.