473,327 Members | 2,103 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

NullReference Fehler

Hallo,

habe ein VS02 Projekt konvertiert auf VS05. Es handelt sich um eine Klasse
zur erzeugung eines Screenshots
Dabei tritt oben genannter Fehler auf an.

Und zwar bei markierter Stelle:

Option Explicit On
Option Strict On
Option Compare Binary

Imports System
Imports System.Windows.Forms

Public Class Form1
Inherits System.Windows.Forms.Form

Private m_ssgen As ScreenshotGenerator

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Me.PictureBox1.Image = m_ssgen.Capture() '// hier solle man zuerst
auf NULL prüfen, Stelle des Fehlers //*****************
End Sub

Die Klasse sieht so aus:

Option Explicit On
Option Strict On
Option Compare Binary

Imports System
Imports System.Drawing

Public Class ScreenshotGenerator

Private Declare Function GetDesktopWindow Lib "user32.dll" () As IntPtr

Private Declare Function GetDC Lib "user32.dll" ( _
ByVal hWnd As IntPtr) As IntPtr

Private Declare Function ReleaseDC Lib "user32.dll" ( _
ByVal hWnd As IntPtr, _
ByVal hdc As IntPtr) As Int32

Private Declare Function GetWindowRect Lib "user32.dll" ( _
ByVal hWnd As IntPtr, _
ByRef lpRect As RECT) As Int32

Private Declare Function ScreenToClient Lib "user32.dll" ( _
ByVal hWnd As IntPtr, _
ByRef lpPoint As POINTAPI) As Int32

Private Structure POINTAPI
Public x As Int32
Public y As Int32
End Structure

Private Structure RECT
Public Left As Int32
Public Top As Int32
Public Right As Int32
Public Bottom As Int32
End Structure

Private Declare Function StretchBlt Lib "gdi32.dll" ( _
ByVal hdc As IntPtr, _
ByVal x As Int32, _
ByVal y As Int32, _
ByVal nWidth As Int32, _
ByVal nHeight As Int32, _
ByVal hSrcDC As IntPtr, _
ByVal xSrc As Int32, _
ByVal ySrc As Int32, _
ByVal nSrcWidth As Int32, _
ByVal nSrcHeight As Int32, _
ByVal dwRop As Int32) As Int32

Private Const SRCCOPY As Int32 = &HCC0020

Private m_intptrWindow As IntPtr

' <summary>
' Gibt das Handle des zu fotografierenden
' Fensters an oder gibt es zurück. Der Wert 0 gibt
' an, dass der gesamte Desktop eingefangen werden soll.
' </summary>
' <value>Handle des zu fotografierenden Fensters.</value>
Public Property Window() As IntPtr
Get
Return m_intptrWindow
End Get
Set(ByVal Value As IntPtr)
m_intptrWindow = Value
End Set
End Property

' <summary>
' Gibt eine Bitmap in Grösse des in der
' Eigenschaft <c>Window</cangegebenen Fensters mit
' dessen Inhalt zurück.
' </summary>
' <returns>Bitmap, die ein Bildschirmfoto
' eines Fensters enthält.</returns>
Public Function Capture() As Bitmap
Dim hWndWindowToCapture As IntPtr
If Me.Window.Equals(IntPtr.Zero) Then

' Handle auf Desktop ermitteln.
hWndWindowToCapture = GetDesktopWindow()
Else
hWndWindowToCapture = Me.Window
End If

' Rechteck mit Massen des Desktops ermitteln.
Dim rct As RECT
GetWindowRect(hWndWindowToCapture, rct)

Dim intWidth As Int32 = rct.Right - rct.Left
Dim intHeight As Int32 = rct.Bottom - rct.Top

' Koordinaten in Client-Koordinaten transformieren.
Dim pt As POINTAPI
pt.y = rct.Top
pt.x = rct.Left
ScreenToClient(hWndWindowToCapture, pt)
rct.Left = pt.x
rct.Top = pt.y

' Erstellen einer Bitmap, die den Screenshot
' aufnehmen kann (in Grösse des Desktops).
Dim b As Bitmap = New Bitmap(intWidth, intHeight)

' Erstellen eines Graphics-Objekts zur Bitmap,
' um in sie zu zeichnen.
Dim g As Graphics = Graphics.FromImage(b)

' Erstellen eines Handles auf den Device
' Context des Desktops.
Dim hdcWindow As IntPtr = GetDC(hWndWindowToCapture)

' Ermitteln eines Handles auf den Device
' Context des Graphics-Objekts
' zur Ziel-Bitmap.
Dim hdc As IntPtr = g.GetHdc()

' Zeichnen des Inhalts des Desktop-DCs
' in den DC der Bitmap.
StretchBlt( _
hdc, _
0, _
0, _
intWidth, _
intHeight, _
hdcWindow, _
rct.Left, _
rct.Top, _
intWidth, _
intHeight, _
SRCCOPY _
)

' Handles freigeben.
ReleaseDC(hWndWindowToCapture, hdcWindow)
g.ReleaseHdc(hdc)

' Erstellte Grafik zurückgeben.
Return b
End Function
End Class
Vielleicht könnt ihr mir helfen das wieder lauffähig zu bekommen.

Herzlichen Dank und Grüßle!
Mar 25 '07 #1
7 1365
Habs rausgefunden, hab einfach ein:
Private m_ssgen As New ScreenshotGenerator

draus gemacht!
Mar 25 '07 #2
Um, you might want to post to a *German* version of this newsgroup to get a
quicker response. This one is in English. Although I'm sure there's someone
around who speaks German...

Robin S.
--------------
"Peter Hansch" <Ha*****@gmx.dewrote in message
news:eu*************@news.t-online.com...
Habs rausgefunden, hab einfach ein:
Private m_ssgen As New ScreenshotGenerator

draus gemacht!

Mar 26 '07 #3
"RobinS" <Ro****@NoSpam.yah.noneschrieb:
Um, you might want to post to a *German* version of this newsgroup to get
a quicker response. This one is in English. Although I'm sure there's
someone around who speaks German...
I agree. The more appropriate newsgroup is
"microsoft.public.de.german.entwickler.dotnet. vb".

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Mar 26 '07 #4


"Herfried K. Wagner [MVP]" <hi***************@gmx.atwrote in message
news:eN**************@TK2MSFTNGP02.phx.gbl...
"RobinS" <Ro****@NoSpam.yah.noneschrieb:
>Um, you might want to post to a *German* version of this newsgroup to get
a quicker response. This one is in English. Although I'm sure there's
someone around who speaks German...

I agree. The more appropriate newsgroup is
"microsoft.public.de.german.entwickler.dotnet. vb".

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Do I want to know what entwickler means?

Mythran
Mar 26 '07 #5
I am really sorry! Please Excuse me.
From now on I will post here in english or in the appropriate german
newsgroup.
thank you!
Mar 26 '07 #6
"Mythran" <ki********@hotmail.comschrieb im Newsbeitrag
news:uA****************@TK2MSFTNGP02.phx.gbl...
Do I want to know what entwickler means?
Entwickler means developer.

Peter
Mar 26 '07 #7
Bitte!

"Peter Hansch" <Ha*****@gmx.dewrote in message
news:eu*************@news.t-online.com...
>I am really sorry! Please Excuse me.
From now on I will post here in english or in the appropriate german
newsgroup.
thank you!

Mar 27 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Taras | last post by:
This code has been working for some months - suddenly it get a NullReference error Private Sub btnShowProj_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnShowProj.Click...
3
by: Benedict Ernst | last post by:
Hallo NG, wo ist der Fehler in diesem C code? > #include <stdio.h> > #include <stdlib.h> > #include <math.h> > > int wait () > { > setvbuf(stdin,NULL,_IONBF,0);
2
by: Larry Re | last post by:
I've written a small C# app which appears to work perfectly except for the fact that I get a NullReference exception when I close the form using the red 'X' in the upper right hand corner of the...
3
by: Tom | last post by:
Hi, I built a class project (classproject.dll) and a web project (webproject.dll). The web project needs to reference to that class project. They can compile without error. But, it has...
1
by: Marko G. | last post by:
Hallo, ich versuche nun seit einiger Zeit, auf einem Active-Directory Server das Passwort eines Benutzers zu setzen. Hier der verwendete Quelltext: ------------ Dim entry As DirectoryEntry =...
5
by: Paul Cheetham | last post by:
Hi, I have moved a fairly large project from VS2003 to VS2005, and now trying to get it running. It now compiles OK after minimal changes, but I am now getting a NullReference Exception on...
0
by: Martin Himmel | last post by:
Hello Newsgroup, I want to build xerces.lib (actually dynamical, but as there are many linker errors using the dll, the static .lib version) ich möchte die xercesc-lib erstellen. eigentlich die...
1
by: Martin Himmel | last post by:
Hello Newsgroup, I want to build xerces.lib (actually dynamical, but as there are many linker errors using the dll, the static .lib version) ich möchte die xercesc-lib erstellen. eigentlich die...
13
by: locy | last post by:
i try to compile this programm useing pluto,it shows me error .where schould the fehler be? #include <"stdio.h"> int main() { int counter; int even=0; int b= 7,int h= 10; if h+ = b % 10;
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.