473,796 Members | 2,482 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 3918
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******@discu ssions.microsof t.com> wrote in message
news:24******** *************** ***********@mic rosoft.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.o rg> wrote in message
news:%2******** ********@TK2MSF TNGP11.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.co m> wrote in message
news:MP******** *************** *@news-server.mn.rr.co m...
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
4276
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 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...
17
3318
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
10455
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10228
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9052
agi2029
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7547
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5441
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5573
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4116
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 we have to send another system
2
3731
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2925
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.