[英]vb.net applications to reload the INI file
i write this code to change default printer in windows and work fine but in reload the INI file have a error this is a code : 我编写此代码来更改Windows中的默认打印机并可以正常工作,但是在重新加载INI文件时出现错误,这是一个代码:
Private Sub SetDefaultPrinter(ByVal PrinterName As String, ByVal DriverName As String, ByVal PrinterPort As String)
Dim DeviceLine As String
'rebuild a valid device line string
DeviceLine = PrinterName & "," & DriverName & "," & PrinterPort
'Store the new printer information in the
'[WINDOWS] section of the WIN.INI file for
'the DEVICE= item
Call WriteProfileString("windows", "Device", DeviceLine)
'Cause all applications to reload the INI file
Call SendMessage(HWND_BROADCAST, WM_WININICHANGE, 0, "windows")
End Sub
Private Declare Function WriteProfileString Lib "kernel32" Alias "WriteProfileStringA" (ByVal lpszSection As String, ByVal lpszKeyName As String, ByVal lpszString As String) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lparam As String) As Long
Private Const HWND_BROADCAST As Long = &HFFFF&
Private Const WM_WININICHANGE As Long = &H1A
and this is a error : 这是一个错误:
A call to PInvoke function 'Test!Test.Form2::SendMessage' has unbalanced the stack. 调用PInvoke函数'Test!Test.Form2 :: SendMessage'已使堆栈不平衡。 This is likely because the managed PInvoke signature does not match the unmanaged target signature. 这可能是因为托管PInvoke签名与非托管目标签名不匹配。 Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature. 检查PInvoke签名的调用约定和参数是否与目标非托管签名匹配。
Does anyone have an idea to solve this problem? 有谁有解决这个问题的想法? Thankful 感谢
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _
ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _
ByVal lparam As String) As Long
Your data types are wrong. 您的数据类型错误。 The hwnd
parameter is pointer sized, wMsg
is a 32 bit value, and wParam
, lParam
and the return value are pointer sized. hwnd
参数的大小是指针大小, wMsg
是32位值, wParam
, lParam
和返回值是指针大小。 Note that Long
is a 64 bit type. 请注意, Long
是64位类型。
Instead it should be 相反,它应该是
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _
ByVal hwnd As IntPtr, ByVal wMsg As Integer, ByVal wParam As IntPtr, _
ByVal lparam As String) As IntPtr
Note that I recommend that, in the modern day, you use pinvoke declarations rather than Declare
. 请注意,我建议在现代使用pinvoke声明而不是Declare
。 This offer much more flexibility. 这提供了更大的灵活性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.