Trainee
Date of registration: Mar 13th 2009
Location: Oberirsen - Germany
Occupation: Senior Software Engineer
Hobbies: Programming aund Photography
Jabaco Source |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
Private WinAPI Sub RtlMoveMemory Lib "kernel32.dll" _ (ByVal Destination As Long, ByVal Source As Long, ByVal Length As Long) Public Sub CopyMemory(ByVal Source As Long, ByVal Destination As Long, _ ByVal Length As Long) RtlMoveMemory Destination, Source, Length End Sub Private WinAPI Function MessageBox Lib "user32.dll" _ Alias "MessageBoxA" (ByVal hwnd As Long, ByVal lpText As Long, _ ByVal lpCaption As Long, ByVal wType As Long) As Long Public Sub Command1_Click() '-Begin----------------------------------------------------------------- Dim VarPtr As New VarPtr() VarPtr.Init '-An example with byte variable and WinAPI CopyMemory----------------- Dim a1, a2 As Long a1 = VarPtr.CreateVar("Test1", "Byte", 0) java#lang#System.out.println "Address a1: " & Str(a1) VarPtr.SetByteVar "Test1", 42 java#lang#System.out.println "Variable Test1: " & _ Str(VarPtr.GetByteVar("Test1")) a2 = VarPtr.CreateVar("Test2", "Byte", 0) java#lang#System.out.println "Address a1: " & Str(a2) java#lang#System.out.println "Variable Test2: " & _ Str(VarPtr.GetByteVar("Test2")) CopyMemory a1, a2, 1 java#lang#System.out.println "Variable Test2 nach CopyMemory: " & _ Str(VarPtr.GetByteVar("Test2")) '-An example with string variable and WinAPI MessageBox---------------- Dim a3, a4 As Long a3 = VarPtr.CreateVar("strTest", "String", 32) java#lang#System.out.println "Address a3: " & Str(a3) VarPtr.SetStringVar "strTest", "Dies ist ein Test" MessageBox 0, a3, 0, 0 java#lang#System.out.println VarPtr.GetStringVar("strTest") java#lang#System.out.println VarPtr.GetVarType("Test2") java#lang#System.out.println VarPtr.GetVarType("strTest") VarPtr.DestroyVar "Test1" VarPtr.DestroyVar "Test2" VarPtr.DestroyVar "strTest" VarPtr.UnInit '-End------------------------------------------------------------------- End Sub |
This post has been edited 3 times, last edit by "StefanSchnell" (May 24th 2009, 9:07am)
Intermediate
Date of registration: Jan 1st 2009
Location: Hanover, Germany
Occupation: Software Engineer
Hobbies: Hilbert Curves
This post has been edited 1 times, last edit by "A1880" (Jun 4th 2009, 11:17am)
Trainee
Date of registration: Mar 13th 2009
Location: Oberirsen - Germany
Occupation: Senior Software Engineer
Hobbies: Programming aund Photography
This post has been edited 1 times, last edit by "StefanSchnell" (May 11th 2009, 11:54pm)
Trainee
Date of registration: Mar 13th 2009
Location: Oberirsen - Germany
Occupation: Senior Software Engineer
Hobbies: Programming aund Photography
This post has been edited 1 times, last edit by "StefanSchnell" (Aug 2nd 2009, 7:49am)
Trainee
Date of registration: Mar 13th 2009
Location: Oberirsen - Germany
Occupation: Senior Software Engineer
Hobbies: Programming aund Photography
Quoted
Only the names of a few methods are different, because Jabaco and Java use different type names, e.g. Short vs. Integer, Integer vs. Long and Float vs. Single
Trainee
Date of registration: Mar 13th 2009
Location: Oberirsen - Germany
Occupation: Senior Software Engineer
Hobbies: Programming aund Photography
Trainee
Date of registration: Mar 16th 2009
Location: Perth, WA, Australia
Occupation: Software/Test Engineer
Hobbies: be a husband and a dad, play ukulele, sing
I've been playing with it, but am confused about something: most of your demos are using the *A form of Win32 API calls. Can you show me one which passes a string into a *W function, like GetFileAttributesW. I want to use the *W form because I'm dealing with filenames in Chinese.Hello community,
you can download a new advanced version of VarPtr here or from the attachment.
Cheers
Stefan
Trainee
Date of registration: Mar 13th 2009
Location: Oberirsen - Germany
Occupation: Senior Software Engineer
Hobbies: Programming aund Photography
Jabaco Source |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
Private WinAPI Function MessageBox Lib "user32.dll" _ Alias "MessageBoxW" (ByVal hwnd As Long, ByVal lpText As Long, _ ByVal lpCaption As Long, ByVal wType As Long) As Long Private WinAPI Function FromUniCode Lib "kernel32.dll" _ Alias "WideCharToMultiByte" (ByVal CodePage As Long, ByVal dwFlags As Long, _ ByVal lpWideCharStr As Long, ByVal cchWideChar As Long, _ ByVal lpMultiByteStr As Long, ByVal cchMultiByte As Long, _ ByVal lpDefaultChar As String, ByVal lpUsedDefaultChar As Long) As Long Private WinAPI Function ToUniCode Lib "kernel32.dll" _ Alias "MultiByteToWideChar" (ByVal CodePage As Long, ByVal dwFlags As Long, _ ByVal lpMultiByteStr As Long, ByVal cchMultiByte As Long, _ ByVal lpWideCharStr As Long, ByVal cchWideChar As Long) As Long Const CP_ACP As Long = 0 Public Sub Command1_Click() '-Begin----------------------------------------------------------------- Dim VarPtr As New VarPtr() VarPtr.Init '-An example with string variable and WinAPI MessageBoxW-------------- Dim strTest, lenTest As Long Dim Text As String Text = "I am MessageBoxW" strTest = VarPtr.CreateVar("strTest", "String", 32) VarPtr.SetStringVar "strTest", Text + Chr(0) strUniTest = VarPtr.CreateVar("strUniTest", "String", Len(Text) + 2) ToUniCode CP_ACP, 0, strTest, -1, strUniTest, Len(Text) + 2 MessageBox 0, strUniTest, 0, 0 VarPtr.DestroyVar "strTest" VarPtr.DestroyVar "strUniTest" VarPtr.UnInit '-End------------------------------------------------------------------- End Sub |
Trainee
Date of registration: Mar 13th 2009
Location: Oberirsen - Germany
Occupation: Senior Software Engineer
Hobbies: Programming aund Photography
Trainee
Date of registration: Mar 13th 2009
Location: Oberirsen - Germany
Occupation: Senior Software Engineer
Hobbies: Programming aund Photography
This post has been edited 5 times, last edit by "StefanSchnell" (Mar 25th 2010, 12:38pm)
Jabaco Source |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
Option Explicit Private Declare Function MessageBox Lib "user32.dll" Alias "MessageBoxW" ( _ ByVal hhwnd As Long, _ ByVal lpText As Long, _ ByVal lpCaption As Long, _ ByVal wType As Long _ ) As Long Public Sub Command1_Click() Dim txt As String: txt = "this is the text. Quick brown fox jumps over the lazy dog" Dim cap As String: cap = "this is the caption" Dim pTxt As Long: pTxt = StrPtr(txt) Dim pCap As Long: pCap = StrPtr(cap) Dim mr As VbMsgBoxResult mr = MessageBox(0, pTxt, pCap, vbOKCancel) MessButton (mr) mr = MessageBox(0, pTxt, pCap, vbYesNoCancel) MessButton (mr) End Sub Public Sub MessButton(mr As VbMsgBoxResult) Dim s As String: s = "You clicked: " Select Case mr Case vbOK: s = s & "OK" Case vbYes: s = s & "Yes" Case vbNo: s = s & "No" Case vbCancel: s = s & "Cancel" End Select MsgBox s End Sub |
Jabaco Source |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
Option Explicit Private Winapi Function MessageBox Lib "user32.dll" Alias "MessageBoxA" ( _ ByVal hwnd As Long, _ Byval lpText As Long, _ ByVal lpCaption As Long, _ ByVal wType As Long _ ) As Long Public Sub Command1_Click() Dim txt As String: txt = "this is the text it is a bit long here the quick brown fox jumps over the lazy dog" Dim cap As String: cap = "this is the caption" Dim pTxt As Long: pTxt = StrPtr(txt) Dim pCap As Long: pCap = StrPtr(cap) Dim mr As VBMsgBoxResult mr = MessageBox(0, pTxt, pCap, vbOKCancel) MessButton(mr) mr = MessageBox(0, pTxt, pCap, vbOKCancel) MessButton(mr) MVarPtr.ClearVarPtr End Sub Public Sub MessButton(mr As VBMsgBoxResult) Dim s As String = "You clicked: " Select Case mr Case vbOK: s = s & "OK" Case vbYes: s = s & "Yes" Case vbNo: s = s & "No" Case vbCancel: s = s & "Cancel" End Select MsgBox s End Sub |
Jabaco Source |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
Option Explicit Private myVarPtr As New VarPtr Private myVars As New Collection Public Sub InitVarPtr() myVarPtr.Init End Sub Public Sub ClearVarPtr() Dim s As String For Each s In myVars myVarPtr.ClearVar s Next End Sub Public Function StrPtr(v As VBVariant) As Long Dim name As String = v.hashCode myVars.Add name If v.isString Then StrPtr = myVarPtr.CreateVar(name, "String", Len(v)) myVarPtr.SetStringVar(name, v) End If End Function |
This post has been edited 1 times, last edit by "OlimilO" (Mar 28th 2010, 12:16pm)
Trainee
Date of registration: Mar 13th 2009
Location: Oberirsen - Germany
Occupation: Senior Software Engineer
Hobbies: Programming aund Photography
Trainee
Date of registration: Mar 13th 2009
Location: Oberirsen - Germany
Occupation: Senior Software Engineer
Hobbies: Programming aund Photography