MyException - 我的异常网
当前位置:我的异常网» C# » c#调用C++写的dll导出类,怎么实现

c#调用C++写的dll导出类,怎么实现(2)

www.MyException.Cn  网友分享于:2013-06-16  浏览:243次

你要调用c++里面的类啊,呵呵
------解决方案--------------------
c#调用 c++的dll文件

http://blog.csdn.net/zhangzxy161723/archive/2009/04/28/4132853.aspx
------解决方案--------------------
http://topic.csdn.net/u/20090430/17/5148f3de-9f7d-45b1-b5ba-2fcaf06baafc.html


------解决方案--------------------
MARK,楼主可以搜一下C#调用ActiveDesktop的代码,据说那是个C++类,贴一点,仅供参考,内容过长,分多贴回了

这个是根据C++头文件搞的一些枚举
C# code
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace HKH.Common.System.ComImports
{
    #region ActiveDesktop Enums

    //Defined in shlobj.h

    // Flags for IActiveDesktop::GetWallpaperOptions()
    //           IActiveDesktop::SetWallpaperOptions()
    public enum WallpaperStyle
    {
        Center = 0,
        Tile = 1,
        Stretch = 2,
        Max = 3
    }

    [Flags]
    internal enum ItemState
    {
        Normal = 0x00000001,
        FullScreen = 00000002,
        Split = 0x00000004,
        ValidSizeStateBits = Normal | Split | FullScreen,    // The set of IS_* state bits which define the "size" of the component - these bits are mutually exclusive.
        ValidStateBits = Normal | Split | FullScreen | unchecked((int)0x80000000) | 0x40000000    // All of the currently defined IS_* bits.
    }

    internal enum ComponentType
    {
        HtmlDoc = 0,
        Picture = 1,
        WebSite = 2,
        Control = 3,
        CFHtml = 4,
        Max = 4
    }

    //Flags for IActiveDesktop::AddDesktopItemWithUI()
    internal enum DeskTopItemAddWithUI
    {
        Default = 0x00000000,
        DisplaySubWizard = 0x00000001,
        PositionItem = 0x00000002,
    }

    // Flags for IActiveDesktop::ApplyChanges()
    [Flags]
    internal enum ActiveDesktopApply
    {
        Save = 0x00000001,
        HtmlGen = 0x00000002,
        Refresh = 0x00000004,
        All = Save | HtmlGen | Refresh,
        Force = 0x00000008,
        BufferedReferesh = 0x00000010,
        DynamicReferesh = 0x00000020
    }

    // Flags for IActiveDesktop::ModifyComponent()
    [Flags]
    internal enum ComponentElement
    {
        Type = 0x00000001,
        Checked = 0x00000002,
        Dirty = 0x00000004,
        NoScroll = 0x00000008,
        Left = 0x00000010,
        Top = 0x00000020,
        Width = 0x00000040,
        Height = 0x00000080,
        ZIndex = 0x00000100,
        Source = 0x00000200,
        FriendlyName = 0x00000400,
        SubscribedUrl = 0x00000800,
        OriginalCSI = 0x00001000,
        RestoredCSI = 0x00002000,
        CurrentItemState = 0x00004000,
        All = Type | Checked | Dirty | NoScroll | Left | Width | Height | ZIndex | Source | FriendlyName | Top |
            SubscribedUrl | OriginalCSI | RestoredCSI | CurrentItemState
    }

    // Flags for IActiveDesktop::AddUrl()
    [Flags]
    internal enum AddUrl
    {
        Silent = 0x0001
    }

    #endregion
}

------解决方案--------------------

这个是另个一些需要的结构
C# code
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace HKH.Common.System.ComImports
{
    #region ActiveDesktop Structs

    //Defined in shlobj.h

    internal struct WallpaperOption
    {
        public int Size;            // size of this Structure. 8 = Marshal.SizeOf(WallpaperOption)
        public WallpaperStyle Style;        // WPSTYLE_* mentioned above
    }

    internal struct ComponentOption
    {
        public int Size;            //Size of this structure, 12 = Marshal.SizeOf(ComponentOption)

        [MarshalAs(UnmanagedType.Bool)]
        public bool EnableComponents;        //Enable components?

        [MarshalAs(UnmanagedType.Bool)]
        public bool EnableActiveDesktop;    // Active desktop enabled ?
    }

    internal struct ComponentPosition
    {
        public const int COMPONENT_TOP = 0x3FFFFFFF;
        public const int COMPONENT_DEFAULT_LEFT = 0xFFFF;
        public const int COMPONENT_DEFAULT_TOP = 0xFFFF;

        public int Size;            //Size of this structure
        public int Left;            //Left of top-left corner in screen co-ordinates.
        public int Top;                //Top of top-left corner in screen co-ordinates.
        public int Width;            // Width in pixels.        
        public int Height;            // Height in pixels.
        public int ZIndex;            // Indicates the Z-order of the component.

        [MarshalAs(UnmanagedType.Bool)]
        public bool CanResize;            // Is the component resizeable?

        [MarshalAs(UnmanagedType.Bool)]
        public bool CanResizeX;            // Resizeable in X-direction?

        [MarshalAs(UnmanagedType.Bool)]
        public bool CanResizeY;            // Resizeable in Y-direction?

        public int PreferredLeftPercent;    //Left of top-left corner as percent of screen width
        public int PreferredTopPercent;        //Top of top-left corner as percent of screen height
    }

    internal struct ComponentStateInfo
    {
        public int Size;            // Size of this structure.
        public int Left;            // Left of the top-left corner in screen co-ordinates.
        public int Top;                // Top of top-left corner in screen co-ordinates.
        public int Width;            // Width in pixels.
        public int Height;            // Height in pixels.
        public ItemState ItemState;        // State of the component (full-screen mode or split-screen or normal state.
    }

    [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
    internal struct Component
    {
        private const int INTERNET_MAX_URL_LENGTH = 2084; // = 

        public int Size;            //Size of this structure
        public int ID;                //Reserved: Set it always to zero.
        public ComponentType iComponentType;    //One of COMP_TYPE_*

        [MarshalAs(UnmanagedType.Bool)]
        public bool Checked;            // Is this component enabled?

        [MarshalAs(UnmanagedType.Bool)]
        public bool Dirty;            // Had the component been modified and not yet saved to disk?

        [MarshalAs(UnmanagedType.Bool)]
        public bool NoScroll;            // Is the component scrollable?

        public ComponentPosition Position;    // Width, height etc.,

        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
        public string FriendlyName;        // Friendly name of component.

        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = INTERNET_MAX_URL_LENGTH)]
        public string Source;            //URL of the component.

        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = INTERNET_MAX_URL_LENGTH)]
        public string SubscribedURL;        //Subscrined URL

        //New fields are added below. Everything above here must exactly match the IE4COMPONENT Structure.
        public ItemState ItemState;        // Current state of the Component.
        public ComponentStateInfo OriginalCSI;    // Original state of the component when it was first added.
        public ComponentStateInfo RestoredCSI;    // Restored state of the component.
    }

    #endregion
}

文章评论

不懂技术不要对懂技术的人说这很容易实现
不懂技术不要对懂技术的人说这很容易实现
编程语言是女人
编程语言是女人
聊聊HTTPS和SSL/TLS协议
聊聊HTTPS和SSL/TLS协议
为什么程序员都是夜猫子
为什么程序员都是夜猫子
一个程序员的时间管理
一个程序员的时间管理
中美印日四国程序员比较
中美印日四国程序员比较
10个调试和排错的小建议
10个调试和排错的小建议
亲爱的项目经理,我恨你
亲爱的项目经理,我恨你
旅行,写作,编程
旅行,写作,编程
什么才是优秀的用户界面设计
什么才是优秀的用户界面设计
Java 与 .NET 的平台发展之争
Java 与 .NET 的平台发展之争
我跳槽是因为他们的显示器更大
我跳槽是因为他们的显示器更大
程序员和编码员之间的区别
程序员和编码员之间的区别
漫画:程序员的工作
漫画:程序员的工作
看13位CEO、创始人和高管如何提高工作效率
看13位CEO、创始人和高管如何提高工作效率
Web开发人员为什么越来越懒了?
Web开发人员为什么越来越懒了?
当下全球最炙手可热的八位少年创业者
当下全球最炙手可热的八位少年创业者
总结2014中国互联网十大段子
总结2014中国互联网十大段子
我的丈夫是个程序员
我的丈夫是个程序员
60个开发者不容错过的免费资源库
60个开发者不容错过的免费资源库
程序员必看的十大电影
程序员必看的十大电影
为啥Android手机总会越用越慢?
为啥Android手机总会越用越慢?
程序猿的崛起——Growth Hacker
程序猿的崛起——Growth Hacker
团队中“技术大拿”并非越多越好
团队中“技术大拿”并非越多越好
程序员周末都喜欢做什么?
程序员周末都喜欢做什么?
Web开发者需具备的8个好习惯
Web开发者需具备的8个好习惯
 程序员的样子
程序员的样子
那些争议最大的编程观点
那些争议最大的编程观点
程序员的一天:一寸光阴一寸金
程序员的一天:一寸光阴一寸金
科技史上最臭名昭著的13大罪犯
科技史上最臭名昭著的13大罪犯
写给自己也写给你 自己到底该何去何从
写给自己也写给你 自己到底该何去何从
“懒”出效率是程序员的美德
“懒”出效率是程序员的美德
十大编程算法助程序员走上高手之路
十大编程算法助程序员走上高手之路
做程序猿的老婆应该注意的一些事情
做程序猿的老婆应该注意的一些事情
如何区分一个程序员是“老手“还是“新手“?
如何区分一个程序员是“老手“还是“新手“?
Java程序员必看电影
Java程序员必看电影
代码女神横空出世
代码女神横空出世
如何成为一名黑客
如何成为一名黑客
5款最佳正则表达式编辑调试器
5款最佳正则表达式编辑调试器
“肮脏的”IT工作排行榜
“肮脏的”IT工作排行榜
老程序员的下场
老程序员的下场
每天工作4小时的程序员
每天工作4小时的程序员
初级 vs 高级开发者 哪个性价比更高?
初级 vs 高级开发者 哪个性价比更高?
我是如何打败拖延症的
我是如何打败拖延症的
10个帮程序员减压放松的网站
10个帮程序员减压放松的网站
软件开发程序错误异常ExceptionCopyright © 2009-2015 MyException 版权所有