
#include"b.c"

struct ss1{BITMAPINFOHEADER bmiHeader;
           RGBQUAD          bmiColors[256];};
struct ss2{ char b;
            char m;
            long fs;
            char d1,d2,d3,d4,d5,d6,d7,d8; };

char outpath[200]="";


//long __stdcall sdllinit(char path[200])
//{   long k;
//  k=dllsetpath(path);
//  return k;
//}



long __stdcall sdllisinit()
{ if(dpath[0]==0) return -1;
  else            return  1;
}

long __stdcall sdllinit(char path[200], char opath[200])
{   long k;
  k=dllsetpath(path);
  strcpy(outpath,opath);
  return k;
}



//long __stdcall sdllfree()
//{ ; }



long __stdcall sdlldraw(long kdc, long xb, long yb, long ww, long hh,double cs,
                        char nmfg[10])
{   long k;
  k=dlldraw(kdc,xb,yb,ww,hh,cs,nmfg);
  return k;
}


long __stdcall sdllgetbmp(char *kbuf)
{
   struct ss1 binfo;
   struct ss2 h;
   HDC        hdcmem;
   HBITMAP    hb,hbold;
   FILE       *fff;
   long       k;

  hdcmem=CreateCompatibleDC(hdc);
  hb=CreateCompatibleBitmap(hdc,wmax,hmax);
  hbold=SelectObject(hdcmem,hb);

  BitBlt(hdcmem,0,0,wmax,hmax,hdc,0,0,SRCCOPY);

binfo.bmiHeader.biSizeImage=wmax*hmax;

  binfo.bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
  binfo.bmiHeader.biWidth=wmax;
  binfo.bmiHeader.biHeight=hmax;
  binfo.bmiHeader.biPlanes=1;
  binfo.bmiHeader.biBitCount=8;
  //binfo.bmiHeader.biCompression=BI_RGB;
  binfo.bmiHeader.biCompression=BI_RLE8;

  k=GetDIBits(hdcmem,hb,0,hmax,kbuf+1078,&binfo,DIB_RGB_COLORS);
  h.b='B';
  h.m='M';
  h.fs=1078+binfo.bmiHeader.biSizeImage;
  h.d1=0; h.d2=0; h.d3=0; h.d4=0;
  h.d5=54;h.d6=4; h.d7=0; h.d8=0;
  memcpy(kbuf,   &h,14);
  memcpy(kbuf+14,&binfo,40+1024);


  SelectObject(hdcmem,hbold);
  DeleteObject(hb);
  DeleteDC(hdcmem);

/*
  fff=fopen("c:\\a.bmp","wb");
    fwrite(kbuf,1,1078+binfo.bmiHeader.biSizeImage,fff);
  fclose(fff);
*/

  return binfo.bmiHeader.biSizeImage;
}




long __stdcall sdllgetimgfile(char ofnm[200])
{
   struct ss1 binfo;
   struct ss2 h;
   HDC        hdcmem;
   HBITMAP    hb,hbold;
   FILE       *fff;
   long       k;

  hdcmem=CreateCompatibleDC(hdc);
  hb=CreateCompatibleBitmap(hdc,wmax,hmax);
  hbold=SelectObject(hdcmem,hb);

  BitBlt(hdcmem,0,0,wmax,hmax,hdc,0,0,SRCCOPY);

binfo.bmiHeader.biSizeImage=wmax*hmax;

  binfo.bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
  binfo.bmiHeader.biWidth=wmax;
  binfo.bmiHeader.biHeight=hmax;
  binfo.bmiHeader.biPlanes=1;
  binfo.bmiHeader.biBitCount=8;
  //binfo.bmiHeader.biCompression=BI_RGB;
  binfo.bmiHeader.biCompression=BI_RLE8;

  k=GetDIBits(hdcmem,hb,0,hmax,buf+1078,&binfo,DIB_RGB_COLORS);
  h.b='B';
  h.m='M';
  h.fs=1078+binfo.bmiHeader.biSizeImage;
  h.d1=0; h.d2=0; h.d3=0; h.d4=0;
  h.d5=54;h.d6=4; h.d7=0; h.d8=0;
  memcpy(buf,   &h,14);
  memcpy(buf+14,&binfo,40+1024);

  SelectObject(hdcmem,hbold);
  DeleteObject(hb);
  DeleteDC(hdcmem);

  GetTempFileName(outpath,"rle",0,ofnm);
  fff=fopen(ofnm,"wb");
    fwrite(buf,1,1078+binfo.bmiHeader.biSizeImage,fff);
  fclose(fff);

  return binfo.bmiHeader.biSizeImage;
}




/*
  hdc=CreateDC("DISPLAY",NULL,NULL,NULL);
  hdcmem=CreateCompatibleDC(hdc);
  hb=CreateCompatibleBitmap(hdc,nx,ny);
  pen0=CreatePen(PS_SOLID,0,RGB(0,255,0));
  pen1=CreatePen(PS_SOLID,2,RGB(0,128,0));
  old=SelectObject(hdcmem,pen1);
  SelectObject(hdcmem,hb);
  ..........
  GetDIBits(hdcmem,hb,0,ny,c,&binfo,DIB_RGB_COLORS);

*/
