CreatePen GDI function problem on Windows 7 - gdi

CreatePen GDI function does not work on Windows 7 when pen width is 3 or 4 (LineTo draws nothing). It works for 0 - 2 width. In all cases PS_SOLID pen style was used.

LineTo does not include the final point of the line. Try a different endcap setting to see if it makes a difference.

does it return a handle or NULL?
have you considered using CreatePenIndirect and the structure LOGPEN?
http://msdn.microsoft.com/en-us/library/dd183510(v=VS.85).aspx
http://msdn.microsoft.com/en-us/library/dd145041(v=VS.85).aspx
this just works fine on my computer, Windows 7 x64:
Option Explicit
Private Declare Function CreatePen Lib "gdi32" ( _
ByVal nPenStyle As Long, _
ByVal nWidth As Long, _
ByVal crColor As Long) As Long
Private Declare Function LineTo Lib "gdi32" ( _
ByVal hDC As Long, ByVal x As Long, ByVal y As Long) As Long
Private Declare Function SelectObject Lib "gdi32" ( _
ByVal hDC As Long, ByVal hObject As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" ( _
ByVal hObject As Long) As Long
Dim x As Long
Dim y As Long
Dim w As Long
Private Sub Command1_Click()
w = w + 1
Dim hpen As Long: hpen = CreatePen(0, w, 0)
Dim ret As Long: ret = SelectObject(Me.hDC, hpen)
If ret <> 0 Then
x = x + 10
y = y + 10
Call LineTo(Me.hDC, x, y)
End If
Call DeleteObject(hpen)
End Sub
click the button more times

Related

How Can I Fix Reflected XSS Clients in Asp.Net

How can I fix a reflected XSS client problem on ASP.Net? Can anyone help me?
The problem is below:
Reflected XSS Client
Method :
ROW:563
Private Shared Function bindSiteMenu(TSql As String) As Data.DataTable
....
563. DRow.Item("Sortby") = dt1.Rows(i).Item("Sortby").ToString
564. dtAll.Rows.Add(DRow)
....
569. Return dtAll
Method :
Public Shared Function FrontSiteMenuForSMap(ByVal SiteID As Long) As
Data.DataTable
....
529. Return bindSiteMenu(TSql)
Method :
Protected Sub SiteMap(SitID As Long)
....
27. Dim dt As Data.DataTable =
SiteMenuObj.FrontSiteMenuForSMap(SitID)
....
29. SetNodes(dt, SitID, 0, 0, "")
Method :
ROW:77
Protected Sub SetNodes(ByVal dtTree As Data.DataTable, ByVal SiteID As Long,ByVal ParentId As Long, ByVal Level As Integer, ByVal TreeNumber As String)
....
33. Protected Sub SetNodes(ByVal dtTree As Data.DataTable, ByVal
SiteID As Long, ByVal ParentId As Long, ByVal Level As Integer, ByVal
TreeNumber As String)
....
36. rows = dtTree.Select(filterExpr)
37. If rows.GetUpperBound(0) >= 0 Then
....
47. For Each row In rows
48. tmpParentId = row.Item("ParentId").ToString
49. tmpFDefaultLink = row.Item("FDefaultLink").ToString
50. tmpMenuTitle = row.Item("MenuTitle").ToString
51. tmpMenuID = row.Item("MenuID").ToString
52. tmpSiteID = row.Item("SiteID").ToString
53. tmpURL = row.Item("URL").ToString
....
71. Url = tmpURL
....
77. litF.Text = "<li " & css & "><a href=""" & Url
& """ title=""" & tmpMenuTitle & Title & """>" & tmpNumber & tmpCount &
"." & tmpMenuTitle & "</a><ol>"
Thanks for everyone's help!

vb6-Getting the physical address of network adapter on Windows 7 and later

I have to apply a protection mechanism to a vb6 software, and we have decided to go ahead with using the hardware address of network card (MAC Address) for generating the keys. I have this piece of code with me which does the same. I believe that it is working on in Windows XP.
Option Explicit
'
'---------------------------------------------------------------------------
' Used to get the MAC address.
'---------------------------------------------------------------------------
'
Private Const NCBNAMSZ As Long = 16
Private Const NCBENUM As Long = &H37
Private Const NCBRESET As Long = &H32
Private Const NCBASTAT As Long = &H33
Private Const HEAP_ZERO_MEMORY As Long = &H8
Private Const HEAP_GENERATE_EXCEPTIONS As Long = &H4
Private Type NET_CONTROL_BLOCK 'NCB
ncb_command As Byte
ncb_retcode As Byte
ncb_lsn As Byte
ncb_num As Byte
ncb_buffer As Long
ncb_length As Integer
ncb_callname As String * NCBNAMSZ
ncb_name As String * NCBNAMSZ
ncb_rto As Byte
ncb_sto As Byte
ncb_post As Long
ncb_lana_num As Byte
ncb_cmd_cplt As Byte
ncb_reserve(9) As Byte 'Reserved, must be 0
ncb_event As Long
End Type
Private Type ADAPTER_STATUS
adapter_address(5) As Byte
rev_major As Byte
reserved0 As Byte
adapter_type As Byte
rev_minor As Byte
duration As Integer
frmr_recv As Integer
frmr_xmit As Integer
iframe_recv_err As Integer
xmit_aborts As Integer
xmit_success As Long
recv_success As Long
iframe_xmit_err As Integer
recv_buff_unavail As Integer
t1_timeouts As Integer
ti_timeouts As Integer
Reserved1 As Long
free_ncbs As Integer
max_cfg_ncbs As Integer
max_ncbs As Integer
xmit_buf_unavail As Integer
max_dgram_size As Integer
pending_sess As Integer
max_cfg_sess As Integer
max_sess As Integer
max_sess_pkt_size As Integer
name_count As Integer
End Type
Private Type NAME_BUFFER
name_(0 To NCBNAMSZ - 1) As Byte
name_num As Byte
name_flags As Byte
End Type
Private Type ASTAT
adapt As ADAPTER_STATUS
NameBuff(0 To 29) As NAME_BUFFER
End Type
Private Declare Function Netbios Lib "netapi32" _
(pncb As NET_CONTROL_BLOCK) As Byte
Private Declare Sub CopyMemory Lib "kernel32" _
Alias "RtlMoveMemory" (hpvDest As Any, ByVal _
hpvSource As Long, ByVal cbCopy As Long)
Private Declare Function GetProcessHeap Lib "kernel32" () As Long
Private Declare Function HeapAlloc Lib "kernel32" _
(ByVal hHeap As Long, ByVal dwFlags As Long, _
ByVal dwBytes As Long) As Long
Private Declare Function HeapFree Lib "kernel32" _
(ByVal hHeap As Long, ByVal dwFlags As Long, _
lpMem As Any) As Long
Private Sub Form_Load()
Dim strMACAddress As String
strMACAddress = fGetMacAddress()
If strMACAddress <> "" Then
Call MsgBox(strMACAddress, vbInformation, "MAC Address")
End If
End Sub
Private Function fGetMacAddress() As String
Dim l As Long
Dim lngError As Long
Dim lngSize As Long
Dim pAdapt As Long
Dim pAddrStr As Long
Dim pASTAT As Long
Dim strTemp As String
Dim strAddress As String
Dim strMACAddress As String
Dim AST As ASTAT
Dim NCB As NET_CONTROL_BLOCK
'
'---------------------------------------------------------------------------
' Get the network interface card's MAC address.
'----------------------------------------------------------------------------
'
On Error GoTo ErrorHandler
fGetMacAddress = ""
strMACAddress = ""
NCB.ncb_command = NCBRESET
Call Netbios(NCB)
NCB.ncb_callname = "* "
NCB.ncb_command = NCBASTAT
NCB.ncb_lana_num = 0
NCB.ncb_length = Len(AST)
pASTAT = HeapAlloc(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS Or _
HEAP_ZERO_MEMORY, NCB.ncb_length)
If pASTAT = 0 Then GoTo ErrorHandler
NCB.ncb_buffer = pASTAT
Call Netbios(NCB)
Call CopyMemory(AST, NCB.ncb_buffer, Len(AST))
strMACAddress = Right$("00" & Hex(AST.adapt.adapter_address(0)), 2) & _
Right$("00" & Hex(AST.adapt.adapter_address(1)), 2) & _
Right$("00" & Hex(AST.adapt.adapter_address(2)), 2) & _
Right$("00" & Hex(AST.adapt.adapter_address(3)), 2) & _
Right$("00" & Hex(AST.adapt.adapter_address(4)), 2) & _
Right$("00" & Hex(AST.adapt.adapter_address(5)), 2)
Call HeapFree(GetProcessHeap(), 0, pASTAT)
fGetMacAddress = strMACAddress
GoTo NormalExit
ErrorHandler:
Call MsgBox(Err.Description, vbCritical, "Error")
NormalExit:
End Function
Reference: 118623
When I run this code on Windows 7. It only returns the MAC Address as 00000000. I have tried on 5 PCs and the result is the same. Please help :|
Try this :
Dim myWMI As Object, myObj As Object, Itm
Set myWMI = GetObject("winmgmts:\\.\root\cimv2")
Set myObj = myWMI.ExecQuery("SELECT * FROM " & _
"Win32_NetworkAdapterConfiguration " & _
"WHERE IPEnabled = True")
For Each Itm In myObj
MsgBox (Itm.IPAddress(0))
MsgBox (Itm.MACAddress)
Exit For
Next
find with google : http://www.access-programmers.co.uk/forums/showthread.php?t=216672
Public Function MACid() As String
Dim computer As String
Dim wmi As Variant
Dim query As Variant
Dim mac As Variant
Dim mac_ids As String
computer = "."
Set wmi = GetObject("winmgmts:" & _
"{impersonationLevel=impersonate}!\\" & _
computer & "\root\cimv2")
Set query = wmi.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration where IPEnabled = true")
For Each mac In query
mac_ids = mac_ids & ", " & mac.MacAddress
Next mac
If Len(mac_ids) > 0 Then mac_ids = Mid$(mac_ids, 3)
MACid = mac_ids
End Function

how to get array element as output in vb asp.net2010

In this program I created one array, while clicking on the get Button it does not show any output because the str variable is empty. How should I get proper output...
Partial Class dynamic_array
Inherits System.Web.UI.Page
Dim s(2) As String
Dim str As String
Protected Sub btn_save_Click(sender As Object, e As System.EventArgs) Handles btn_save.Click
Dim i As Integer = 0
For i = 0 To s.Length - 1
s(i) = InputBox("enter name " + (i + 1).ToString)
Next
End Sub
Protected Sub btn_get_Click(sender As Object, e As System.EventArgs) Handles btn_get.Click
Dim i As Integer = 0
str = ""
For i = 0 To s.Length - 1
str &= s(i) + vbCrLf
Next
MsgBox(str)
End Sub
End Class
You can use Session or ViewState to store the Array values..
try like this
Partial Class dynamic_array
Inherits System.Web.UI.Page
Dim s(2) As String
Dim str As String
Protected Sub btn_save_Click(sender As Object, e As System.EventArgs) Handles btn_save.Click
Dim i As Integer = 0
For i = 0 To s.Length - 1
s(i) = InputBox("enter name " + (i + 1).ToString)
Next
ViewState("Array")=s
End Sub
Protected Sub btn_get_Click(sender As Object, e As System.EventArgs) Handles btn_get.Click
Dim i As Integer = 0
str = ""
s= ViewState("Array")
For i = 0 To s.Length - 1
str &= s(i) + vbCrLf
Next
MsgBox(str)
End Sub
End Class
Hope this will help, Mark useful if it's helps.
In Asp.Net all variables set on the page level are reset on every postback. Thats why s-variable is always empty on get-button click.
You could save this information for example in the viewstate
Viewstate("MyData") = "Something"
I encourage you to familiarize your self with Asp.Net web forms basic state management: http://msdn.microsoft.com/en-us/library/50x35554(v=vs.80).aspx

how to decode an ASCII code back to string in ASP.Net

I Have a problem with decoding ASCII code back to string.
First I take a text input from user and convert it to ASCII code which is consecutively assigned to a label. Than I want to convert it from that label back to the normal string. But in stead of the string I receive a random symbols.
I believe it's because the function can't distinguish when a code for a certain letter starts and when it's finishes. Any Idea how can i set a delimiter or something like that? if ever it's going to solve the problem of course
this is the code i used:
Protected Sub Button4_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button4.Click
Label3.Text = ""
For x As Integer = 1 To TextBox3.Text.Length
Label3.Text &= CStr(Asc(Mid$(TextBox3.Text, x, 1)))
Next
End Sub
Protected Sub Button5_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button5.Click
Label4.Text = ""
For x As Integer = 1 To Label3.Text.Length
Label4.Text &= Chr(Mid$(Label3.Text, x, 1))
Next
End Sub
Try this out.
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Label3.Text = ""
For x As Integer = 1 To TextBox3.Text.Length
Label3.Text &= CStr(Asc(Mid$(TextBox3.Text, x, 1))) & "|"
Next
End Sub
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button2.Click
Label4.Text = ""
Dim value As Integer = 0
Dim buf As String = ""
For x As Integer = 1 To Label3.Text.Length
If Mid$(Label3.Text, x, 1) <> "|" Then
buf &= Mid$(Label3.Text, x, 1)
Else
Label4.Text &= Chr(Val(buf))
buf = ""
End If
Next
End Sub

Loop through the datalist to get data

I'm stuck in converting the rate in the datalist. My page contain one dropdownlist(currency converter), one datalist - inside contain the price of bags in labels. Now I uses the dropdownlist.selectedIndexchange
Protected Sub ddl_rate_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddl_rate.SelectedIndexChanged
Dim lbl_rate As Label = roomList.Items.Item(0).FindControl("lbl_rate")
Dim a As Integer = Convert.ToInt32(lbl_rate.Text)
If ddl_rate.Text = "Australia Dollars (AUD)" Then
Dim b As Integer = (a * 0.8029)
lbl_rate.Text = b.ToString()
ElseIf ddl_rate.Text = "Brazil Reais (BRL)" Then
Dim b As Integer = (a * 1.3024)
lbl_rate.Text = b.ToString()
End If
Althought it did convert the rate, but it only convert the first row.
Any suggestion?
this is a guess without seeing the rest of the code:
Protected Sub ddl_rate_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddl_rate.SelectedIndexChanged
foreach(c as Control in roomList.Items)
Dim lbl_rate As Label = c.FindControl("lbl_rate")
Dim a As Integer = Convert.ToInt32(lbl_rate.Text)
If ddl_rate.Text = "Australia Dollars (AUD)" Then
Dim b As Integer = (a * 0.8029)
lbl_rate.Text = b.ToString()
ElseIf ddl_rate.Text = "Brazil Reais (BRL)" Then
Dim b As Integer = (a * 1.3024)
lbl_rate.Text = b.ToString()
End If
next

Resources