Click here to Skip to main content
15,881,709 members
Articles / Programming Languages / XML

How to Automate Exporting .NET Function to Unmanaged Programs

Rate me:
Please Sign up or sign in to vote.
4.90/5 (44 votes)
21 Nov 2006MIT3 min read 456.2K   4.5K   94  
Post-build tool which can automate exporting .NET function to unmanaged programs
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;

namespace ExportDllAttribute
{
    [AttributeUsage(AttributeTargets.Method)] 
    public class ExportDllAttribute: Attribute
    {
        public ExportDllAttribute(string exportName)
            : this(exportName, System.Runtime.InteropServices.CallingConvention.StdCall)
        {
        }

        static Dictionary<System.Runtime.InteropServices.CallingConvention, string> dic = new Dictionary<CallingConvention,string>();

        static ExportDllAttribute()
        {
            dic[System.Runtime.InteropServices.CallingConvention.Cdecl] = typeof(CallConvStdcall).FullName;
            dic[System.Runtime.InteropServices.CallingConvention.FastCall] = typeof(CallConvFastcall).FullName;
            dic[System.Runtime.InteropServices.CallingConvention.StdCall] = typeof(CallConvStdcall).FullName;
            dic[System.Runtime.InteropServices.CallingConvention.ThisCall] = typeof(CallConvThiscall).FullName;
            dic[System.Runtime.InteropServices.CallingConvention.Winapi] = typeof(CallConvStdcall).FullName;
        }

        public ExportDllAttribute(string exportName, System.Runtime.InteropServices.CallingConvention CallingConvention)
        {
            m_ExportName = exportName;
            m_CallingConvention = dic[CallingConvention];
        }

        private string m_ExportName;
        public string ExportName
        {
            get { return m_ExportName; }
        }

        private string m_CallingConvention;
        public string CallingConvention
        {
            get { return m_CallingConvention; }
        }
	
    }
}

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.

License

This article, along with any associated source code and files, is licensed under The MIT License


Written By
Systems / Hardware Administrator
Poland Poland
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions