Benutzer mit den meisten Antworten
Falscher Datentyp in VB.net / Verständnisproblem

Frage
-
Hallo,
wenn ich mein Script analysieren lasse, bekomme ich für die folgende Zeile 3 Warnungen, für die ich nicht weiß wie ich sie lösen soll:
Private Declare Ansi Function GetWindowThreadProcessId Lib "user32" (ByVal hWnd As Integer, ByRef lpdwProcessId As IntPtr) As IntPtr
Hier die zugehörigen Warnungen:
Because it is a P/Invoke method, 'ScriptMain.GetWindowThreadProcessId(Integer, ByRef IntPtr)' should be defined in a class named NativeMethods, SafeNativeMethods, or UnsafeNativeMethods.
As it is declared in your code, parameter 'hWnd' of P/Invoke 'ScriptMain.GetWindowThreadProcessId(Integer, ByRef IntPtr)' will be 4 bytes wide on 64-bit platforms. This is not correct, as the actual native declaration of this API indicates it should be 8 bytes wide on 64-bit platforms. Consult the MSDN Platform SDK documentation for help determining what data type should be used instead of 'Integer'.
As it is declared in your code, the return type of P/Invoke 'ScriptMain.GetWindowThreadProcessId(Integer, ByRef IntPtr)' will be 8 bytes wide on 64-bit platforms. This is not correct, as the actual native declaration of this API indicates it should be 4 bytes wide on 64-bit platforms. Consult the MSDN Platform SDK documentation for help determining what data type should be used instead of 'IntPtr'.
Ich habe dieses Script im Zuge der Migration von SQL Server 2008 nach 2016 geprüft.
Da ich nicht der tiefe Kenner dieser Dinge bin stehe ich gerade vor einem Rätsel und komme nicht weiter.
Gruß
cheapy
Antworten
-
Hi,
lt. https://www.pinvoke.net/default.aspx/user32.getwindowthreadprocessid sind die Datentypen genau umgekehrt zu denen, die Du verwendest. Evtl. ein Fehler bei deiner Migration?
Private Declare Auto Function GetWindowThreadProcessId Lib "user32.dll" ( ByVal hwnd As IntPtr, ByRef lpdwProcessId As Integer ) As Integer
HTH
Gruß, Stefan
Microsoft MVP - Visual Developer ASP/ASP.NET (2001-2018)
https://www.asp-solutions.de/ - IT Beratung, Softwareentwicklung, Remotesupport
- Bearbeitet Stefan FalzModerator Freitag, 18. Juni 2021 11:33
- Als Antwort vorgeschlagen Dimitar DenkovMicrosoft contingent staff, Administrator Freitag, 25. Juni 2021 10:11
- Als Antwort markiert Cheaptrick_la Freitag, 25. Juni 2021 12:47
Alle Antworten
-
Hi,
lt. https://www.pinvoke.net/default.aspx/user32.getwindowthreadprocessid sind die Datentypen genau umgekehrt zu denen, die Du verwendest. Evtl. ein Fehler bei deiner Migration?
Private Declare Auto Function GetWindowThreadProcessId Lib "user32.dll" ( ByVal hwnd As IntPtr, ByRef lpdwProcessId As Integer ) As Integer
HTH
Gruß, Stefan
Microsoft MVP - Visual Developer ASP/ASP.NET (2001-2018)
https://www.asp-solutions.de/ - IT Beratung, Softwareentwicklung, Remotesupport
- Bearbeitet Stefan FalzModerator Freitag, 18. Juni 2021 11:33
- Als Antwort vorgeschlagen Dimitar DenkovMicrosoft contingent staff, Administrator Freitag, 25. Juni 2021 10:11
- Als Antwort markiert Cheaptrick_la Freitag, 25. Juni 2021 12:47
-
Deine Signatur für .Net ist falsch. Deine gilt nur noch für VB6 oder VBA:
https://www.pinvoke.net/default.aspx/user32.getwindowthreadprocessid