DrawTransparentBitmap(CDC*   pDC,CBitmap*   pBitmap,   
                                          short   xStart,short   yStart,COLORREF   cTransparentColor) 
在c#中dllimport这个函数。类型应该怎么转换啊?
郁闷啊

解决方案 »

  1.   

    像DrawTransparentBitmap(HDC hdc, HBITMAP hBitmap,...)还有办法。像你那样用MFC类,...还是放弃这个函数吧。
      

  2.   

    mfc类为什么不能用呢?没明白。。
      

  3.   

    用不了
    别说C#用不了
    VC自己用还有问题呢.
    如果原型是这样的话C#还能用.
    DrawTransparentBitmap(HDC hdc, HBITMAP hBitmap,short   xStart,short   yStart,COLORREF   cTransparentColor)
      

  4.   

    在C++里定义: 
    static CDC* GetDialogDC()
    {
      //for example:
      return theDC();
    }static CBitmap* GetBitmapPointer(LPCTSTR lpszBmpFileName)
    {
      //
    }
    在C++里,定义这两个函数的dllexport
    //
    在C#:
    [DllImprt("MyDll.dll"),EntryPoint="GetDialogDC",CharSet=CharSet.Auto]
    public external static void* GetDialogDC();
    //
    [DllImprt("MyDll.dll"),EntryPoint="GetBitmapPointer",CharSet=CharSet.Auto]
    public external static void* GetBitmapPointer(string lpszBmpFileName);
    //
    [DllImprt("MyDll.dll"),EntryPoint="GetDialogDC",CharSet=CharSet.Auto]
    public external static void DrawTransparentBitmap(void* pDC, void* pBitmap, short xStart, short yStart, uint cTransparentColor);
    //C# code:
    [code]
    unsafe void Test()
    {
      void* theDC = null;
      void* pBitmap = null;
      try
      {
      theDC = GetDialogDC();
      pBitmap = GetBitmapPointer(@"C:\bmp.bmp");
      if(theDC != null && pBitmap != null)
      {
        DrawTransparentBitmap(theDC, pBitmap, 0,0,0x12e4f1);
      }
      }
      catch(/*...*/Exception ex)
      {
        MessageBox.Show("Damn, I lost!");
      }
      finally
      {
        if(theDC != null)
          Marshal.FreeHGlobal((IntPtr)theDC);
        if(pBitmap != null)
          Marshal.FreeHGlobal((IntPtr)pBitmap);
        theDC = null;
        pBitmap = null;
      }
    }
    [/code]
      

  5.   

    [DllImprt("MyDll.dll"),EntryPoint="DrawTransparentBitmap",CharSet=CharSet.Auto] 
    public external static void DrawTransparentBitmap(void* pDC, void* pBitmap, short xStart, short yStart, uint cTransparentColor); 
     C# code:
    unsafe
    {
      void* theDC = null;
      void* theBitmap = null;
      try
    {
      theDC = GetDialogDC();
      theBitmap = GetBitmapPointer();
      if(theDC != null && theBitmap != null)
        DrawTransparentBitmap(theDC, theBitmap, 0,0,0x93e14f);
    }
    catch(/*...*/Exception ex)
    {
      int err = Marshal.GetLastWin32Error();
      if(err == something)
        MessageBox.Show("Error code = " + err);
    }
    finally
    {
      Marshal.FreeHGlobal((IntPtr)theDC);
      Marshal.FreeHGlobal((IntPtr)theBitmap);
      theDC = null;
      theBitmap = null;
    }
    }
      

  6.   

    [DllImprt("MyDll.dll"),EntryPoint="GetDialogDC",CharSet=CharSet.Auto] 
    unsafe public external static void* GetDialogDC(); 
    // 
    [DllImprt("MyDll.dll"),EntryPoint="GetBitmapPointer",CharSet=CharSet.Auto] 
    unsafe public external static void* GetBitmapPointer(string lpszBmpFileName); 
    // 
    [DllImprt("MyDll.dll"),EntryPoint="DrawTransparentBitmap",CharSet=CharSet.Auto] 
    unsafe public external static void DrawTransparentBitmap(void* pDC, void* pBitmap, short xStart, short yStart, uint cTransparentColor); Damn...不用编辑器写代码真的是错误好多......