473,326 Members | 2,134 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,326 software developers and data experts.

cast from structure to int in C++ to C#

Hi, I'm new to C#. I have a C++ program and need to develop it in C# now.

In C++ Program:
typedef struct A_T {
char id[17];
DWORD status;
} AStruct

AStruct rcd;
SYSTEMTIME st;
DWORD dwSN;

In which the rcd and st contain data.
Then I use a dll function "Function" in the C++ Program like this:
Function((DWORD) &rcd, (DWORD) &st, (DWORD) &dwSN);
Just cast to DWORD, and then pass this 3 parameters to the function.

In C#, I write like this:
[StructLayout(LayoutKind.Sequential )]
public struct AStruct {
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=17)] public string id;
public int status;
}

[StructLayoutAttribute(LayoutKind.Sequential)]
public struct SYSTEMTIME
{
public short year;
public short month;
public short dayOfWeek;
public short day;
public short hour;
public short minute;
public short second;
public short milliseconds;
}

But I do not have idea how to use the function in C#.
Can you help translate to C#?

Thanks
Grace
Nov 16 '05 #1
1 3588
Hi Grace
In c# function calling is the same as C++ also as c++ you can cast input
parameters using the brackets (type you want to cast to) object. Check this
link I think it may help you with c#

http://msdn.microsoft.com/msdnmag/is...p/default.aspx

Mohamed Mahfouz
MEA Developer Support Center
ITworx on behalf of Microsoft EMEA GTSC

Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

36
by: MSG | last post by:
The answer is neither. Use macros. #define ALLOC(size, type) ((type) *) malloc((size) * sizeof(type)) #define NEW(type, name, size) (type) * (name) = ALLOC((size), (type)) They are both ...
12
by: Martin | last post by:
Two questions relating to FAQ answer 12.42. (1) In the statement s.i16 |= (unsigned)(getc(fp) << 8); i16 is declared int. The reason for casting to (unsigned) is explained as guarding...
16
by: Martijn | last post by:
Hi, I recently updated my version of gcc (to gcc version 3.4.2 (mingw-special) ), and I get a warning I am not too sure about how to best solve: warning: use of cast expressions as lvalues is...
3
by: Brian Bischof | last post by:
I'm using a third-party tool that takes a DataTable as a parameter. I really need to pass it a DataView instead. When I try to explicitly cast the DataView as a DataTable I get an error that they...
3
by: Pablo Gutierrez | last post by:
I have a C# method that reads Binary data (BLOB type) from a database and returns the data an array of bytes (i.e byte outbyte = new byte;). The BLOB column is saved into the database by a C...
3
by: Zürcher See | last post by:
I'm using the following structure for my programm, and I never had problems. Now by the invoke of the MyObject_End eventhandler I get the following error: System.Windows.FormsSpecified cast is...
5
by: Eric bouxirot | last post by:
hi, i'd like to do a "cast", who seem to be very complicated in .NET. in C standard it's so easy... i explain : i have made an app based on plugin architecture in VB.NET. all work fine.. ...
2
by: Eric bouxirot | last post by:
hi, i'd like to do a "cast", who seem to be very complicated in .NET. in C standard it's so easy... i explain : i have made an app based on plugin architecture in VB.NET. all work fine.. ...
4
by: JackBlack | last post by:
Hi, all! Need a little help tracking down a runtime error problem. I'm getting this error: "Unable to cast object of type 'myStruct' to type 'myStruct'... but the two types are identical! I...
12
by: Milux | last post by:
Hi All, This question has to do with interface design. Suppose I have an translation tool. It can translates structs from type "general" to other types and then does some processing. Example:...
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
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
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: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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

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.