Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB How-To
|
VB How-To Ask your "How do I do this with VB?" questions in this forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 5th, 2005, 04:37 AM
Authorized User
 
Join Date: Jun 2005
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default wrote a Linked list , but failed why??

Hello

i have used the following code to write a linked list.
but the code crashes at CopyMemoryRead in ReadDataToStructure.
may i know the reason for the failure of my code!?!?




Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
    (Destination As Any, Source As Any, ByVal Length As Long)
Public Declare Function GetProcessHeap Lib "kernel32" () As Long
Public Declare Function HeapAlloc Lib "kernel32" _
    (ByVal hHeap As Long, ByVal dwFlags As Long, _
    ByVal dwBytes As Long) As Long
Public Declare Function HeapFree Lib "kernel32" _
    (ByVal hHeap As Long, ByVal dwFlags As Long, _
    lpMem As Any) As Long
Public Declare Sub CopyMemoryPut Lib "kernel32" Alias _
    "RtlMoveMemory" (ByVal Destination As Long, _
    Source As Any, ByVal Length As Long)
Public Declare Sub CopyMemoryRead Lib "kernel32" Alias _
    "RtlMoveMemory" (Destination As Any, _
    ByVal Source As Long, ByVal Length As Long)

Public pHead As Long

Public Type struc_ewordptr

    sUserName As String
    sDir As String
    sFileName As String
    pNext As Long

End Type

Public Sub PutDataIntoStructure(ByVal ptr As Long, _
        szdata As String, ByVal ptrNext As Long)
Dim stLL As struc_ewordptr
    stLL.sUserName = szdata
    stLL.pNext = ptrNext
    CopyMemoryPut ptr, stLL, 504
End Sub

Public Sub ReadDataToStructure(ByVal ptr As Long, _
        struct As struc_ewordptr)
Dim stLL As struc_ewordptr
    CopyMemoryRead stLL, ptr, 504
    struct.sUserName = stLL.sUserName
    struct.pNext = stLL.pNext
End Sub

Public Sub ReadLinkedListDataAndFreeMemory()

Dim pLocal As Long
Dim hHeap As Long
Dim stLL As struc_ewordptr
Dim strData As String
    pLocal = pHead
    hHeap = GetProcessHeap()
    Do While pLocal <> 0
        ReadDataToStructure pLocal, stLL
        strData = strData & vbCrLf & stLL.sUserName
        HeapFree hHeap, 0, pLocal
        pLocal = stLL.pNext
    Loop
    MsgBox strData
End Sub
Public Sub CreateLinkedList()
'add three items to list
' get the heap first
    Dim pFirst As Long, pSecond As Long 'local pointers
    Dim hHeap As Long
    Dim str As String

    hHeap = GetProcessHeap()
    'allocate memory for the first and second element
    pFirst = HeapAlloc(hHeap, 0, 504)
    pSecond = HeapAlloc(hHeap, 0, 504)
    If pFirst <> 0 And pSecond <> 0 Then
    'memory is allocated
        str = InputBox("enter the user name")

        PutDataIntoStructure pFirst, str, pSecond
        PutDataIntoStructure pSecond, "Pointers", 0
        pHead = pFirst
    End If
    'put he second element in the list
End Sub


thanks in advance
Sruti





Similar Threads
Thread Thread Starter Forum Replies Last Post
Linked List? pmcizhere Java Basics 2 March 6th, 2008 09:02 PM
Linked LIst Progam in C Peter_APIIT C++ Programming 1 December 1st, 2007 05:16 AM
Linked List Implementation shah123 C# 0 April 17th, 2007 09:20 AM
Linked List....!!! amahja56 C++ Programming 4 April 6th, 2004 01:05 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.