|
Hi everyone.
Recently I've began to study WTL programming and I 've got a question. Please explain me how can I create a colour bitmap from array of bits? Not colour bitmap I create like this:
HBITMAP btmp;
LPBITMAPINFO pbi;
LPBITMAPINFOHEADER pbmph;
bool CDisplay::initBmp(byte* Img)
{
if(pbi != NULL)
delete [] pbi;
if(btmp != NULL)
DeleteObject(btmp);
int headerSize = sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * 256;
try
{
pbi = (LPBITMAPINFO)new char [headerSize];
pbmph = &(pbi->bmiHeader);
memset(pbmph, 0, headerSize);
pbmph->biSize = sizeof(BITMAPINFOHEADER);
pbmph->biPlanes = 1;
pbmph->biCompression = BI_RGB;
pbmph->biClrUsed = 256;
pbmph->biClrImportant = 256;
pbmph->biBitCount = 8;
// fill RGBQUAD
LPRGBQUAD pRGBQ = (LPRGBQUAD)((LPSTR)pbmph + pbmph->biSize);
for( int i = 0; i < 256; i++ )
{
pRGBQ[i].rgbBlue =
pRGBQ[i].rgbGreen =
pRGBQ[i].rgbRed = i;
}
}
catch(...)
{
return false;
}
pbmph->biWidth = MaxX[0];
pbmph->biHeight = MaxY[0];
pbmph->biSizeImage = MaxX[0]*MaxY[0];
btmp = CreateDIBitmap(GetDC(), pbmph, CBM_INIT, Img, pbi, DIB_RGB_COLORS);
return true;
}
How create colour bitmap?
P.S.: Sorry for my english if I wrote with errors.
Nulla dies sine linea !!!
|
|
|
|
|
You might want to look at CreateDIBSection. This is similar to what you already have (it will return a HBITMAP handle and a pointer to the bits). You can directly modify the bits via that pointer and use the handle for selecting the object into DCs.
If you simply want to create a 24-bit colour image, you don't need to create palette information in the BITMAPINFOHEADER (set those values to 0). Then simply write an RGB TRIPLE (Blue, Green, Red) for each pixel using the pointer. Remember you will need to pad each scanline to the DWORD boundary. If you want to write a 256-colour (paletted) image, you will need to provide a colour table. Check out MSDN documentation for that information.
Another gotcha is that if you want the bitmap to be "top-down" i.e. pixel (0,0) is in the top-left corner, you must specify a NEGATIVE height value in the BITMAPINFOHEADER structure.
Hope that helps
|
|
|
|
|
TNX, That helped me.
I did it.
Nulla dies sine linea !!!
|
|
|
|
|
Hi,
I am trying to use a COM component in MFC client app. I call one Method of a this component but it throws and error with HRESULT as 0x80020008. The error code I verified corresponds to FACILITY_DISPATCH and DISP_E_BADVARTYPE.
The problem is - it works on another machine but not on my machine. Also, I am using TLH, TLI file generated for this component using #import directive.
Please provide me with some solution to this.
Thanks in advance.
Have a great day ahead!
Regards,
Sohail Kadiwala
(My Blog - http://blogs.wdevs.com/sohail/[^])
modified 21-Apr-21 21:01pm.
|
|
|
|
|
Difficult for saying without further info. But from the description I think, that you're passing some VARIANT parameter into the function, or the function expects it. (or some other VARIANT conversion takes place on the way).
Then for the problem one-machine-works-other-not I would check the values passed to the function (or possibly it can be also some operation inside the COM object) for some regional setting specific parts - number with decimal dot, dates... If you pass e.g. a number 1.2 as a VARIANT type string (VT_BSTR ) on some machines it can be a working construct, because they know that decimal dot is a separator and then can safely convert it to required number. On other machine, where is comma set as separator, the conversion can fail.
But these are just thoughts, without more details it's difficult to tell what can be wrong.
|
|
|
|
|
Hi geo
Thanks for information. Look I am not passing anything myself. The Method got absoluetly no [IN] parameter.
Also I said in my post that I am using TLH and TLI files and these are generated using #import "component.dll"
Even I have only limited information.
If possible try giving me some info regarding this error. Also, I don't have source of the Component
Have a great day ahead!
Regards,
Sohail Kadiwala
(My Blog - http://blogs.wdevs.com/sohail/[^])
modified 21-Apr-21 21:01pm.
|
|
|
|
|
Hmm, that would be quite difficult to debug - I would check, if there is difference between these two machines in regional settings (for user as well as for the system). Also take into account what the method call have to do (can help to focus a bit - if it should work with date/time or numbers or whatever).
Also possibility is that it calls internally some other component and on one machine is different version that on the other one.
Anyway, if there's no support neither source code for the component, I would think about dumping it and trying to find/develop somethin what does the same job but more reliable, because now, you can spend some few days with locating the bug and tomorrow at client's site there can be other problems similar or worse than this one.
|
|
|
|
|
Thanks Geo,
I'll take a look at things you have mentioned. Also the ReDesigning stuff
Have a great day ahead!
Regards,
Sohail Kadiwala
(My Blog - http://blogs.wdevs.com/sohail/[^])
modified 21-Apr-21 21:01pm.
|
|
|
|
|
I found many examples about DirectoryWatch, FileWatch. I need help regarding the moment of closing of the file. Suppose some operation on the file is going on by some application. I want to add some information at the end of the file but immediately after it is closed by the application. So my application must be able to trace the closing of the file.
Moyeen
Sr. Software Design Engineer
|
|
|
|
|
look @ ReadDirectoryChangesW with FILE_NOTIFY_CHANGE_LAST_WRITE flag set. This is the nearest option I can imagine to help you quite easily.
Problem is that closing the file handle can mean nothing for the underlying filesystem in some situations, and I don't know any API that would allow you go as deep as to file locking mechanism that CAN be influenced by simple file closing (not saying that the behavior of such a functions can be different for NTFS or FAT32 or network drive)
Maybe you can track the file handles directly, but this will need a great experience in low level system programming (although nothing impossible I think) but it can also cause bugs in other applications, because you have to dig in other processes.
|
|
|
|
|
hi all,
As I understood it vectors are bound safe, i.e. you can't go past the end of the vector. However I've found some code which does just that!
the vector is defined as an "vector < vector < int > >" and although when you try to access an out of bound area on the first part you get an error, if you do the same on the second part it allows you. An example is if the first vector has 10 elements (i.e. 10 x vector < int > ) and the second part has 10 elements (i.e. 10 x int). If you do "myVector[i][j] = 6 ;" where i=20 and j=5 then you get a crash, whereas if i=5 and j=20 you don't!
Can anyone tell me if this is standard behaviour or could it be a compiler 'feature' (I'm using MS VC++ 6.0 with (iirc) SP5).
cheers,
Andy
|
|
|
|
|
You must access the vector elements using the at() member function to get bounds checking. Using the [] operator to access out of bounds elements causes undefined behavior.
|
|
|
|
|
Also keep in mind that at() throws on failure. Good to know in beforehand
--
Weiter, weiter, ins verderben.
Wir müssen leben bis wir sterben.
I blog too now[^]
|
|
|
|
|
Can anyone tell how to pass an array from an avent in case of ATL COM DLL.Awaiting for respense eagerly.Plz respond as soon as possible.
Akshay Dave
|
|
|
|
|
use SAFEARRAY
see in MSDN CreateSafeArray and related functions
|
|
|
|
|
Hi Akshay ,
i just adding to real Monkey advice,
just declare the return element VARIANT, and using SAFEARRAY return an array to Client.
-----------------------------
"I Think It Will Help"
-----------------------------
Alok Gupta
visit me at http://www.thisisalok.tk
|
|
|
|
|
Hi Alok,Thanx 4 ur reply.I had tried out 4 what u have suggested.But I think I'm not able to implement VARAINT SAFEARRAY it is giving warning in Proxy file it generates 4 event.It says"Forcing a tagSafeArray value to Bool true
or false".Plz reply me with some codes of VB and Vc if possible.My email-id is avd9683@rediffmail.com.
Awaiting 4 ur reply soon.
AKshay Dave
|
|
|
|
|
Hi Alok, I am in very much need of Safearray related concepts and methodologies because I need much use of it too pass large values from COM Dll to VB in meterological projects and M/c related projects.Plz send me some codes and some URL where I can get get proper conceptual knowledge of SAFEARRAY with code.I'm currently facing difficulty in Passing SAFEARRAY from ATL/COM DLL to VB in an Event.So please help me.I am a memeber of this group by name Akshay Dave.My mail id is avd9683@rediffmail.com,
akshayd@eqqu.com.
Awaiting eagerly 4 ur reply.
Akshay Dave
Akshay Dave
|
|
|
|
|
Sorry Askhay,
i too never used Safarray in Events,ijust read similar comment on any other forum about this. which is working fine.
i think you can brush your knowledge about SAFEARRAY from Inside Atl book.
-----------------------------
"I Think It Will Help"
-----------------------------
Alok Gupta
visit me at http://www.thisisalok.tk
|
|
|
|
|
Hi all,
sorry for this basic question...
I've got a std::list<myclass*> mlist and want to erase several elements.
I thought mlist.erase(iter) deletes the element pointed to by iter.
As this is a pointer, only the pointer should be erased, but the destructor of myclass is also called... Is this the desired behaviour?
Btw. how can I delete only the pointer but not the instance of my class?
I'm using the stl_eVC port for PocketPC
Thanks alot
Stefan
|
|
|
|
|
(Next time, please tick on the "Do not treat <'s as HTML tags" checkbox so that brackets show in your message.)
I've got a std::list<myclass*> mlist and want to erase several elements.
I thought mlist.erase(iter) deletes the element pointed to by iter.
As this is a pointer, only the pointer should be erased, but the destructor of myclass is also called... Is this the desired behaviour?
You should misinterpreting the behavior of your program, since mlist.erase(iter) will only erase the element and not destroy the object pointed to. Are you 100% sure the object is being destroyed, too?
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
Want a Boost forum in Code Project? Vote here[^]!
|
|
|
|
|
Thanks.
I've found the problem... I continued to use iter after erase (which was invalid) and didn't know that erase returns the next element...
Stefan
|
|
|
|
|
Hi,
I'm working on a web service programmed with ATL Server templates and classes. This web service is under testing in a Windows 2000 Server, IIS 5. It's running with high (isolated) application protection (so a new DLLHOST process appears when I make a request to my web service). I've noticed (using Process Explorer) that when an unhandled exception raises, Windows kills all my components in the DLLHOST process, but doesn't kill the DLLHOST process itself (of course, the user owned one, not the system DLLHOST). I just want to know why it behaves like that. Is it not supposed to kill the whole process that produces an unhandled exception?
Thanks,
Federico
|
|
|
|
|
Hi
I am implementing a data structure to insert ( 50000 - 100000 items )and retrive in First in First Out ( FIFO ) order.
Please suggest me which one is the fastest
QUEUE , STACK , LIST , MAP , MULTIMAP or any other
Thanks
Sandeep Naik
|
|
|
|
|
A deque (check the manual) is an ideal structure for this, as insertions and deletions at both ends of the sequence are very efficient (constant time, basically.)
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
Want a Boost forum in Code Project? Vote here[^]!
|
|
|
|