DrawTransparentBitmap(CDC* pDC,CBitmap* pBitmap,
short xStart,short yStart,COLORREF cTransparentColor)
在c#中dllimport这个函数。类型应该怎么转换啊?
郁闷啊
short xStart,short yStart,COLORREF cTransparentColor)
在c#中dllimport这个函数。类型应该怎么转换啊?
郁闷啊
解决方案 »
- 关于excel导入access头疼的问题
- 如何禁止Visual Studio的ClickOnce功能?
- C# 下如何实现 IDocHostUIHandler::FilterDataObject
- 菜鸟问一个弱弱的问题:DataGridView中删除命令无效
- winform里的datagrid为什么没有“属性生成器”?
- 請教C#與LOTUS NOTES如何連接?
- web引用小问题
- crystal reports报表一定要放到crystalreportviewer中运行时预览吗?
- 高分求一个NHibernate模板,要求能生成实体类和Xml,包含一对多,多对多关系
- Datagrid中的换行问题?****小问题****
- 等你!!!TreeView导航?
- grideview 已经显示表了,为什么this.GridView1.Columns.Count的值是0?
别说C#用不了
VC自己用还有问题呢.
如果原型是这样的话C#还能用.
DrawTransparentBitmap(HDC hdc, HBITMAP hBitmap,short xStart,short yStart,COLORREF cTransparentColor)
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]
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;
}
}
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...不用编辑器写代码真的是错误好多......