Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Cards.Dll - Just For Fun
Message
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01473654
Message ID:
01473679
Views:
54
>I thought I'd try to use the Cards.Dll that ships with Windows to draw a card on a C# WinF/orm.
>
>The Object Explorer shows this method in Cards.DLL:
>
>
>cards.cardsdll.drawcard(System.IntPtr, int, int, int, int, int)
>
>
>So I wrote this:
>
>
>public class DeckOfCards
>{
>    [DllImport("cards.dll")]
>    private static extern bool drawcard(ref IntPtr handle, ref int top, ref int left, 
>           ref int width, ref int height, ref int card);
>
>    public DeckOfCards()
>    {
>    }
>
>    public bool DrawACard(IntPtr canvas, int top, int left, int width, int height, int card)
>    {
>        return drawcard(ref canvas, ref top, ref left, ref height, ref width, ref card);
>    }
>}
>
>
>Then I attempted to use it like this:
>
>
>public partial class Form1 : Form
>{
>    public Form1()
>    {
>        InitializeComponent();
>
>            DrawCard();
>    }
>
>    private void DrawCard()
>    {
>        DeckOfCards Deck = new DeckOfCards();
>
>        IntPtr hdc = this.Handle;
>
>        Deck.DrawACard(hdc, 10, 10, 100, 50, (int)Ranks.Five * 4 + (int)Suits.Clubs);
>
>    }
>}
>
>
>It dies in the DrawACard method of my class with "Unable to find an entry point named 'drawcard' in DLL "cards.dll'.
>
>As I have little to no experience working with COM in .Net (yet) I'm hoping someone can see what's wrong.

I don't think cards.dll has that method. Based on some old stuff I found try something like this:
    public class DeckOfCards
    {
        [DllImport("cards.dll")]
        private static extern bool cdtInit(ref int width, ref int height);

        [DllImport("cards.dll")]
        private static extern bool cdtDraw(IntPtr hdc, int x, int y, int card, int mode, long color);
        
        public DeckOfCards()
        {
            int width = 150; int height = 150;
            if (!cdtInit(ref width, ref height))
                throw new Exception("Could not initialize");
        }
 
        public bool DrawACard(IntPtr canvas, int left, int top, int card, int mode, long color)
        {
           return  cdtDraw(canvas, left, top,card, mode, color);
        }
    }
Also I don't think you can draw it using the handle. Try from the forms OnPaint():
new DeckOfCards().DrawACard(e.Graphics.GetHdc(), 10, 10, 16 ,1,207);
Of course in reality you wouldn't create an instance of DeckOfCards every time - just keep one hanging around somewhere.....
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform