|
-
March 7th, 2007, 08:38 AM
#1
VB 6 API Programming
I would like to design the program in VB 6.0 for the following activity:
1) open the Excel file
2) Read the API function name, required parameters value.
3) Call the API
4) Store the result in other excel file.
Is it possible with VB 6.0?
Please help.
-
March 7th, 2007, 09:10 AM
#2
Re: VB 6 API Programming
hello,
1) open the Excel file
2) Read the API function name, required parameters value.
3) Call the API
4) Store the result in other excel file.
I hardly understand (just guess... without being quite sure)
1) what does "open the Excel file" mean ? would it be "open an existing and known excel File ?
2) When tou say " Read the API function name, required parameters value",; what do you exactly mean ? Read from where ?
-
March 7th, 2007, 09:31 AM
#3
Re: VB 6 API Programming
If you are talking about the API calls being held in an Excel file, then no, you cannot. You cannot add and subtract code from an EXE during runtime.
If you desire to write a log file, that is very simply done, but why you would use Excel for that, I don't know. Do some searching in the forums. Plenty of code is provided to help you work with Excel.
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
March 7th, 2007, 12:30 PM
#4
Re: VB 6 API Programming
 Originally Posted by PeejAvery
You cannot add and subtract code from an EXE during runtime.
True, but you can dynamically load and call procedures within DLLs.
Use LoadLibrary to load the dll, GetProcAddress to get the address of the function, and, at it's most simple use CallWindowProc to call the function: Example at AllAPI.net
You're limited to 4 parameters using CallWindowProc and I'm not sure passing 0& to unused parameters is completely safe, but you can circumvent this by using SoftCircuits' CallPtr dll:
Code:
Private Declare Function FreeLibrary Lib "kernel32" ( _
ByVal hLibModule As Long) As Long
Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" ( _
ByVal lpLibFileName As String) As Long
Private Declare Function GetProcAddress Lib "kernel32" ( _
ByVal hModule As Long, ByVal lpProcName As String) As Long
Private Declare Function CallAPI Lib "CALLPTR.DLL" Alias "scCallPtr" ( _
ByVal pProc As Long) As Long
Private Declare Function CallAPIWithArgs2 Lib "CALLPTR.DLL" Alias "scCallPtr" ( _
ByVal pProc As Long, ByVal arg1 As Any, ByVal arg2 As Any) As Long
Private Sub Command1_Click()
Dim hLib As Long, hProc As Long
hLib = LoadLibrary("user32")
hProc = GetProcAddress(hLib, "SetWindowTextA")
Debug.Print CallAPIWithArgs2(hProc, Me.hWnd, "Test")
hProc = GetProcAddress(hLib, "GetDesktopWindow")
Debug.Print CallAPI(hProc)
FreeLibrary hLib
End Sub
-
March 7th, 2007, 01:16 PM
#5
Re: VB 6 API Programming
 Originally Posted by bushmobile
True, but you can dynamically load and call procedures within DLLs.
Ah yes. How could I forget that.
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
March 7th, 2007, 06:08 PM
#6
Re: VB 6 API Programming
There is also a pure VB way of doing that:
http://www.planet-source-code.com/vb...32873&lngWId=1
Nifty piece of code lets you put DLLs wherever and call their functions, not just force them into the system32 directory or add to the PATH environment variable.
I've only tested it with a DLL that takes two strings as it's parameters, but that works perfectly.
-
March 8th, 2007, 02:44 AM
#7
Re: VB 6 API Programming
Thanks Bushmobile.
you got it right what I actually want to say.
Still SoftCircuits' CallPtr.dll having limitation i.e. you cannot use a string
argument here because Visual Basic converts strings to ANSI when calling DLL functions.
Some functions which I need to call requires string parametr then how to tackle this problem.
PeejAvery:
"you can dynamically load and call procedures within DLLs."
Plesae tell me how to do this. Code sample will be very helpful.
-
March 8th, 2007, 04:00 AM
#8
Re: VB 6 API Programming
 Originally Posted by g_bhujbal
Thanks Bushmobile.
you got it right what I actually want to say.
Still SoftCircuits' CallPtr.dll having limitation i.e. you cannot use a string
argument here because Visual Basic converts strings to ANSI when calling DLL functions.
I used a string in my example.
 Originally Posted by g_bhujbal
PeejAvery:
"you can dynamically load and call procedures within DLLs."
Plesae tell me how to do this. Code sample will be very helpful.
he was quoting me, and i demonstrated it in my post, also check out ChaosTheEternal's post
@ChaosTheEternal: nice link!
-
March 8th, 2007, 08:51 AM
#9
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|