Click here to Skip to main content
12,074,763 members (60,332 online)
Click here to Skip to main content

Stats

258.6K views
3.2K downloads
87 bookmarked
Posted

How to Automate Exporting .NET Function to Unmanaged Programs

, 21 Nov 2006 CPOL
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 Code Project Open License (CPOL)

Share

About the Author

Selvin
Systems / Hardware Administrator
Poland Poland
No Biography provided

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.160208.1 | Last Updated 22 Nov 2006
Article Copyright 2006 by Selvin
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid