473,394 Members | 1,696 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,394 software developers and data experts.

c++ typedef structs in c#

Hi,
i know that typedef structs creates an aliases for a particular struct in C++.
i m trying to convert .h c++ files to a namespace in C#.net so that i use
C++ DLL in my C# application.
one of the structs in C++ is something like
typedef struct mystruct {....} mystruct1, *mystruct2;
since typedef is used, mystruct1 and *mystruct2 are aliases to mystruct.
how can i acheive the same (i.e aliasses in c#)? i can subtitute mystruct1 and *mystruct2 in the C# namespace (which i am creating) by mystruct. but i am not sure if they are used in the DLL?
your help is greatly appreciated. i am new to DLL and C#
thanks

Nov 16 '05 #1
6 3861
how can i acheive the same (i.e aliasses in c#)? i can subtitute mystruct1 and *mystruct2 in the C# namespace (which i am creating) by mystruct. but i am not sure if they are used in the DLL?


Once the C++ code is compiled, the names are not important anymore.
What matters is that your C# structs have the same memory layout as
the original C++ struct, you can then name it anything you want.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 16 '05 #2
First, you cannot have *mystruct2 in C#. C# doesn't have pointers. And no
you still can't do pointer to struct, though you can do AddressOf
(FunctionName). Thats about the only pointer like thing you have in C#/.NET.
That is hella useful for our equivalent of callback functions.

Secondly structs in C# are very different from structs in C++. In C++ a
struct is a class with all members public, in C# a struct is a value type
which is always declared inline/stack (versus heap in C++). It is not a
class in C#.

What you really need is a class, not a struct. .. and atleast I donot know
of a way to do *LPMyStruct1, though maybe if I saw the actual code .. I
could take a shot at it.

--
- Sahil Malik
Independent Consultant
You can reach me thru my blog at -
http://www.dotnetjunkies.com/weblog/sahilmalik/

"marabo82" <ma******@discussions.microsoft.com> wrote in message
news:24**********************************@microsof t.com...
Hi,
i know that typedef structs creates an aliases for a particular struct in C++. i m trying to convert .h c++ files to a namespace in C#.net so that i use
C++ DLL in my C# application.
one of the structs in C++ is something like
typedef struct mystruct {....} mystruct1, *mystruct2;
since typedef is used, mystruct1 and *mystruct2 are aliases to mystruct.
how can i acheive the same (i.e aliasses in c#)? i can subtitute mystruct1 and *mystruct2 in the C# namespace (which i am creating) by mystruct. but i
am not sure if they are used in the DLL? your help is greatly appreciated. i am new to DLL and C#
thanks

Nov 16 '05 #3
>First, you cannot have *mystruct2 in C#. C# doesn't have pointers.

Yes it does.

And no
you still can't do pointer to struct, though you can do AddressOf
(FunctionName).


AddressOf is a VB keyword.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 16 '05 #4
Allright new EventHandler ..

How do you have pointers in C#?

- Sahil Malik
Independent Consultant
You can reach me thru my blog - http://dotnetjunkies.com/WebLog/sahilmalik/

"Mattias Sjögren" <ma********************@mvps.org> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
First, you cannot have *mystruct2 in C#. C# doesn't have pointers.


Yes it does.

And no
you still can't do pointer to struct, though you can do AddressOf
(FunctionName).


AddressOf is a VB keyword.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

Nov 16 '05 #5
In article <en**************@TK2MSFTNGP12.phx.gbl>,
co*****************@nospam.com says...
Allright new EventHandler ..

How do you have pointers in C#?


unsafe {
double foo, *p;

p = &foo;
*p = 5;
}

look familiar?

Nov 16 '05 #6
Oh man .. yes the unsafe keyword. .. now that rings a bell.

Thanks

- SM
"John Doe" <na**@domain.com> wrote in message
news:MP************************@news-server.mn.rr.com...
In article <en**************@TK2MSFTNGP12.phx.gbl>,
co*****************@nospam.com says...
Allright new EventHandler ..

How do you have pointers in C#?


unsafe {
double foo, *p;

p = &foo;
*p = 5;
}

look familiar?

Nov 16 '05 #7

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

Similar topics

30
by: stephen henry | last post by:
Hi all, I have a question that I'm having difficulty answering. If I have a struct: typedef struct my_struct_tag{ struct my_other_struct *other; } my_struct_tag
0
by: marabo82 | last post by:
Hi, i know that typedef structs creates an aliases for a particular struct in C++. i m trying to convert .h c++ files to a namespace in C#.net so that i use C++ DLL in my C# application. one of...
17
by: Steve Carter | last post by:
Can someone please explain why the following is not possible? typedef foobar { int x; foobar *next; /* why can't we do this? */ }; Thanks
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
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 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.