Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Cards.Dll - Just For Fun
Message
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Divers
Thread ID:
01473654
Message ID:
01474188
Vues:
42
Ok, something's wrong.

When I do this:
public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    protected override void OnPaint(PaintEventArgs e)
    {
        new DeckOfCards().DrawACard(e.Graphics.GetHdc(), 10, 10, 21, 1, 255);
    }
}
I get a big red X the size of the form with a red border around it.

When I do this:
public partial class Form1 : Form
{
    DeckOfCards Deck = null;

    public Form1()
    {
        InitializeComponent();
        Deck = new DeckOfCards();
    }

    protected override void OnPaint(PaintEventArgs e)
    {
        Deck.DrawACard(e.Graphics.GetHdc(), 10, 10, 21, 1, 255);
    }
}
I get an exception in Deck's CTOR "Unable to find an entry point named 'cdtInit' in DLL 'cards.dll'.".

Any idea what's wrong?






>>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.....
Everything makes sense in someone's mind
public class SystemCrasher :ICrashable
In addition, an integer field is not for irrational people
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform