Comment puis-je avoir 2 instances de la fonction DLL encore utilisez toujours les deux?

StackOverflow https://stackoverflow.com//questions/11685675

  •  12-12-2019
  •  | 
  •  

Question

    [DllImport("user32.dll")]
    public static extern int FindWindow(string lpClassName, string lpWindowName);
    [DllImport("user32.dll")]
    public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

Comme ça.J'ai besoin à la fois des deux.Si je vais pour INTPTR, il ne peut pas être converti en int proportivement si postmessage, etc. Stuff échoue, d'une autre manière, des choses qui nécessitent une "poignée" échouent, car c'est censé être pointé.

        Bitmap thisScreenshot = new Bitmap(Width, Height);
        Graphics gfxScreenshot = Graphics.FromImage(thisScreenshot);
        IntPtr hdcBitmap = gfxScreenshot.GetHdc();
        PrintWindow(handle, hdcBitmap, 0);
        gfxScreenshot.ReleaseHdc(hdcBitmap);

Je veux fondamentalement exécuter cela tout en ayant la fonction Int Findwindow.Des idées comment?aussi Findwindow est la poignée, non?

Était-ce utile?

La solution

Il n'est jamais correct d'utiliser la version qui renvoie int.FINDWINDOW retourne une poignée de fenêtre, c'est toujours IntPTR.Vous aurez besoin de corriger votre déclaration postmessage à la place:

[DllImport("user32.dll")]
public static extern bool PostMessage(IntPtr hWnd, int msg, IntPtr wp, IntPtr lp);

Autres conseils

Donnez à la fonction un nom différent et utilisez l'entréePoint pour spécifier le nom d'origine

[DllImport("user32.dll")]
public static extern int FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll", EntryPoint="FindWindow")]
public static extern IntPtr FindWindowA(string lpClassName, string lpWindowName);

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top