Saturday, March 05, 2005

[Access Driver]Cannot open any more tables

I'm writing this app which reads heavilly from an access 'database'. all goes well, but after a large dataload, the odbc driver began throwing this message at me! how dare you, little woodpecker! ;)
i paniced at first and even began considering whether i should move to ADO.NET (the app is written in c#). i searched and searched the net (Google) and a note in a
message
got me startled - " ...and then close the statement object once the result set query has been accessed..." and this - "..You may also want to close the result set as you say after you are done with it...".
of course i close my datareaders and without this notion, but this constant repeating of "close this, close that" got me an idea - and then suddenly i noticed that OdbcCommand has a Dispose() method. and thats was it! after i close the datareader, now i also dispose of the odbccommand object and everything goes smoothly....

Tuesday, March 01, 2005

activex - save graphics to file

i'm writing an mfc activex control and want to save its visuals to a file. so how should i do this? the graphics on the control are created through GDI+, so should i go through Graphics contents to an Image, or may be through CDC?

so far i have this:

CDC* pdc = GetDC();

RECT rect;
GetClientRect(&rect);

Graphics graphics(pdc->GetSafeHdc());
Bitmap bitmap(rect.right -
rect.left, rect.bottom -
rect.top, &graphics);

CLSID pngClsid;
GetEncoderClsid(L"image/jpeg", &pngClsid);


bitmap.Save(fineName, &pngClsid, NULL);


but it just outputs a black screen, which is understandable

luckily my search led me to GdipCreateBitmapFromGraphics method and this post:
http://www.pscode.com/vb/scripts/ShowCode.asp?txtCodeId=37541&lngWId=1

where this guy - "Avery" - gives a great hint: it turns out creating the Image this way only gives a blank Image compatible with the Graphics object. to get the visuals all the graphics have to be done on a Graphics object derived from this Image. so i rewrote my drawing procedure to a function to be called with a Graphics object and depending on what i want - i would pass either the Graphics derived from the CDC in OnDraw, or the one needed for saving the image to a file... voila!