且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

重启Windows

更新时间:2023-12-04 10:35:10

" Lee Kok Onn" < ko *** @ viperlink.com.sgschrieb
"Lee Kok Onn" <ko***@viperlink.com.sgschrieb




我在vb2005中编写了以下代码重新启动windows,

但以错误ExitWindows(EWX_REBOOT,& HFFFFFFFF)结束,调用

PInvoke函数''shutdown!shutdown.Form1: :ExitWindows''具有

不平衡堆栈。这可能是因为托管的PInvoke

签名与非托管目标签名不匹配


任何想法,都可以帮助。
>
Public Class Form1


Const EWX_LogOff As Long = 0


Const EWX_SHUTDOWN = 1


Const EWX_REBOOT = 2


Const EWX_FORCE = 4


私有声明功能ExitWindows _


Lib" User32"别名ExitWindowsEx _


(ByVal dwOptions As Long,ByVal dwReserved As Long)As Long
Hi,

I have written the following code in vb2005 to reboot the windows,
but end with error "ExitWindows(EWX_REBOOT, &HFFFFFFFF)", call to
PInvoke function ''shutdown!shutdown.Form1::ExitWindows'' has
unbalanced the stack. This is likely because the managed PInvoke
signature does not match the unmanaged target signature"

Any ideas, can pls help.

Public Class Form1

Const EWX_LogOff As Long = 0

Const EWX_SHUTDOWN = 1

Const EWX_REBOOT = 2

Const EWX_FORCE = 4

Private Declare Function ExitWindows _

Lib "User32" Alias "ExitWindowsEx" _

(ByVal dwOptions As Long, ByVal dwReserved As Long) As Long



这些是VB6的声明,不是VB.Net。 32Bit现在是Integer或Int32

,或IntPtr,或布尔,取决于定义。


未经测试:


ReadOnly EWX_LogOff As New IntPtr(0)

ReadOnly EWX_SHUTDOWN As New IntPtr(1)

''...


私有声明函数ExitWindows _

Lib" User32"别名ExitWindowsEx _

(ByVal dwOptions作为IntPtr,ByVal dwReserved为整数)_

作为布尔值


我使用Intptr作为第一个参数因为它在PSDK中声明为UINT,

和UINT等于unsigned int谁的大小被宣布为系统

依赖,这意味着IntPtr。

Armin

These are declarations for VB6, not for VB.Net. 32Bit is Integer or Int32
now, or IntPtr, or Boolean, depending on the definition.

Untested:

ReadOnly EWX_LogOff As New IntPtr(0)
ReadOnly EWX_SHUTDOWN As New IntPtr(1)
''...

Private Declare Function ExitWindows _
Lib "User32" Alias "ExitWindowsEx" _
(ByVal dwOptions As IntPtr, ByVal dwReserved As Integer) _
As Boolean

I used Intptr for the first param because it''s declared as UINT in the PSDK,
and UINT is equal to "unsigned int" who''s size is declared as "System
dependent", which means IntPtr.
Armin

>

http://www.gotdotnet.com/Community/U...C-4A9A89D47FAD


-

新手编码器>
(这只是一个名字)
http://www.gotdotnet.com/Community/U...C-4A9A89D47FAD

--
Newbie Coder
(It''s just a name)


" Lee Kok Onn" < ko *** @ viperlink.com.sgschrieb:
"Lee Kok Onn" <ko***@viperlink.com.sgschrieb:

我在vb2005中编写了以下代码来重启windows,但结束了

,错误ExitWindows(EWX_REBOOT,& HFFFFFFFF),调用PInvoke

函数''shutdown!shutdown.Form1 :: ExitWindows''使堆栈失衡。

这可能是因为托管的PInvoke签名与

非托管目标签名不匹配
I have written the following code in vb2005 to reboot the windows, but end
with error "ExitWindows(EWX_REBOOT, &HFFFFFFFF)", call to PInvoke
function ''shutdown!shutdown.Form1::ExitWindows'' has unbalanced the stack.
This is likely because the managed PInvoke signature does not match the
unmanaged target signature"



你的函数声明是错误的。请查看以下示例,了解有效的

声明:


< URL:http://www.mentalis.org/soft/class.qpx?id = 7>


-

MS Herfried K. Wagner

MVP< URL:http://dotnet.mvps .org />

VB< URL:http://dotnet.mvps.org/dotnet/faqs/>

Your function declarations are wrong. Check out the sample below for valid
declarations:

<URL:http://www.mentalis.org/soft/class.qpx?id=7>

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