slower BitBlt from unmanaged mem into C# hDC than old VB6

BitBlt'ing from unmanaged memory into an hDC obtained in a managed
(C#) program takes 50-100% longer than the same BitBlt into an hDC
obtained in an unmanaged (old VB6) program.

My ShowPic() function resides in a DLL written in straight C.
It reads a JPEG into memory allocated within the unmanaged DLL and
then StretchDIBits()s it to the hDC passed.

Some ancient VB6 code called it in a Paint event:

Private Sub Picture1_Paint()
    ShowPic(Picture1.hdc, ...)
End Sub

Here is the C# code that is almost 100% slower:

private void picObj1_Paint(object sender,
System.Windows.Forms.PaintEventArgs e)
{
    Graphics gfx = e.Graphics;
    IntPtr pTarget = gfx.GetHdc();
    ShowPic(pTarget, ...);
    gfx.ReleaseHdc(pTarget);
}

I simplified the example code above but would be glad to provide more
detail.

WHAT IS SLOWING IT DOWN... and how can I speed it back up?

0
StevO
1/25/2010 11:55:15 PM
dotnet.languages.csharp 1931 articles. 0 followers. Follow

1 Replies
537 Views

Similar Articles

[PageSpeed] 43

StevO wrote:
> [...]
> Here is the C# code that is almost 100% slower:
> 
> private void picObj1_Paint(object sender,
> System.Windows.Forms.PaintEventArgs e)
> {
>     Graphics gfx = e.Graphics;
>     IntPtr pTarget = gfx.GetHdc();
>     ShowPic(pTarget, ...);
>     gfx.ReleaseHdc(pTarget);
> }
> 
> I simplified the example code above but would be glad to provide more
> detail.
> 
> WHAT IS SLOWING IT DOWN... and how can I speed it back up?

It could easily be the interop overhead, which involves marshaling of 
data types that AFAIK would not be required in the VB6 program.  There 
also is the question of retrieving the DC.  Not that I'd expect that to 
be _very_ slow, but there may be subtle differences between getting the 
DC in your VB6 code (especially if that's an "owner DC"�one created 
permanently for the window) as compared to retrieving the DC from the 
Graphics instance.

But yes, a concise-but-complete code example would be required for any 
specific statements to be made about what's actually slowing things down.

Pete
0
Peter
1/26/2010 8:48:30 AM
Reply:

Similar Artilces:

Printing getting slower and slower
I have an epson TIII88 and when I first set everything up it was zippy. Now when a transaction completes it takes about 15 seconds for the printer to get the job. The pc it self is in good shape. Any ideas? hi Jho, make sure one thing. go to Register Properties then click on the Cash Drawer 1. and see if you have put the "Wait for drawer to close" and in timeout it should be 0 if you have entered soemthing this might also casue the issue. "jho" wrote: > I have an epson TIII88 and when I first set everything up it was zippy. Now > when a transaction completes ...

(C)
Does anyone know of a permanent fix (cell formatting or otherwise) to make (C) not appear as the copyright symbol © when entered into a cell? A temporary fix is to enter ('C') or ( C ), then tab out of cell and then delete the spaces or single quotes. -- Jim Schmidt Jim, Go to the Tools menu, choose AutoCorrect Options, and delete the entry that changes (c) to the copyright symbol. It is typically the first entry in the list. -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting, LLC www.cpearson.com "Jim Schmidt" <JimSchmidt@discussi...

Replace old data
I'm working on a simple program that enabled the user to Search and Edit the data. The user has 2 options whether to save the data as a new record or to replace the existing data. I managed to get the job done for the user to SAVE AS NEW RECORD by using this coding : ActiveCell.Value = txtSpecificationNo.Value ActiveCell.Offset(0, 1) = txtIssueNo.Value ActiveCell.Offset(0, 2) = lblPly1.Caption ActiveCell.Offset(0, 3) = txtQtyPly.Value ActiveCell.Offset(0, 4) = txtCodePly.Value ActiveCell.Offset(0, 5) = txtLengthPly.Value ActiveCell.Offset(0, 6) = txtWidthPly.Value ActiveCell.Offset(0, 7)...

Problem in BitBlt Function
Code for the program is : #include "StdAfx.h" #include "resource.h" #include ".\chidmenu.h" #define mnuHeight 24 #define mnuWidth 163 CChidMenu::CChidMenu(void) { } CChidMenu::~CChidMenu(void) { } void CChidMenu ::DrawItem (LPDRAWITEMSTRUCT lpDIS) { if(lpDIS->itemAction == ODA_DRAWENTIRE) { DrawEntireMenu(lpDIS); } //if() } void CChidMenu ::DrawEntireMenu (LPDRAWITEMSTRUCT lpDIS) { CDC* pDC = CDC::FromHandle(lpDIS->hDC); CDC *tempDC=new CDC(); tempDC->CreateCompatibleDC (pDC); CBitmap bmpMenuBitamp,*oldBitmap; BOOL b=bmpMenuBitam...

Report on transactions posted to fixed/variable allocation A/C's
Be able to reports or enquire on transactions that were allocated to variable or fixed allocation accounts? Also be able to identify postings to a distribution account which have come from the an allocation account and ones which have not? ---------------- This post is a suggestion for Microsoft, and Microsoft responds to the suggestions with the most votes. To vote for this suggestion, click the "I Agree" button in the message pane. If you do not see the button, follow this link to open the suggestion in the Microsoft Web-based Newsreader and then click "I Agree" ...

Recovering old Information STore Databases
Hi gurus I have( sorry HAD) a perfecty functioning SBS2003 Exchange System until an active directory corruption due to HDD partial failure! I had the Exchange Information Store database (priv1 and pub1 edb and stm files) located on another HDD...phew...or so I thought. I have rebuilt the SBS server on a new HDD and am now trying to connect exchange to the old Information Store databases. I stopped the Information Store Service and then replaced the new empty databases (saving the new ones to a temp directory first!) with my old ones. and then restarted the Service. However, when I ex...

Archiving/backup of old data
I have 6 years of data in my msmoney file. I just did an archive of all my data prior to 1 Jan 2004. MSMoney created archive file with old plus also some data after 1 Jan 2004 (including some transactions from yesterday!). How do I get MSMoney to create an archive/backup of only data prior to 1 Jan 2004? What techniques do you folks use? -- Using Opera's revolutionary e-mail client: http://www.opera.com/mail/ Most of us don't. My Money file goes back to Money 95. Have a look at http://umpmfaq.info/faq.html#Q184 plus other questions in the same area. -- Regards Bob Pee...

Faster or Slower
I need to refer to an external database. Does it matter if it's on the root or a directory or two down? C:\History.mdb or C:\PS\History.mdb or C:\PS\WR\History.mdb Will there be a great performance difference between one or the other? Thnaks DS Tony Toews has some comments on this question here: http://www.granite.ab.ca/access/performancefaq.htm -- 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. "DS" <bootybox@optonline.net> wrote in mes...

When i press Ctrl+C it creates a screen print/copy
When i press Ctrl+C it creates a screen print/copy instread of copy the formula, how can i get rid of this? Thanks Niklas Does the same thing happen if you open excel in safe mode: close excel windows start button|run excel /safe If no, then it sounds like you have a "helpful" macro jumping in. Chip Pearson has some notes on how to diagnose startup errors at: http://www.cpearson.com/excel/StartupErrors.htm And Jan Karel Pieterse has more notes at: http://www.jkp-ads.com/Articles/StartupProblems.htm Following these instructions, you should be able to isolate the workbook that&...

How do I stop Outlook from auto starting (auto loading) when my c.
How do I stop Outlook from auto starting (auto loading) when my computer sterts up?? Delete the shortcut from your Windows startup folder. --� Milly Staples [MVP - Outlook] Post all replies to the group to keep the discussion intact. Due to the (insert latest virus name here) virus, all mail sent to my personal account will be deleted without reading. After furious head scratching, Jason <Jason@discussions.microsoft.com> asked this group: | How do I stop Outlook from auto starting (auto loading) when my | computer sterts up?? ...

Basic C++ question
I have a dll which is a cpp program in VS 2005. I checked the code, this has a class but that doesn't have any members in the header file and also in .cpp file. Both of them only have constructor and is also left blank. In the CPP program it has around 15 methods and one of the is the extern 'C' call to the dll and is working fine. This extern 'C' methods calls some other methods in the c program which in turn calls other methods. Now the question is how come these methods without any declaration in any of the header files or in C++ file works properly? The reason for thi...

Remove old month from chart add new/no manual reference change
jan feb mar apr 10 20 30 40 I want to graph the latest 4 months without having to go in a change refrences in the chart each month. Next month feb mar apr may 20 30 40 50 If I drag the last months across to pick up the formulas for the next month I get 5 months on the graph instead of 4 Hi Kameel Its possible only. Example: First Row months (A1: Jan, B1: Feb,…..) Second Row values (A2: 10, B2: 20,…..) Put any column (eg. K10) this function: =ADDRESS(1,COUNTA(A1:AA1)-3)&":"&ADDRESS(2,COUNTA(A1:AA1)) You will get the cell address of new four months. Click Ins...

HP Pavilion Intel 8200 runs slower than other Intel Q8200
I have an HP p6140f+, Pavilion Q8200 Intel CPU desktop. Windows 7, 8 GB of RAM. After I have defragged the C drive perfectly, deleted all cookies, significantly reduced Restore points, have no applications loaded other than ESET NOD32 AV, Graphic PCI Express 9400 GT, and running Passmark Performance Test, version 7, after the many tests are done this new desktop gets an overall score of 691. When I get the worldwide database for the same CPU Q8200 and the same Graphics card and the same (or less RAM I find overall scores of 1220, 1144, 1191, 1292 and higher. Talking to HP ...

equivalent of old office 2002 Shortcut Bar
Hello: Since office 2003, no more Shortcut Bar comes with office, is there a standalone program that can do the same job? I find it really convenient Thanks Maurice On Jan 29, 3:58=A0pm, "Maurice" <moris...@hotmail.com> wrote: > Hello: > > Since office 2003, no more Shortcut Bar comes with office, is there a > standalone program that can do the same job? > I find it really convenient > > Thanks > Maurice Perhpas this will help you get started: http://support.microsoft.com/kb/822573 http://support.microsoft.com/kb/830180 ...

Visual C++ 6.0 & Visual C++ Toolkit 2003
I read an article that we can make Visual C++ 6.0 use the free Visual C++ 2003 Toolkit (command-line) compiler. Assuming Visual Studio 2003.NET uses the same C++ compiler as the free 2003 Toolkit is it possible to make Visual Studio 2003.NET point the include/lib folder path to Visual C++ 6.0 ones? I've never heard of this, but my guess is that it would be easier to just upgrade to the later version. Something tells me that trying to kludge a new compiler into the older IDE is going to be problematic. Tom "Andrew Wan" <andrew_wan1980@hotmail.com> wrote in messa...

The hot tips from 23 year old!!!
Do you want to hear 23 year old Successful internet Enterpreneur shares All of the secrets to how she makes a lot of money. YES Click now: http://angel1991.mannco.hop.clickbank.net --- MAF Anti-Spam ID: 20060203060445U5l5GtE0 ...

Portfolio Manager the same old Problem
Hi After opening 2 tickets, number of unanswered emails and waiting for 2 months I still didn't received final respond from MS Tech Support. So much for free support. This is how we leaned ... See problem description below. This problem starts some where around Money 2003. I am thinking about going back from my 2006 version to 2003 or 2004 version. I found a couple of messages on this site, from people who had the same problem. Does any body know for sure, what was the last version that didn't have this problem - 2002, 2003, 2004, so I can try to reinstall it in place of 2006? Pr...

MFC and c++ problems
Forgive me if I'm overlooking the obvious. Basically, this is my problem: I have a derived Dialog: class A : public CDialog{ } I have a derived CTreeCtrl: class B : public CTreeCtrl{ } In A, there is an instance of B, as well as a bunch of other controls, which should contain information relating to the text for a tree item (HTREEITEM) in B. The information is stored in an INI file. Ok, I can get some of the windows messages to work in B, but begindrag() does not work at all (I've checked the create() settings, and it's not the TVS_DISABLEDRAGDROP flag). Basically, my ques...

Excel 2007
The same Edit / Fill / Justify doesn't seem to work the same in 2007 as it does with XP when editing long text in a cell to fill below. Any suggestions? Can you provide an example of the problem you see? -- Jim "Scott" <Scott@discussions.microsoft.com> wrote in message news:A1995B19-B8C6-4B8A-88B9-7C0BF7605776@microsoft.com... | The same Edit / Fill / Justify doesn't seem to work the same in 2007 as it | does with XP when editing long text in a cell to fill below. Any suggestions? ...

Old Display name showing on sent mails
Ok maybe this question has been asked a thousand times... I have moved from a big company with system admin to a new business owner and have spent the last 3 weeks trying to change my Email account in Outlook to show my Company name as my display name.... So far have tried.... 1: Delete all accounts - Exit Outlook - start > settings > Mail - create new account - restart - open Outlook - select new account as defalt send an Email to myself and.... same problem.... 2: Start > run > REGEDIT - search "my name" and it isnt in the registry in either BINARY or TEXT so ...

Handle under Visual C++.NET
Hi, I have some problem to retrieve handle of window under VC++.NET. Under VC++ 6, i could use hWnd which was corresponding to my Application... however under .NET i didn't find a such thing... could you help me please ? thanks, Maileen As far as I know, there is no difference. There are some issues of managed code, but even C# has a way to retrieve a raw handle. Your description is a bit vague, because window handles are not applications; did you mean that you want the handle for the mainframe of your application? joe On Sun, 22 Feb 2004 18:36:30 +0100, Maileen <nospam@nospam....

ActiveX ok in MFC but not in C#
Hello, I wrote an ActiveX in MFC. This ActiveX is derived from the interface IMyInterface and implement the standard functions QueryInterface, AddRef,Release and my own InCmde(BSTR Cmde,BSTR *Retour), OutCmde(BSTR Cmde,BSTR *Retour). The definition of this interface is in a separate idl file, I compile it with MIDL to obtain IMyInterface_h.h and IMyInterface_i.c . I do this, instead of integrated it in the ActiveX idl file, because I use this interface to many ACtiveX. The MFC application can take the pointer of this interface on two ActiveX and exchange it, so the two ActiveX can communica...

Using C# to read mass data from Excel 2003
Hi all�� I am using C# to read data from Excel 2003, However, I found the method I taken is too inefficient. Read a 250X250 sized matrix will take several minutes. May u provide me some high efficient method to solve mass data reading problem��Thanks int ColNum = mySheet.UsedRange.Columns.Count; int RowNum = mySheet.UsedRange.Rows.Count; Range range = mySheet.get_Range(mySheet.Cells[1, 1], mySheet.Cells[RowNum, ColNum]); ... for (int i = 1; i <= RowNum; ++ i) { DataRow dr; dr = dt.NewRow(); for (int j = 1; j <= ColNum; ++ j) { dr[j - 1] = ((...

MFC with c engine
Hi, My MFC application contains an engine that was written in c language. My problem is that each time that the engine calls DOS functions (such as copy, del, etc...) I recieve a black "cmd" window for a second. How can I prevent the cmd window from showing ? thanks, Yoav. Yoavo wrote: > Hi, > My MFC application contains an engine that was written in c language. > My problem is that each time that the engine calls DOS functions (such as > copy, del, etc...) I recieve a black "cmd" window for a second. > How can I prevent the cmd window from showing ? ...

Outlook slower after archiving
I know this sounds crazy, but users in my office have been reporting that their computers are *much* slower after archiving messages from Outlook 2003. Here's some background. Most users are running Windows XP SP3. Boxes are 1.25Ghz Pentium IVs with 2GB of RAM and 10-20GB free. Their Exchange mailboxes are ridiculous -- 2-5GB. Just last night, a user archived several hundred message using Outlooks archive feature. The archive.pst files is located on her HD. She called me this morning saying that her computer is much slower now, and that it has periods of unresponsiveness. Multiple users ...