Re: Unknown pointer problem between Visual Basic and C
From: Maximiliano Rios (maximiliano_rios_at_hotmail.com)
Date: 02/11/05
- Next message: d.theis: "modifyworldtransform on entire screen"
- Previous message: Fabien: "Searching for the quickest way to do an alphablend per pixel and be compatible with W9x"
- In reply to: Craig Kelly: "Re: Unknown pointer problem between Visual Basic and C"
- Next in thread: Mike D Sutton: "Re: Unknown pointer problem between Visual Basic and C"
- Reply: Mike D Sutton: "Re: Unknown pointer problem between Visual Basic and C"
- Reply: Craig Kelly: "Re: Unknown pointer problem between Visual Basic and C"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 11 Feb 2005 12:02:57 -0300
Hi Craig, really thanks a lot for answering.
I'm going to explain more detailed:
how application works:
Objective: Draw into a picture area. I can draw everything, except complex
GIS data, provided for a third party library. That library is C coded; I
can't access the methods from Visual Basic directly, so, I've built an small
VB compatible C library to pass information. That library works ok with
every method, except drawing from Visual Basic (HDC seems to be wrong). I
use same library from C#, and it works ok!
>From Visual Basic
- I get a device context and create Compatible DC.
- For drawing, I create a pen and assign to DC
- For drawing, I create a solid brush an assign to DC
- I create a compatible bitmap, white, solid, with picture dimensions and
assign to DC
- For checking, I draw a simple diagonal line, it works and I can see the
line into the picture
- I send to the "Visual Basic wrapper" built in C, dimensions and DC pointer
- Third party library fails. Really, doesn't hang, but send to me a result
code with an unspecified error trying to draw.
>From Dot Net C#
- I create a bitmap object
- I Get a graphic object from this bitmap
- I create a white SolidBrush object
- I fill graphics rectangle with that brush, with a screen picture dimension
- I set background bitmap from picture to the created Bitmap object
- I send to the "Visual Basic wrapper" built in C, dimensions and DC pointer
- Third party library DRAW the picture perfect !!!!!!!
C code looks like this:
int _stdcall DrawLayer(int hDC, int aLayer, double... )
Int pointer is sent from Visual Basic and Dot Net, value is okay, I put
debug code to check it;
>From Visual Basic I send DC obtained from GetDC(picture1.hWND) or
picture1.hDC (both of them fails)
>From Dot Net I send IntPtr object. (works!)
Craig, your code, used in my Visual Basic code works fine, I can see an
small colored box, It probes than DC pointer is valid.
Thanks.
"Craig Kelly" <cnkelly.nospam@nospam.net> escribió en el mensaje
news:l0SOd.188112$w62.123661@bgtnsc05-news.ops.worldnet.att.net...
> "Maximiliano Rios" wrote:
>
> > But, I ever can't draw with a HDC sent from Visual Basic, everytime
> > fails. Every method works okay, but I send a pointer from a picture
> > (for example) or from a window, and I get an unexpected error when I
> > try to use it. Application doesn't cause GPF, but I get an error or
> > (the worst) nothing happens.
>
> A few thoughts...
>
> - Have you checked the AutoRedraw property of the PictureBox? If it's
> False, the picture box must be visible for the drawing to take effect.
>
> - Does your C code cache the HDC for use later? The HDC can change, so
you
> really need to pass it to the C code every time you perform your drawing
> operations.
>
> - Does your C code erase the HDC first?
>
> A simple test would be
>
> SomePictureBox.AutoRedraw = True
> SomePictureBox.Cls
> Call MyBigCFunction(SomePictureBox.hDC)
>
> To prove to yourself that this works, you can ever substitute a VB
function
> to draw to the HDC via the API. Before posting this, I cobbled together a
> test:
>
> Dim hbr As Long
> Dim r As RECT
>
> Picture1.Cls
>
> r.Bottom = (Rnd * 240) + 1
> r.Right = (Rnd * 240) + 1
>
> hbr = CreateSolidBrush(&HFFAAAA)
> FillRect Picture1.hdc, r, hbr
> Call DeleteObject(hbr)
>
>
> This worked fine. If none of the above helps, perhaps you could post some
> sample code to test?
>
> Craig
>
>
- Next message: d.theis: "modifyworldtransform on entire screen"
- Previous message: Fabien: "Searching for the quickest way to do an alphablend per pixel and be compatible with W9x"
- In reply to: Craig Kelly: "Re: Unknown pointer problem between Visual Basic and C"
- Next in thread: Mike D Sutton: "Re: Unknown pointer problem between Visual Basic and C"
- Reply: Mike D Sutton: "Re: Unknown pointer problem between Visual Basic and C"
- Reply: Craig Kelly: "Re: Unknown pointer problem between Visual Basic and C"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|