473,508 Members | 2,202 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3870
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
4201
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
407
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
3287
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
7227
marktang
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,...
0
7127
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...
0
7331
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
7391
jinu1996
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...
0
4713
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...
0
3204
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3188
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1564
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
424
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.