Click here to Skip to main content
Licence 
First Posted 11 May 2003
Views 81,558
Bookmarked 22 times

A P/Invoke Type Translator

By | 11 May 2003 | Article
Typtrans is a free command-line utility that helps you to translate C/C++ enumerations, unions and structures into CSharp and VB.NET code.

Introduction

The .NET framework provides us with a service called Platform Invoke. This service enables managed code to call unmanaged functions implemented in dynamic link libraries (DLLs), such as those in the Win32 API. It locates and invokes an exported function and marshals its arguments (integers, strings, arrays, structures, and so on) across the interoperation boundary, as needed.

However, many unmanaged functions expect you to pass, as a parameter to the function, members of structures (user-defined types in Visual Basic) that are defined in managed code. When passing structures to unmanaged code using platform invoke, you must provide additional information to preserve the original layout and alignment.

For more information, see « A closer look at Platform Invoke » on MSDN.

What is TypTrans?

Typtrans is a free command-line utility that helps you to translate C/C++ enumerations, unions and structures into C# and VB.NET code. This little utility can make you save a considerable amount of time leveraging .NET in your current environment.

Features

I have provided a sample header file (sample.h) that will demonstrate what can be accomplished with TypTrans. If your questions about using this tool have not been answered here, please Email me at support@advover.com.

Syntax

TypTrans [-v] [-s] [-t:synsfile] srcfile [destfile]

The file sample.h.cs was generated by using the following command:

TypTrans -t:wintyp.syn sample.h

Disclaimer

TYPTRANS is contributed «AS IS », with no warranties of any kind, including warranties of merchantability and fitness for a particular purpose.

Conclusion

I welcome your suggestions about this tool. If you find it useful or if you find a bug, please let me know. Enjoy !

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Frederic Rezeau

Founder
Perform Labs
United Kingdom United Kingdom

Member

My name is Frederic Rezeau, I am a certified MCSD IT Professional. Based in London, I have a background in the medical industry developing components related to the UK National Program for IT. Prior to that, I worked in the banking sector in France developing distributed security applications.
 
Visit my website for more information.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
NewsDO NOT VISIT THIS AUTHOR'S HOMEPAGE PinmemberPJ Arends9:58 8 Mar '12  
GeneralRe: DO NOT VISIT THIS AUTHOR'S HOMEPAGE PinmemberFrederic Rezeau5:14 26 Mar '12  
GeneralPlease share code to allow further enhance of tool Pinmemberidan_bismut10:19 27 Oct '09  
Generalwish add a new function to convert windows API PinmemberAhfu20:27 13 Jan '06  
QuestionIsn't this called *code*project? PinmemberAlexander Gräf5:35 30 Jan '05  
GeneralMono PinsussAnonymous3:04 3 Nov '03  
Generalunions with array members Pinmemberarian_shailesh5:50 22 Jul '03  
Generaltypedef does not work PinmemberHeadless Rider20:28 29 May '03  
GeneralIt does not work on Windows header files... PinmemberAlex Kucherenko20:53 14 May '03  
QuestionCan you publish sources? PinmemberAlex Kucherenko20:44 14 May '03  
GeneralPacking PinmemberRichard Birkby23:10 13 May '03  
GeneralRequested improvements Pinmemberehollas11:01 13 May '03  
GeneralRe: Requested improvements Pinmemberehollas5:43 14 May '03  
GeneralGreate PinmemberMeisi17:50 12 May '03  
Generalgui PinmemberGoran Mitrovic11:00 12 May '03  
GeneralNice but not much detail PinmemberGriffonRL2:30 12 May '03  
GeneralInteresting PinmemberPaul Ingles0:08 12 May '03  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.120517.1 | Last Updated 12 May 2003
Article Copyright 2003 by Frederic Rezeau
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid