I have created 2 structures in my C# code : - [StructLayoutAttribute(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
-
public class RollInformationCSharp
-
{
-
[MarshalAs(UnmanagedType.R8)]
-
public double rollDiameter;
-
-
[MarshalAs(UnmanagedType.R8)]
-
public double initialRoughness;
-
-
[MarshalAs(UnmanagedType.R8)]
-
public double finalRoughness;
-
-
[MarshalAs(UnmanagedType.R8)]
-
public double accumulateCombination;
-
-
[MarshalAs(UnmanagedType.R8)]
-
public double critialRollLength;
-
-
[MarshalAs(UnmanagedType.R8)]
-
public double rolledLength;
-
-
[MarshalAs(UnmanagedType.R8)]
-
public double percentageLifeRoll;
-
-
[MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst = 256)]
-
public string rollName;
-
};
and : - [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
-
public class MultiRollCSharp
-
{
-
[MarshalAs(UnmanagedType.I4)]
-
public int nbRoll;
-
-
public RollInformationCSharp[] tabRoll;
-
}
In the C# code, i invoke a function of C++ dll : - [DllImport("DLL_RaFTmodel.dll", CharSet = CharSet.Ansi)]
-
public static extern IntPtr DLL_FlesCalculation(MultiRollCSharp multiRollInfo,
-
CoilInformationCSharp coilInfo,
-
RollInformationCSharp rollInfo,
-
LimitsTypeCSharp LimitsSteel,
-
LimitsTypeCSharp LimitsRegulation,
-
LimitsTypeCSharp LimitsMachine,
-
FTInputsCsharp forceTensionInfo,
-
RaConstantsCSharp RaModelIn,
-
FTWeightCsharp FTmodelIn,
-
[In, MarshalAs(UnmanagedType.I4)] int strategy,
-
[In, MarshalAs(UnmanagedType.I4)] int rollLifeMaximization,
-
RaInputsCsharp RaDataIn,
-
char Version,
-
[In, MarshalAs(UnmanagedType.R4)] float errMax,
-
[Out, MarshalAs(UnmanagedType.I4)] out int error);
In C++, I have also 2 structures : - struct RollInformation
-
{
-
double rollDiameter;
-
double initialRoughnessRoll;
-
double finalRoughnessRoll;
-
double accumulateCombination;
-
double percentageLifeRoll;
-
double criticalRollLength;
-
double rolledLength;
-
char rollName[256];
-
};
and - struct MultiRollInformation
-
{
-
int nbRoll;
-
RollInformation* tabRoll;
-
};
The function is also declared as follow : - extern EXPORTTOTEM_API
-
MULTICURVETYPE* DLL_FlesCalculation( struct MultiRollInformation *multiRollInfo, struct CoilInformation *coilInfo,
-
struct RollInformation *rollInfo,
-
struct LimitsType *LimitsSteel,
-
struct LimitsType *LimitsRegulation,
-
struct LimitsType *LimitsMachine,
-
struct FTInputs *forceTensionInfo,
-
struct RaConstants *constRaIn,
-
struct FTWeight *modelFTIn,
-
int strategy,
-
int rollLifeMaximization,
-
struct RaInputs *dataRaIn,
-
char Version,
-
float errMax,
-
int &error);
Example to fill the structure in C# : - MultiRollCSharp multiRollInfo = new MultiRollCSharp();
-
for(int i = 0; i < 5; i++)
-
{
-
RollInformationCSharp rollInfo1 = GetRollInformation();
-
int taille = 0;
-
if (multiRollInfo.tabRoll != null)
-
taille = multiRollInfo.tabRoll.Length;
-
-
RollInformationCSharp[] tab = new RollInformationCSharp[taille +1];
-
if (taille > 0)
-
{
-
multiRollInfo.tabRoll.CopyTo(tab, 0);
-
}
-
tab[tab.Length-1] = rollInfo1;
-
multiRollInfo.tabRoll = tab;
-
-
multiRollInfo.nbRoll += 1;
-
}
In debug mode, just before the call to the DLL, the both structures in C# are right (multiRollInfo and rollInfo)
.
In C++, the rollInfo is good. But the the multiroll info has 5 elements but there values are wrong .
What is wrong?
How can I correct this?
thank you very much for your help
0 1157 Sign in to post your reply or Sign up for a free account.
Similar topics
by: Bob Rock |
last post by:
Hello,
in the last few days I've made my first few attempts at creating mixed C++
managed-unmanaged assemblies and looking aftwerwards with ILDASM at what is
visible in those assemblies from a...
|
by: Paul Kenny |
last post by:
Hi,
I am trying to expose the functionality of an unmanaged
C++ class to the other languages available in the .NET
Framework. I have decided to do this by wrapping the
unmanaged C++ class in a...
|
by: Rachel Suddeth |
last post by:
What is the difference between a managed/unmanaged resource, and how do you
tell which is which? I'm trying to understand how to write some Dispose()
methods, and we are supposed to put code that...
|
by: zhphust |
last post by:
I want to convert a object of a managed class to a unmanaged structure
that has the same member with that managed class. Can anybody tell me
how i can do it?
Thanks in advance.
--
zhphust...
|
by: Sparhawk |
last post by:
Hi,
my company is going to migrate a large VC++ application to .NET to
make use of Windows Forms (the old class library is not updated any
more). We are not planning to migrate the rest of the...
|
by: marek |
last post by:
Hello All,
we are doing a quite a big project that contains at
the lowest level an unmenaged c++ classes. Above it there
are managed wrappers and at the top there are ASP.NET
pages. Can anyone...
|
by: Stephen Walch |
last post by:
Our application environment consists of three basic layers:
1. Third-party unmanaged DLLs that were written before the CLR was invented
and maintain a significant amount of information (including...
|
by: Amit Dedhia |
last post by:
Hi All
I have a VC++ 2005 MFC application with all classes defined as
unmanaged classes. I want to write my application data in xml format.
Since ADO.NET has buit in functions available for...
|
by: akash |
last post by:
I'm having problems calling an unmanaged class from a managed wrapper.
I suspect I'm missing something obvious, as I'm unfamiliar with C++ and
classes are very simple. My unmanaged class is as...
|
by: Jon Slaughter |
last post by:
How difficult is it for one to integrate unmanaged C++ into C#? I know for
functions one can use DLLimport but how does one go about doing it for
classes? Do I have to completely reimplement the...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
| |