Page 1 of 1

Posted: Tue Jan 21, 2003 7:27 pm
by BackupUser
Restored from previous forum. Originally posted by ricardo.

Hi,

In my code, when load the window i open my dll in this way

Code: Select all

If OpenLibrary(1, "wavemp3.dll")
              *F = IsFunction(1, "WM_SetCBWindow")
              If *F
                CALLBACK_MSG.l = CallFunctionFast(*F,WindowID(),0,0)
              EndIf
  EndIf
Then iif i call any dll function inside a procedure it does the job but crash when finish

Code: Select all

Procedure Enc()

           *Fenc = IsFunction(1, "WM_WavToMp3")
              If *Fenc
                Resultado.l = CallFunctionFast(*Fenc,Infile,OutFile,128,44100)
                SetGadgetState(5, 0)
              EndIf
ProcedureReturn 1
EndProcedure
BUT if i call the same dll function inside tha main loop of the window as:

Code: Select all

      Case 7 ; Button Clicked
           *Fenc = IsFunction(1, "WM_WavToMp3")
              If *Fenc
                Resultado.l = CallFunctionFast(*Fenc,Infile,OutFile,128,44100)
                SetGadgetState(5, 0)
              EndIf
Its works right and dosent crash... why?

Does anybody knows what are going wrong here?

I want to run every function as a Thread but it crashes too.

Best Regards




Best Regards

Ricardo

Dont cry for me Argentina...

Posted: Tue Jan 21, 2003 7:48 pm
by BackupUser
Restored from previous forum. Originally posted by freak.

Are you sure, you have the correct number of Arguments for your Dll's Functions?
Sounds like a Stack problem to me.

BTW: If you always use IsFunction() before CallFunctionFast(), it is not faster that CallFunction(). Using IsFunction()/CallFunctionFast() makes only sense, if you get the Function Pointer
with IsFunction one Time, and then only call CallFunctionFast() for all calls.

Timo

Posted: Tue Jan 21, 2003 11:05 pm
by BackupUser
Restored from previous forum. Originally posted by ricardo.
Originally posted by freak

Are you sure, you have the correct number of Arguments for your Dll's Functions?
Sounds like a Stack problem to me.
Yes, its the correct number of args.
Outside the procedure it works right.
Thats why i dont get what is going wrong here.
BTW: If you always use IsFunction() before CallFunctionFast(), it is not faster that CallFunction(). Using IsFunction()/CallFunctionFast() makes only sense, if you get the Function Pointer
with IsFunction one Time, and then only call CallFunctionFast() for all calls.

Timo
Ok, thanks for the info.



Best Regards

Ricardo

Dont cry for me Argentina...

Posted: Tue Jan 21, 2003 11:53 pm
by BackupUser
Restored from previous forum. Originally posted by freak.

Sorry, but i have now idea, what the problem might be.

Where can I get this dll from?
I'd like to do some further testing.

If you want to, you can also email me your source code ( [url]mailto:freak@abwesend.de[/url] ), that
would make it even easier.

Timo

Posted: Wed Jan 22, 2003 8:58 am
by BackupUser
Restored from previous forum. Originally posted by fred.

This not another CDECL/STDCALL problem ?

Fred - AlphaSND

Posted: Wed Jan 22, 2003 6:42 pm
by BackupUser
Restored from previous forum. Originally posted by ricardo.

@Freak

All the dlls that uses ACM or lame that i have tried with PB Crashes in some way. In VB run with no problem with similar code.

@Fred

This not another CDECL/STDCALL problem ?

What does it means?
How can i change/modify the calling convention?
Exists a workarround?



Best Regards

Ricardo

Dont cry for me Argentina...

Posted: Wed Jan 22, 2003 7:01 pm
by BackupUser
Restored from previous forum. Originally posted by freak.

If the Dlls use CDECL, you can't use them with PureBasic. It only supports STDCALL Dlls.
I think VB supports both, so that's why you didn't have any problems there.

Timo

Posted: Wed Jan 22, 2003 9:42 pm
by BackupUser
Restored from previous forum. Originally posted by fred.

Yes, but VB can't dream about the call convention, so it has been specified somewhere in the VB header... I could add a function to use CDECL stuff, something like CallFunctionC() and CallFunctionFastC(). If you have other good name for such functions, just tell me :)

Fred - AlphaSND

Posted: Thu Jan 23, 2003 5:01 am
by BackupUser
Restored from previous forum. Originally posted by ricardo.
Originally posted by fred

I could add a function to use CDECL stuff, something like CallFunctionC() and CallFunctionFastC(). If you have other good name for such functions, just tell me :)
Thanks Fred !!!



Best Regards

Ricardo

Dont cry for me Argentina...

Posted: Thu Jan 23, 2003 8:51 am
by BackupUser
Restored from previous forum. Originally posted by fred.

For now, you can still use asm to adjust back the stack (if it's really the problem):

CallFunctionFast(*Fenc,Infile,OutFile,128,44100)
!ADD esp,16

(4 args, each args takes 4 bytes (long) so it's 16 for this function).

Thanks to Danilo to points this out. About the eax stuff, the library is in asm but declared as STDCALL, so it's all on the stack.

Posted: Thu Jan 23, 2003 10:19 am
by BackupUser
Restored from previous forum. Originally posted by Danilo.

Fred, your example has 4 arguments for the DLL only.
First arg is pointer for CallFunctionFast.
And i think first pointer for CallFunctionFast is in EAX anyway... (ASM Lib)

cya,
...Danilo
(registered PureBasic user)