#144169 - 2005-07-22 07:43 PM
Win32 API via COM
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
The following code correctly returns the pid for Kix32.exe.
Code:
break on $iRC=SETOPTION('WrapAtEOL','on') $HABObject = createobject("HBullock.AdminObjects") if vartypename($HABObject) <> "Object" ? "@serror" endif
$GetProcessID = $HABObject.Win32API ("kernel32", "int GetCurrentProcessId()") ? vartypename($GetProcessID) $pid = $GetProcessID.Call ? "pid = " + $pid get $x
I am not an API person, can someone post in this thread a couple API calls that I can use for further testing?
Edited by Howard Bullock (2005-07-22 07:44 PM)
|
Top
|
|
|
|
#144172 - 2005-07-22 09:03 PM
Re: Win32 API via COM
|
Lonkero
KiX Master Guru
   
Registered: 2001-06-05
Posts: 22346
Loc: OK
|
|
Top
|
|
|
|
#144175 - 2005-07-22 09:49 PM
Re: Win32 API via COM
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
I have not yet posted the version on which I am working. I need to work out a few specifics so that it can be used uniformly. The syntax for usage is now different. I also need to add some docs or you will not be able to use it. Give me an hour.
Edited by Howard Bullock (2005-07-22 09:50 PM)
|
Top
|
|
|
|
#144176 - 2005-07-22 10:36 PM
Re: Win32 API via COM
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
The new DLL has been posted. http://home.comcast.net/~habullock/habobjects.htm
The online docs have not yet been updated. I have one API call working in the code below. The second example was an attempt to use Chris' cursor control but I can not get it to work. The third example 'GetTempPath' return the length of the TEMP path but does not replace the value of $buffer. I think this may be a limitation of KiXtart. I tested with 4.50.
Code:
break on $iRC=SETOPTION('WrapAtEOL','on') $HABObject = createobject("HBullock.AdminObjects") if vartypename($HABObject) <> "Object" ? "@serror" endif ;Docs: ; ;You need to pass 4 parameters: ; 1. The name of the library from which you want to import the function. ; 2. The name of the function (as exported by the library). ; 3. The number and types of the arguments the function expects as input. ; 4. The type of the value returned by the function. ; ;Parameters 3 and 4 follow: ; I: value is an integer (int) ; N: value is a number (long) ; F: value is a floating point number (float) ; D: value is a double precision number (double) ; C: value is a char (char) ; P: value is a pointer (to a string, structure, etc) ; ;Parameter 4 could also be V for void ; ;$GetProcessID = $HABObject.Win32API ("kernel32", "GetCurrentProcessId", "", "I" ) ; kernel32 is name of library ; GetCurrentProcessId is name of function ; There are no input paramters ; The function returns an integer ;This works great. ------------------ $GetProcessID = $HABObject.Win32API ("kernel32", "GetCurrentProcessId", "", "I" ) ? vartypename($GetProcessID) $pid = $GetProcessID.Call ? "pid = " + $pid ? ;This does nothing that I can see. Maybe the values are wrong. ; ;------------------------------------------------------------ $LoadCursorA=$HABObject.Win32API("USER32.DLL", "LoadCursor", "IN", "P") ; there are 2 input parameters ("IN" Integer and Long) ; returns a pointer This might be a problem in KiXtart but the next line shows an object ? "Handle = " + vartypename($LoadCursorA) $SetCursor=$HABObject.Win32API("USER32.DLL", "SetSystemCursor", "PN", "N") ? "SetCursor = " + vartypename($SetCursor) $CursorHandle = $LoadCursorA.Call(0, 32514) $result = $SetCursor.Call( $CursorHandle, 32512) ? @Serror sleep 5 $CursorHandle = $LoadCursorA.Call(0, 32514) $result = $SetCursor.Call( $CursorHandle, 32512) ? @serror ; this does not appear to work because $buffer should behave as a pointer. ; but the function does not replace the content of $buffer -------------------------------------------------------------------------- $GetTempPath = $HABObject.Win32API('kernel32', 'GetTempPath', 'NP', 'N') for $x=1 to 80 $buffer = " " + $buffer next $result = $GetTempPath.Call(80, $buffer) ? "result = " + $result ? "buffer = (" + len($buffer)+ ") " + $buffer
Edited by Howard Bullock (2005-07-22 10:37 PM)
|
Top
|
|
|
|
#144177 - 2005-07-22 10:40 PM
Re: Win32 API via COM
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
The name of the function must be written exactly as it is exported by the library (case is significant here). If you are using Windows 95 or NT 4.0, you can use the Quick View command on the DLL file to see the function it exports. Remember that you can only import functions from 32 bit DLLs: in Quick View, the file's characteristics should report somewhere ``32 bit word machine''; as a rule of thumb, when you see that all the exported functions are in upper case, the DLL is a 16 bit one and you can't use it. If their capitalization looks correct, then it's probably a 32 bit DLL.
Also note that many Win32 APIs are exported twice, with the addition of a final A or W to their name, for - respectively - the ASCII and the Unicode version. When a function name is not found, Win32::API will actually append an A to the name and try again; if the extension is built on a Unicode system, then it will try with the W instead. So our function name will not include the trailing "A" or "W".
Edited by Howard Bullock (2005-07-23 12:40 AM)
|
Top
|
|
|
|
#144178 - 2005-07-22 10:46 PM
Re: Win32 API via COM
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
I also have Clipboard object in the new DLL.
http://search.cpan.org/~jdb/libwin32-0.24/Clipboard/Clipboard.pm
Code:
$Clip = $HABObject.ClipBoard ? "IsText = " + $Clip.IsText ? "IsFiles = " + $Clip.IsFiles ? "IsBitMap = " + $Clip.IsBitMap
;view Clipboard contents Select case $Clip.IsText $text = $Clip.GetText ? "ClipBoard contains text: " + $text
case $Clip.IsFiles $files = $Clip.List.GetFiles ? "ClipBoard contains these files: " for each $file in $files ? " " + $file next
case $Clip.IsBitMap $image = $Clip.GetBitmap ; not sure what to do with this item.
Endselect
$Clip.Set("Put some text into the clipboard!")
|
Top
|
|
|
|
#144179 - 2005-07-22 10:49 PM
Re: Win32 API via COM
|
Chris S.
MM club member
   
Registered: 2002-03-18
Posts: 2368
Loc: Earth
|
Do I see HABForms in the future?
|
Top
|
|
|
|
#144180 - 2005-07-23 08:47 PM
Re: Win32 API via COM
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
Anyone give this a try yet? Any API's that you got to work that seem interesting?
|
Top
|
|
|
|
#144182 - 2006-09-21 04:59 AM
Re: Win32 API via COM
|
cj
MM club member
   
Registered: 2000-04-06
Posts: 1102
Loc: Brisbane, Australia
|
So i'm trawling the korg forums admiring the golf scores and I saw this gem: 'Did you read all of the thread Howard linked to. His DLL has the ability to expose API calls in other DLLs that do not have COM automation.'
sweet!! I DL'd and had a play, this is really cool! Example code on the front page has a little error 
To use the DLL first create an object for the DLL: Code:
$HABObject = createobject("HBullock.AdminObjects") if vartypename($HABObject1) <> "Object" ? "@serror" endif
first line should read $HABObject1 = createobject("HBullock.AdminObjects")
this is some great work howard!
cj
|
Top
|
|
|
|
Moderator: Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 2366 anonymous users online.
|
|
|