Jump to content

dllcall wants ptr to callback func.


Recommended Posts

Well, heres a show stopper for me.

How can I get a pointer to a func in my script so i can pass it along in my dllcall?

What I am trying to do is add zip functionality to my script via info-zips dll.

I have a script I wrote that uses 7za.exe but I would rather use the zip32.dll for two reasons.

1. I need to learn this method

2. I think there is greater versatility in the dll.

This is the vb code

' this is the declare in the api.h file in the package

'int   EXPENTRY ZpInit(LPZIPUSERFUNCTIONS lpZipUserFunc);

'-- This Structure Is Used For The ZIP32.DLL Function Callbacks
Public Type ZIPUSERFUNCTIONS
  ZDLLPrnt   As Long        ' Callback ZIP32.DLL Print Function
  ZDLLCOMMENT  As Long      ' Callback ZIP32.DLL Comment Function
  ZDLLPASSWORD As Long      ' Callback ZIP32.DLL Password Function
  ZDLLSERVICE  As Long      ' Callback ZIP32.DLL Service Function
End Type
----------------------------------------------------------------------------

Private Declare Function ZpInit Lib "zip32.dll" _
  (ByRef Zipfun As ZIPUSERFUNCTIONS) As Long '-- Set Zip Callbacks

 -----------------------------------------------------------------------------  
  '-- Set Address Of ZIP32.DLL Callback Functions
  '-- (WARNING!) Do Not Change!!!
  ZUSER.ZDLLPrnt = FnPtr(AddressOf ZDLLPrnt)
  ZUSER.ZDLLPASSWORD = FnPtr(AddressOf ZDLLPass)
  ZUSER.ZDLLCOMMENT = FnPtr(AddressOf ZDLLComm)
  ZUSER.ZDLLSERVICE = FnPtr(AddressOf ZDLLServ)
--------------------------------------------------------------------------- 
 Public Function VBZip32() As Long
    
  Dim retcode As Long
    
  On Error Resume Next '-- Nothing Will Go Wrong :-)
    
  retcode = 0
    
  '-- Set Address Of ZIP32.DLL Callback Functions
  '-- (WARNING!) Do Not Change!!!
  ZUSER.ZDLLPrnt = FnPtr(AddressOf ZDLLPrnt)
  ZUSER.ZDLLPASSWORD = FnPtr(AddressOf ZDLLPass)
  ZUSER.ZDLLCOMMENT = FnPtr(AddressOf ZDLLComm)
  ZUSER.ZDLLSERVICE = FnPtr(AddressOf ZDLLServ)
    
  '-- Set ZIP32.DLL Callbacks
  retcode = ZpInit(ZUSER)
  If retcode = 0 Then
    MsgBox "Zip32.dll did not initialize.  Is it in the current directory " & _
                "or on the command path?", vbOKOnly, "VB Zip"
    Exit Function
  End If

Here's the code I have. Well, it's almost code.

; zip user functions 
$userfunc = "long;long;long;long";callback pointer to func

$zUFunc = DllStructCreate($userfunc)

DllStructSetData($zUFunc, 1, *********);pointer to call back func
DllStructSetData($zUFunc, 2, *********);pointer to call back func
DllStructSetData($zUFunc, 3, *********);pointer to call back func
DllStructSetData($zUFunc, 4, *********);pointer to call back func

$retval = dllcall("zip32.dll","int","ZpInit","long_ptr",*******);

msgbox(4096,"Error ,Return",@error &","&$retval,0)

DllStructDelete($zUFunc)

Any Ideas?

here my 7z script. It creates an archive from Dev-cpp project files.

devzip2.au3

Link to comment
Share on other sites

O.k.,

Someone has to have a way to do this?

Valik oh great one, show us the way.

-Steve

Link to comment
Share on other sites

O.k., 

Someone has to have a way to do this?

Valik oh great one, show us the way.

-Steve

<{POST_SNAPBACK}>

i don't have a link for the thread, but i got some awesome help on setting the system time that may be applicable (even if just as a reference for dll struct and dll calls). do a search for 'setting system time' without the quotes...

***edit***

sorry, being stupid, just click on my name on the left and look at my topics, there's only like 3, and one is the thread in question.

Edited by cameronsdad
Link to comment
Share on other sites

cameronsdad, you mean DllStruct, this is cool, but not give ability for using callback function - i.e. function that repeatedly calls from your main function.

I'm tried to add rtf control to gui - control is works just fine, but I can't read/write data to it without callback fucntion. If this ability will be added to autoit, together with DllStruct this will allow to call virtually any function.

Link to comment
Share on other sites

cameronsdad, you mean DllStruct, this is cool, but not give ability for using callback function - i.e. function that repeatedly calls from your main function.

I'm tried to add rtf control to gui - control is works just fine, but I can't read/write data to it without callback fucntion. If this ability will be added to autoit, together with DllStruct this will allow to call virtually any function.

<{POST_SNAPBACK}>

sorry i'm new to using dll's and apparently completely ignorant of the concept you two are trying to implement...with the dll call i was doing, the necessary pointer was set in the dllcall i believe, and thought that might have been the same for this case.
Link to comment
Share on other sites

This was an issue way back in vb4 before M$ added AddressOf. People used to get around this by writing a dll that would handle the callbacks. I think in a way thats self defeating.

As LazyCat stated,

If this ability will be added to autoit, together with DllStruct this will allow to call virtually any function.

.

A case in point could be the post about the corrupt pdf. Chances are in order to be able to check the integrity of the pdf a callback function to the calling script would be necessary.

I've used Ghostscript to make a pdf merge tool in C++ using wxWidgets. There are at least 2 callbacks that I can remember.

The info-zip dll that I am trying to interface to has 4 callbacks.

I had thought of using zlibwapi.dll but decided against it because it uses streams. That means bin read the source file to a buffer , calc the return buffer size and create it, then stream the source to dll, then binary write the file out from the return buffer when the dll returns it. A bunch harder than sending in some filenames.

I really would like to see some kind of function ptr added to Autoit. :) It would be a good kick in the a** that would allow Autoit to have an even greater advantage in scripting.

Maybe this belong in the Ideas forum instead?

-Steve

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...