Click here to Skip to main content
13,350,985 members (53,546 online)
Click here to Skip to main content


55 bookmarked
Posted 30 May 2001

Mixing Managed and Unmanaged code

, 30 May 2001
C++ managed code introduced us a new string type, namely System.String. You can imagine though, that some conversion functions are needed to work with this new string type when mixing managed and unmanaged code in your project.
namespace StringSampleCSharp
    using System;
	using System.Runtime.InteropServices;

    public class Class1
        public Class1()
            // TODO: Add Constructor Logic here

	     public static extern int MessageBoxA(int h, 
											  [MarshalAs(UnmanagedType.LPStr)]string m, 
											  [MarshalAs(UnmanagedType.LPStr)]string c, 
			                                  int type);

		public static int Main(string[] args)
			MessageBoxA(0, "Hello World!", "My Message Box", 0);

            return 0;

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


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

Nick Van den Abbeele
Web Developer
Belgium Belgium
No Biography provided

You may also be interested in...

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.180111.1 | Last Updated 31 May 2001
Article Copyright 2001 by Nick Van den Abbeele
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid