Page 1 of 1

how to use USBPhysic.dll with purebasic.. URGENT!

Posted: Sat Mar 12, 2016 7:05 am
by Deraman
Dear, Please help me in using USBPhysic.dll with Purebasic... I already successfully used with VB6...
Uploading file not possible here! can email you if you need...hard to find on net.... Please quick support...Thanks

USBPhysic_lib.bas

Code: Select all

Attribute VB_Name = "USBPhysic_lib"

Public Declare Function Init Lib "USBPhysic.dll" (ByVal sUser As String, ByVal sRegCode As String) As Long
Public Declare Function GetUSBPhysicInfo Lib "USBPhysic.dll" (ByVal diskIndex As Long, ByVal InfoType As Long, ByVal pHddInfo As String) As Long
VB Form

Code: Select all

Private Sub Command1_Click()
    
    Dim iDiskNo As Long
    Dim sBuffer As String
    Dim iReturn As Long
    If Combo1.ListIndex = -1 Then
      Exit Sub
    End If
    
    sBuffer = Space(1024)  ' make room in the buffer
    iDiskNo = Combo1.ListIndex 'get selected disk number
    ClearEdit
    
    iReturn = GetUSBPhysicInfo(iDiskNo, 0, sBuffer)    '0 = serial number
    Text1.Text = Left(sBuffer, iReturn)
    
    iReturn = GetUSBPhysicInfo(iDiskNo, 1, sBuffer)    '1 = usb product name
    Text2.Text = Left(sBuffer, iReturn)
    
    iReturn = GetUSBPhysicInfo(iDiskNo, 2, sBuffer)    '2 = usb manufacturer
    Text3.Text = Left(sBuffer, iReturn)
    
    iReturn = GetUSBPhysicInfo(iDiskNo, 3, sBuffer)    '3 = usb drive letter mapped on windows
    Text6.Text = Left(sBuffer, iReturn)
                
End Sub

Private Sub Form_Load()
 Dim tDiscs As Long
 Dim intX As Integer
 Dim WinHdd As Integer
 
 tDiscs = Init("your reg name here", "your reg code here")
 
 If tDiscs > 0 Then
   For intX = 0 To tDiscs - 1
     Combo1.AddItem intX
   Next
   
   Combo1.ListIndex = 0
 End If
 
End Sub



Re: how to use USBPhysic.dll with purebasic.. URGENT!

Posted: Sat Mar 12, 2016 8:22 am
by Danilo
Try that with 32-bit PureBasic:

Code: Select all

Prototype.l protoInit(sUser.p-ascii, sRegCode.p-ascii)
Prototype.l protoGetUSBPhysicInfo(diskIndex.l, InfoType.l, *pHddInfo)

Global Init.protoInit
Global GetUSBPhysicInfo.protoGetUSBPhysicInfo

Procedure ComboboxChanged()
    ClearGadgetItems(1)
    iDiskNo = GetGadgetState(0)
    If iDiskNo = -1
        ProcedureReturn
    EndIf
    AddGadgetItem(1,-1,"Info for Drive "+Str(iDiskNo))
    *buffer = AllocateMemory(1024)
    If *buffer
        If GetUSBPhysicInfo
            iReturn = GetUSBPhysicInfo(iDiskNo,0,*buffer) ; 0 = serial number
            AddGadgetItem(1,-1,"Serial number: " + PeekS(*buffer,iReturn,#PB_Ascii))
            iReturn = GetUSBPhysicInfo(iDiskNo,1,*buffer) ; 1 = usb product name
            AddGadgetItem(1,-1,"USB product name: " + PeekS(*buffer,iReturn,#PB_Ascii))
            iReturn = GetUSBPhysicInfo(iDiskNo,2,*buffer) ; 2 = usb manufacturer
            AddGadgetItem(1,-1,"USB manufacturer: " + PeekS(*buffer,iReturn,#PB_Ascii))
            iReturn = GetUSBPhysicInfo(iDiskNo,3,*buffer) ; 3 = usb drive letter mapped on windows
            AddGadgetItem(1,-1,"USB drive letter: " + PeekS(*buffer,iReturn,#PB_Ascii))
        EndIf
        FreeMemory(*buffer)
    EndIf
EndProcedure

Procedure RunGUI(numDiscs)
    If OpenWindow(0,0,0,500,200,"USBPhysics.dll",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
        ComboBoxGadget(0,10,10,80,25)
        If numDiscs
            For i = 0 To numDiscs-1
                AddGadgetItem(0,-1,Str(i))
            Next
        EndIf
        ListViewGadget(1,100,10,390,180)
        BindGadgetEvent(0,@ComboboxChanged(),#PB_EventType_Change)
        Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
    EndIf
EndProcedure

If OpenLibrary(0,"USBPhysic.dll")
    Init             = GetFunction(0,"_Init@8")
    GetUSBPhysicInfo = GetFunction(0,"_GetUSBPhysicInfo@12")
    If Not Init             : Init             = GetFunction(0,"Init@8")              : EndIf
    If Not GetUSBPhysicInfo : GetUSBPhysicInfo = GetFunction(0,"GetUSBPhysicInfo@12") : EndIf
    If Not Init             : Init             = GetFunction(0,"Init")                : EndIf
    If Not GetUSBPhysicInfo : GetUSBPhysicInfo = GetFunction(0,"GetUSBPhysicInfo")    : EndIf
    If Not Init             : Init             = GetFunction(0,"_Init")               : EndIf
    If Not GetUSBPhysicInfo : GetUSBPhysicInfo = GetFunction(0,"_GetUSBPhysicInfo")   : EndIf
    
    If Init And GetUSBPhysicInfo
        tDiscs = Init("your reg name here", "your reg code here")
        RunGUI(tDiscs)
    Else
        MessageRequester("ERROR","Can't get functions inside USBPhysic.dll")
    EndIf
    CloseLibrary(0)
Else
    MessageRequester("ERROR","Can't open USBPhysic.dll")
EndIf

Re: how to use USBPhysic.dll with purebasic.. URGENT!

Posted: Sat Mar 12, 2016 8:51 am
by Deraman
Thanks dear... it partially worked but return nothing in list like usbflash-serial , manufacturer name etc... please help,,, thanks

Re: how to use USBPhysic.dll with purebasic.. URGENT!

Posted: Sat Mar 12, 2016 9:02 am
by Danilo
Hmm.. does VB use Unicode BSTR/OLE-Strings?

Code: Select all

Prototype.l protoInit(sUser.p-Unicode, sRegCode.p-Unicode)
Prototype.l protoGetUSBPhysicInfo(diskIndex.l, InfoType.l, *pHddInfo)

Global Init.protoInit
Global GetUSBPhysicInfo.protoGetUSBPhysicInfo

Procedure ComboboxChanged()
    ClearGadgetItems(1)
    iDiskNo = GetGadgetState(0)
    If iDiskNo = -1
        ProcedureReturn
    EndIf
    AddGadgetItem(1,-1,"Info for Drive "+Str(iDiskNo))
    *buffer = AllocateMemory(1024)
    If *buffer
        If GetUSBPhysicInfo
            iReturn = GetUSBPhysicInfo(iDiskNo,0,*buffer) ; 0 = serial number
            AddGadgetItem(1,-1,"Serial number: " + PeekS(*buffer+4,iReturn,#PB_Unicode))
            AddGadgetItem(1,-1,"Serial number: " + PeekS(*buffer,iReturn,#PB_Unicode))
            iReturn = GetUSBPhysicInfo(iDiskNo,1,*buffer) ; 1 = usb product name
            AddGadgetItem(1,-1,"USB product name: " + PeekS(*buffer+4,iReturn,#PB_Unicode))
            AddGadgetItem(1,-1,"USB product name: " + PeekS(*buffer,iReturn,#PB_Unicode))
            iReturn = GetUSBPhysicInfo(iDiskNo,2,*buffer) ; 2 = usb manufacturer
            AddGadgetItem(1,-1,"USB manufacturer: " + PeekS(*buffer+4,iReturn,#PB_Unicode))
            AddGadgetItem(1,-1,"USB manufacturer: " + PeekS(*buffer,iReturn,#PB_Unicode))
            iReturn = GetUSBPhysicInfo(iDiskNo,3,*buffer) ; 3 = usb drive letter mapped on windows
            AddGadgetItem(1,-1,"USB drive letter: " + PeekS(*buffer+4,iReturn,#PB_Unicode))
            AddGadgetItem(1,-1,"USB drive letter: " + PeekS(*buffer,iReturn,#PB_Unicode))
        EndIf
        FreeMemory(*buffer)
    EndIf
EndProcedure

Procedure RunGUI(numDiscs)
    If OpenWindow(0,0,0,500,200,"USBPhysics.dll",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
        ComboBoxGadget(0,10,10,80,25)
        If numDiscs
            For i = 0 To numDiscs-1
                AddGadgetItem(0,-1,Str(i))
            Next
        EndIf
        ListViewGadget(1,100,10,390,180)
        BindGadgetEvent(0,@ComboboxChanged(),#PB_EventType_Change)
        Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
    EndIf
EndProcedure

If OpenLibrary(0,"USBPhysic.dll")
    Init             = GetFunction(0,"_Init@8")
    GetUSBPhysicInfo = GetFunction(0,"_GetUSBPhysicInfo@12")
    If Not Init             : Init             = GetFunction(0,"Init@8")              : EndIf
    If Not GetUSBPhysicInfo : GetUSBPhysicInfo = GetFunction(0,"GetUSBPhysicInfo@12") : EndIf
    If Not Init             : Init             = GetFunction(0,"Init")                : EndIf
    If Not GetUSBPhysicInfo : GetUSBPhysicInfo = GetFunction(0,"GetUSBPhysicInfo")    : EndIf
    If Not Init             : Init             = GetFunction(0,"_Init")               : EndIf
    If Not GetUSBPhysicInfo : GetUSBPhysicInfo = GetFunction(0,"_GetUSBPhysicInfo")   : EndIf
    
    If Init And GetUSBPhysicInfo
        tDiscs = Init("your reg name here", "your reg code here")
        RunGUI(tDiscs)
    Else
        MessageRequester("ERROR","Can't get functions inside USBPhysic.dll")
    EndIf
    CloseLibrary(0)
Else
    MessageRequester("ERROR","Can't open USBPhysic.dll")
EndIf
Can't test, I'm on Mac.

Re: how to use USBPhysic.dll with purebasic.. URGENT!

Posted: Sat Mar 12, 2016 9:35 am
by Danilo
Using SysAllocStringLen_() is probably more correct:

Code: Select all

Prototype.l protoInit(sUser.p-bstr, sRegCode.p-bstr)
Prototype.l protoGetUSBPhysicInfo(diskIndex.l, InfoType.l, *pHddInfo)

Global Init.protoInit
Global GetUSBPhysicInfo.protoGetUSBPhysicInfo

Procedure ComboboxChanged()
    ClearGadgetItems(1)
    iDiskNo = GetGadgetState(0)
    If iDiskNo = -1
        ProcedureReturn
    EndIf
    AddGadgetItem(1,-1,"Info for Drive "+Str(iDiskNo))
    *buffer = SysAllocStringLen_(0, 1024)
    If *buffer
        If GetUSBPhysicInfo
            iReturn = GetUSBPhysicInfo(iDiskNo,0,*buffer) ; 0 = serial number
            AddGadgetItem(1,-1,"Serial number: " + PeekS(*buffer,iReturn,#PB_Unicode))
            iReturn = GetUSBPhysicInfo(iDiskNo,1,*buffer) ; 1 = usb product name
            AddGadgetItem(1,-1,"USB product name: " + PeekS(*buffer,iReturn,#PB_Unicode))
            iReturn = GetUSBPhysicInfo(iDiskNo,2,*buffer) ; 2 = usb manufacturer
            AddGadgetItem(1,-1,"USB manufacturer: " + PeekS(*buffer,iReturn,#PB_Unicode))
            iReturn = GetUSBPhysicInfo(iDiskNo,3,*buffer) ; 3 = usb drive letter mapped on windows
            AddGadgetItem(1,-1,"USB drive letter: " + PeekS(*buffer,iReturn,#PB_Unicode))
        EndIf
        SysFreeString_(*buffer)
    EndIf
EndProcedure

Procedure RunGUI(numDiscs)
    If OpenWindow(0,0,0,500,200,"USBPhysics.dll",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
        ComboBoxGadget(0,10,10,80,25)
        If numDiscs
            For i = 0 To numDiscs-1
                AddGadgetItem(0,-1,Str(i))
            Next
        EndIf
        ListViewGadget(1,100,10,390,180)
        BindGadgetEvent(0,@ComboboxChanged(),#PB_EventType_Change)
        Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
    EndIf
EndProcedure

If OpenLibrary(0,"USBPhysic.dll")
    Init             = GetFunction(0,"_Init@8")
    GetUSBPhysicInfo = GetFunction(0,"_GetUSBPhysicInfo@12")
    If Not Init             : Init             = GetFunction(0,"Init@8")              : EndIf
    If Not GetUSBPhysicInfo : GetUSBPhysicInfo = GetFunction(0,"GetUSBPhysicInfo@12") : EndIf
    If Not Init             : Init             = GetFunction(0,"Init")                : EndIf
    If Not GetUSBPhysicInfo : GetUSBPhysicInfo = GetFunction(0,"GetUSBPhysicInfo")    : EndIf
    If Not Init             : Init             = GetFunction(0,"_Init")               : EndIf
    If Not GetUSBPhysicInfo : GetUSBPhysicInfo = GetFunction(0,"_GetUSBPhysicInfo")   : EndIf
    
    If Init And GetUSBPhysicInfo
        tDiscs = Init("your reg name here", "your reg code here")
        RunGUI(tDiscs)
    Else
        MessageRequester("ERROR","Can't get functions inside USBPhysic.dll")
    EndIf
    CloseLibrary(0)
Else
    MessageRequester("ERROR","Can't open USBPhysic.dll")
EndIf

Re: how to use USBPhysic.dll with purebasic.. URGENT!

Posted: Sat Mar 12, 2016 2:08 pm
by Deraman
Thanks Dear .... really appreciate you support...
The first code example was okay! I made exe and run as administrator.
Thanks again you are very fast...
Thanks again
deraman

Re: how to use USBPhysic.dll with purebasic.. URGENT!

Posted: Sat Mar 12, 2016 3:57 pm
by infratec

Re: how to use USBPhysic.dll with purebasic.. URGENT!

Posted: Sun Mar 13, 2016 11:23 am
by Deraman
Dear, is it possible to merge this dll file in my code to make single exe ... so my exe will not require this dll file
Thanks
deraman