CBitmap causes Access Violation?


I have an application where the Document class has a 
CBitmap member variable. The member variable loads just 
fine, since I use it to draw to the view and it displays 
the bitmap image perfectly.

However, I need to be able to alter the bitmap bits. I 
have a menu item which calls my derived Document's member 
function AlterBmp();

The function is as follows:

(m_bitmap is my CBitmap object)


void CBMPTestDoc::AlterBmp()
	BITMAP bmp;
	m_bitmap.GetObject(sizeof(BITMAP), &bmp);

	BYTE* bmpBuf = (BYTE*)GlobalAlloc(GPTR, 
bmp.bmWidthBytes * bmp.bmHeight);

	m_bitmap.GetBitmapBits(bmp.bmWidthBytes * 
bmp.bmHeight, bmpBuf);
	for (int i=0; i< bmp.bmWidthBytes*bmp.bmHeight; 
		bmpBuf[i] >>= 3;

(bmp.bmWidthBytes*bmp.bmHeight, bmpBuf);



It should work. However, when m_bitmap.GetObject() is 
called, I get "Unhandled Exception in BMPTest.exe 
(MFC42D.DLL): 0xC0000005: Access Violation"

I tried some things, and it turns out that every member 
function of m_bitmap generates this error.

By the way, the code above has worked in another 
application: I created a HBITMAP handler, called 
LoadImage on it to load the bitmap from disk, used 
m_bitmap.Attach() to attach the handle to the bitmap, and 
then followed the code you see above.

That worked like a charm. My theory is that somehow, 
after the function in which the m_bitmap is Attached 
ends, something goes wrong with the CBitmap object? But 
if that's the case, how come my View's OnDraw still draws 
the bitmap?

Any ideas? Anybody?

For completeness, I'll just add the onDraw function too 
(which keeps working no matter what)


  // GetBitmap() returns a const reference to the m_bitmap
  // object. GetWidth and GetHeight simply return integers
 // stored earlier.

	CBMPTestDoc* pDoc = GetDocument();
	// TODO: add draw code for native data here

	CDC dcmem;

	pDC->BitBlt(0,0, GetDocument()->GetWidth(), 
GetDocument()->GetHeight(), &dcmem, 0,0, SRCCOPY);

7/19/2003 5:51:32 PM
vc.mfc 33608 articles. 0 followers. Follow

0 Replies

Similar Articles

[PageSpeed] 4


Similar Artilces:

Constructor for Attachment causing Sys.Webforms.PageRequestManagerServerErrorException
Okay, this seems odd to me but I've narrowed the source of the above error down to the following line of code: Dim att As New Attachment(attachment) Where attachment is a UNC path. If I comment that line of code out, the error goes away. Why does this work on my developement box but not on our test server? I've tried including the content type to no avail. Any help with this? using VS2008 on XP sp3 S P.S. This just happens to be on a page that has a couple of AJAX update panels on them and the error message box that pops up looks a bit AJAX like to me. ...

odd scroll bar behaviour in access, keeps returning to top
hi i have a user here, using ms office 2003, and he has noticed that when scrolling through ms access or excel, that often the vertical scroll bar he is using will return to the top position. this is the same for excel. its a bit of an issue, as he would be clicking through databases with thousands of rows of data, and it keeps retuning to the top of the row. i did notice that a program called ifinger kept popping up as this was happening. but i could not find info on the web linking this product with the issue he is having. if any one has any suggestions, id appreaciate it. Regards ...

snapshot in Access 2007
Hi have moved to Access 2007 and now I dont seem to be able to open or read any Snapshot format documents. has it been changed? thanks A I'm not seeing this problem. I saved a query with its properties set to Snapshot, and used it as the source for a report. The report opened as expected. Something else must be going on. -- Allen Browne - Microsoft MVP. Perth, Western Australia Tips for Access users - http://allenbrowne.com/tips.html Reply to group, rather than allenbrowne at mvps dot org. "Alexey" <alexdeletethisgates@hotmail.co.uk> wrote in message news:%236Z...

change the starting vaule for an autonumber field access 2007
how do I change the starting value for an autonumber field in access 2007 (...) > how do I change the starting value for an autonumber field in access 2007 DoCmd.RunSQL "alter table Table1 alter column ID counter(X,1)" X - starting value K.P. "Richard" wrote: > how do I change the starting value for an autonumber field in access 2007 How exactly do I do that? Where do I enter that line? Sorry for my ignorance! "Krzysztof Pozorek [MVP]" wrote: > (...) > > how do I change the starting value for an autonumber field in access 2007 > >...

Access 2003 to Email issue.
I have a working Access 2003 form that has a button to open a report and send a email. This makes the report an attachment in the email. The name of the report is placed in the document as the name of the attachment. I would like to add the "variable" EmployeeName so that it appears in the attachment name. Is this possible and if so where and how do I code it to have this happen? I used to be a mindreader, but those skills deteriorate with distance. Without seeing your code, that's hard to do. If you're handy with VBA, try using it to change the name of the attachment,...

How can I use my Access list to email selective groups?
How can I use an Access List to email selective groups without having to go to my Outlook Address Book? ...

access violation caused by cstring
We are working on a project where we need to migrate some code of an old application to a new application.The old app is an MFC app,which have some functions in the application class and document class which is required by the new app also.We created a dll project which is derived from the old app(Instead of directly deriving from CWinApp).So the hierarchy is as follows CWinApp<-Old app(COldApp)<-CNewDLLApp When the CNewDLLApp object is created(When LoadLibrary() is called),an access violation error is happening.It is caused in the constructor of COldApp where it is initialising a CStr...

Access Databases, MFC and VS2005
Okay. I'm going to try and ask this as succinctly as possible. When using an Access database in my apps, I've had to derive a recordset for each table. Before you laugh, consider that there are all of 3 tables in each, and each of those has less than 20 columns. My preferred way of using this techniques is to use the wizard to create a class derived from CRecordset and indicate the desired table in the dialogs. It works well but it's a lot of code, particularly if I want to do anything relational between tables. I have read and re re re read the MS docs, but I cannot seem to ...

Allow only one user to access workbook at a time
I need to set excel to allow only one user at a time to access a workbook. The workbook is NOT a shared workbook, but it resides on a network share. Multiple users need to access it, but only One at a time. I want all other users to get a message that the file is in use and they can not open it. Is this possible? I believe that is the standard behavior of a network file that is not shared; users who access the file when it is in use get a message the file is in use and whether they want to open as Read Only. -- Greeting from the Gulf Coast! http://myweb.cableone.net/twodays "Emir_of_sh...

Access--Form View & Print Preview Display
I have made a form in design view with a page setup of legal size, top, bottom and side margins of .4. I can see all the fields in design view, but when I "view" in Form, I only get the first page with 3/4 of the vertical page showing. I have all the fields showing in horizontal view. In Print Preview, I get only 3/4 of the first page. It will kick me to a second page, but nothing prints except the shaded box of the background. Will appreciate any suggestions. -- GEK ...

Configuring Domain Name for internal/external access
Well I sort of think i've got it right. Please comment on the following points: 1. I have created an internal domain name of "audor.org" the system has registered this as "remote.audor.org". 2. Our external domain name is www.acdorchester.org. 3. I now need to purchase a domain name of www.audor.org and point the A record to the fixed IP address ISP has given. This will allow external access for management and roaming staff. Please comment and advise on any changes necessary. I am not sure if I really need to purchase another one? -- happyhacker -...

Access 2003-Access 2002 Incompatibility
I updated an Access 2002 db using Access 2003. Now when I try to run the db on Access 2002 I get an error message that says: Access contains a missing or broken reference to file msador15.dll version 2.7 What can I do to fix this problem? Or more generally, what do I do to ensure that dbs created or modified with Access 2003 will still run on Access 2002? Thanks. Have MDAC 2.7 been installed on the machine that's attempting to use the database? -- Doug Steele, Microsoft Access MVP http://I.Am/DougSteele (no e-mails, please!) "Chaplain Doug" <anonymous@discussio...

access 2000 converting text to number format
a database in my office was created and the person who designed it put every field in a table as a text field. the numbers that are in those fields need to be change to a number to related to other tables. is there VB code or script to change it? or any other waY? Can you change the data type of the field to be Number? ...

2 personal folders causing Outlook to hang
Please help! I have got myself into difficulties with Outlook 2003. I imported data from Outlook on my previous PC that used Win2K. I now use XPProf. Somehow I have managed to create 2 personal folders within the email folder section of Outlook. I can't delete one as the Personal folder can't be deleted within Outlook. My Contacts, diary and other sections seem OK. The .pst file is about 280Mb. The program lets me look at my emails (with the preview pane off) but hangs on any email with an attachment. I have now uninstalled Outlook. I have the SP1 ready and WinSP2 to install....

Converting Access to MS SQL
I got a big Access file (1 400 tables) to convert to SQL and I would > like to be provided with some automated tools, except upsizing wizard > and DTS, to convert it on my own. > > I got a lot of forms and query to convert too. > > I analysed a tool suggested by Douglas last week, but it convert only the data, and not the froms and query. Can someday provide me with other tool name ? > > Thanks, > > Guy As I told you before, SQL Server doesn't have forms and queries in it: it's a database only. Therefore it's impossible to find a product that will co...

Extranet Configuration of project web access
I have installed Microsoft EPM with in two server installation. and now I need to configure extranet environment . but I am confused to understant host header , load balance url , alternate access mapping. I extended my web access site . but further what i need to do . then my site will be an accessible from anywhere. I am bit confused. although I study technet pages . but confused kindly tell me step by step. Kindly tell me the solution as soon as poosible. Regards Hello Sam. Hopefully this link will help explain some of those keywords and how you go about configuring ...

Access Deleting a Query SQL
Hi all, I am working with a multiple parameter search query. The form I am using to conduct the search displays the results in a subform. I have gone through and really combed through the SQL to make sure there are no blatant spelling errors or incorrect references within the code. Anyways when I open the form that it is attached to, I keep getting the boxes described in this website http://allenbrowne.com/bug-13.html .. The form is open, and I even changed names of fields in the table in case SQL was choosing to be picky about what I named my fields. Is there anything else that would cau...

Downloading Msgs From Outlook Web Access to Local HDD
Hey Everyone, I just got assaigned an email account for college next fall. Their method of checking email is Outlook Web Acess. I find this program extremly difficult to use and was wondering if it's possible to download the messeges from my account to my HDD using a program like Thunderbird or possibly Outlook Express? I tried connected via POP method- using mail.SCHOOL.edu as my incoming mail server and smtp.SCHOOL.edu as my outgoing mail server. Is it my school that is the problem or is it simply impossible to download msgs from Web Access? Thank You! -Oyster Outlook Web Access i...

Access 2003 Sorting Text
I am looking for a way to order text numbers - similar to a number list order in Word i.e. - 1,1.1, 1.2, 2, 2.1, 2.2, 3 ... etc. These are item numbers in a procedure list that I want to show on a form or report in 'text' order. The problem is that the sort order 'reads' 2.10 (two decimal ten) as equal to 2.1 (two decimal one). Is there a routine for handling this sort? Any help would be appreciated. Cheers, -- BRich am not sure this is the reply you are looking for....but it seems like the field is defined as a number - if it dropping that 0; but could/should be ...

user access deny
i forgot to say the error message in the internet when i was trying to login to the CRM server. It is "User access Error". Please help me, it is urgent case...... thanks Hi Jerry, Please double check if the user has a licence assigned and is member of a security group. I hope this helps, Ronald Lemmen Avanade Netherlands "jerry" wrote: > i forgot to say the error message in the internet when i was trying to login > to the CRM server. It is "User access Error". > Please help me, it is urgent case...... > > thanks ...

Convert to 97 Access Database
Hi Everyone, Have a quick question, I'm using MS Access 2007, not fully up to speed with it yet. In Access 2003 - you had an option to convert a database to a 97 Access DB >>Tools >>>>Convert Database >>>>>>Convert to 97 Access Database But I am unable to find this option in Access 2007? Any help, much appreciated Thanks Paul The option wasn't included in Access 2007. Remember that Access 97 is ten years older than Access 2007: is it realistic to expect a product to work with a 10 years old of the same product? -- Doug Steele, Microsoft ...

microsoft.public.access not subscribed group
microsoft.public.access not subscribed groupmicrosoft.public.access not subscribed groupmicrosoft.public.access not subscribed group ...

Problem Accessing Service Calendar & Knowledge Base
Hi, I'm having a problem accessing the service calendar & Knowledge Base. I have CRM version 3.0, I also recently reformatted my PC to a fresh install of XP Pro SP2. I has not worked on my PC since, however all the other users can acces these fine. I would appreciate some help. This problem can occur if you have the Outlook CRM client running. Try closing Outlook and all web browser windows, then opening the web browser and connecting to CRM. If this still doesn't work, try deleting all cookies on the machine -- David Jennaway - Microsoft Dynamics CRM MVP Web: http://...

Make an Access Database out of Excel spreadsheet
I have a spreadsheet with 5 tabs; all same info. How do I make a database with a form for entry of info from it? -- ahmebah ...

"collecting data via email from Access 2007"
Although it is supposed to work with any HTML mail recipient it only works if recipient is sending from Outlook. Has anyone else had success with recipients from Yahoo and Hotmail recipients? ...