CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
可用分押宝游戏火热进行中... 专题改版:Java Web 专题
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  VC/MFC >  基础类

dll的问题

楼主thisisll(学习王高李,有个好身体)2005-04-04 18:11:09 在 VC/MFC / 基础类 提问

没写过dll,照葫芦画瓢写了一个  
  能编译  
  不过就是用不成  
  大家给看看有啥毛病没,谢谢  
   
  这个是.h  
   
  #if   !defined(AFX_MYISM_H__5BFD6F06_84D9_4163_BE7A_169389502846__INCLUDED_)  
  #define   AFX_MYISM_H__5BFD6F06_84D9_4163_BE7A_169389502846__INCLUDED_  
   
  #define   BMP_API   __declspec(dllexport)    
   
  #ifdef   _cplusplus  
  #ifndef   __AFXWIN_H__  
  #error   include   'stdafx.h'   before   including   this   file   for   PCH  
  #endif  
   
   
  extern   "C"   {  
  #endif  
  BMP_API   BOOL   LoadBmp(CString   sPath,BYTE*   pBmpFile);  
  BMP_API   BOOL   ShowBmp(CDC*   pDC,BYTE*   pBmpFile);  
  BMP_API   int   PixeltoOffset(CPoint   point,int   widthbit,int   nHeight);  
  BMP_API   BOOL   DrawLine(CPoint   a,CPoint   b,BYTE*   pBmpFile);  
  BMP_API   BOOL   SaveBmp(CString   sPath,BYTE*   pBmpFile);  
   
  #ifdef   _cplusplus  
  }  
  #endif  
   
  #endif  
   
   
  这个是.cpp  
  //   MyBmpDll.cpp   :   Defines   the   entry   point   for   the   DLL   application.  
  //  
   
  #include   "stdafx.h"  
  #include   "MyBmpDll.h"  
   
  #ifdef   _DEBUG  
  #define   new   DEBUG_NEW  
  #undef   THIS_FILE  
  static   char   THIS_FILE[]   =   __FILE__;  
  #endif  
   
   
  BMP_API   BOOL   LoadBmp(CString   sPath,BYTE*   pBmpFile)  
  {  
  CFile   BmpFile;  
  if(!BmpFile.Open(sPath,CFile::modeRead,NULL))  
  {  
  AfxMessageBox("can't   open   the   file");  
  return   false;  
  }  
  int   nsize;  
  nsize=BmpFile.GetLength();  
  pBmpFile=new   BYTE[nsize];  
  BmpFile.Seek(0,CFile::begin);  
  BmpFile.Read(pBmpFile,nsize);  
  BmpFile.Close();  
  return   true;  
  }  
   
  BMP_API   BOOL   ShowBmp(CDC*   pDC,BYTE*   pBmpFile)  
  {  
  if(pBmpFile==NULL)  
  return   false;  
  BYTE*   pBmp=&pBmpFile[54];  
  int   nWidth,nHeight;  
  BITMAPINFOHEADER   *bmpinfo=(BITMAPINFOHEADER*)&pBmpFile[14];  
  int   bitcount=(int)bmpinfo->biBitCount;  
  if(bitcount!=24)  
  {  
  AfxMessageBox("it   can   only   open   24   bit   bmp");  
  return   false;  
  }  
  nWidth=bmpinfo->biWidth;  
  nHeight=bmpinfo->biHeight;  
  BYTE*   pBuf,*   ptmp;  
  pBuf=pBmp;  
  int   widthbit=(4-nWidth*3%4)+nWidth*3;  
  for(int   i=0;i<nHeight;i++)  
  {  
  pBuf=pBmp+widthbit*i;  
  for(int   j=0;j<nWidth*3;j+=3)  
  {  
  ptmp=&pBuf[j];  
  CPoint   point;  
  point.x=j/3;  
  point.y=nWidth-i;  
  pDC->SetPixel(point,RGB(ptmp[2],ptmp[1],ptmp[0]));  
  }  
  }  
  return   true;  
  }  
   
  BMP_API   int   PixeltoOffset(CPoint   point,int   widthbit,int   nHeight)  
  {  
  int   x;  
  x=point.x*3+widthbit*(nHeight-point.y);  
  return   x;  
  }  
   
  BMP_API   BOOL   DrawLine(CPoint   a,CPoint   b,BYTE*   pBmpFile)  
  {  
  if(pBmpFile==NULL)  
  return   false;  
  BYTE*   pBmp=&pBmpFile[54];  
  int   nWidth,nHeight;  
  BITMAPINFOHEADER   *bmpinfo=(BITMAPINFOHEADER*)&pBmpFile[14];  
  nWidth=bmpinfo->biWidth;  
  nHeight=bmpinfo->biHeight;  
  int   widthbit=(4-nWidth*3%4)+nWidth*3;  
  int   Minx,Maxy;  
  if(b.x>a.x)  
  Minx=a.x;  
  else   Minx=b.x;  
  if(b.y>a.y)  
  Maxy=b.y;  
  else   Maxy=a.y;  
  float   tg=float(b.x-a.x)/float(b.y-a.y);  
  int   x,y;  
  for(int   i=0;i<abs(b.x-a.x);i++)  
  {  
  x=Minx+i;  
  y=abs(x/tg);  
  CPoint   point;  
  point.x=x;  
  point.y=y;  
  int   j=PixeltoOffset(point,widthbit,nHeight);  
  pBmpFile[j]=0;  
  pBmpFile[j+1]=0;  
  pBmpFile[j+2]=0;  
  }  
  return   true;  
  }  
   
  BMP_API   BOOL   SaveBmp(CString   sPath,BYTE*   pBmpFile)    
  {  
  CFile   BmpFile(sPath,CFile::modeWrite);  
  BITMAPFILEHEADER*   bf=(BITMAPFILEHEADER*)   pBmpFile;  
  int   nsize=bf->bfSize;  
  BmpFile.Write(pBmpFile,nsize);  
  BmpFile.Flush();  
  BmpFile.Close();  
  return   true;  
  }  
   
   
  函数里面应该没什么问题  
  调用的时候我是  
  typedef   BOOL(_cdecl   *Connect)(CString   sPath,BYTE*   pBmpFile);  
  HINSTANCE   hinstDLL=NULL;    
  hinstDLL=LoadLibrary("MyBmpDll.dll");  
  if   (hinstDLL)  
  {  
  Connect   Proc;  
  Proc   =   (Connect)GetProcAddress   (hinstDLL,"LoadBmp");  
  if(Proc==NULL)  
  {  
  AfxMessageBox("can't   find   proc");  
  return;  
  }  
  if(!Proc(sPath,pBmpFile))  
  return;  
  FreeLibrary(hinstDLL);  
   
  }  
  else  
  {  
  AfxMessageBox("can't   find   dll");  
    } 问题点数:100、回复次数:10Top

1 楼fvan(RainVan)回复于 2005-04-04 18:29:13 得分 20

标准的Dll的话,建议不要有类进行参数传递(更不要做为返回值),如上述的CStringTop

2 楼oyljerry(【勇敢的心】→ ㊣提拉米苏√㊣)回复于 2005-04-04 18:33:05 得分 20

extern   C   和_cdecl   函数调用约定要一致Top

3 楼surstar(我要写个操作系统出来……)回复于 2005-04-04 18:35:26 得分 10

我比你还菜啦~Top

4 楼thisisll(学习王高李,有个好身体)回复于 2005-04-05 08:04:32 得分 0

to     oyljerry(【勇敢的心】→   ㊣Warm   up,A   za!㊣)    
  extern   C   和_cdecl   函数调用约定要一致  
   
  具体的怎么一致?Top

5 楼thisisll(学习王高李,有个好身体)回复于 2005-04-05 08:31:13 得分 0

upTop

6 楼DentistryDoctor(Data Recovery -- http://www.powerdatarecovery.com)回复于 2005-04-05 09:00:46 得分 10

Windows核心编程?Top

7 楼thisisll(学习王高李,有个好身体)回复于 2005-04-05 09:13:51 得分 0

不是  
  是我老师给我的  
  让我看着做  
  -----------------------  
  又出现了新状况  
   
  我加了一个.def  
  现在可以调用了  
  可是传递不了指针  
  Top

8 楼slience(疏星朗月)回复于 2005-04-05 09:22:10 得分 20

typedef   BOOL(__stdcall   *Connect)(CString   sPath,BYTE*   pBmpFile);Top

9 楼sjcode(愚者)回复于 2005-04-05 10:09:32 得分 20

你这样,到不如用隐式加载的方式处理MFC   DLL了。  
   
  只要加AFX_EXT_CLASS就可以了。Top

10 楼thisisll(学习王高李,有个好身体)回复于 2005-04-05 13:49:39 得分 0

自己搞定了  
  还是谢谢大家  
  我就把分散给大家了Top

相关问题

  • DLL
  • DLL?
  • dll
  • DLL
  • *.dll
  • dll?
  • (.dll)
  • dll is 》》》----------------------------------------->
  • DLL
  • dll

关键词

  • 函数
  • api
  • dll
  • pbmpfile
  • widthbit
  • mybmpdll
  • cpoint
  • hinstdll
  • 调用
  • nheight

得分解答快速导航

  • 帖主:thisisll
  • fvan
  • oyljerry
  • surstar
  • DentistryDoctor
  • slience
  • sjcode

相关链接

  • Visual C++类图书
  • Visual C++类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
世纪乐知(北京)网络技术有限公司 版权所有, 京 ICP 证 020026 号
北京创新乐知广告有限公司 提供技术支持
Copyright © 2000-2007, CSDN.NET, All Rights Reserved
GongshangLogo