Need help calling a DLL

Just starting out? Need help? Post your questions and find answers here.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by ricardo.

Hi,
I tried to call one DLL in PB but always crashing.
In VB i succesfully cal it by:

Code: Select all

Public Enum EncodeMode
    BE_MP3_MODE_STEREO = 0
    BE_MP3_MODE_JSTEREO = 1
    BE_MP3_MODE_DUALCHANNEL = 2
    BE_MP3_MODE_MONO = 3
End Enum

Public Declare Function EncodeMp3 Lib "MP3Enc.dll" (ByVal lpszWavFile As String, ByVal lpszOutFile As String, ByVal BitRate As Long, ByVal SampleRate As Long, ByVal EncMode As EncodeMode, lpCallback As Any) As Long

Public Function EnumEncoding(ByVal nStatus As Integer) As Boolean
        
    If frmMain.pb1.Value  nStatus Then
        frmMain.lblPercent.Caption = nStatus & "%"
        frmMain.pb1.Value = nStatus
    End If
    
End Function

ret = EncodeMp3(txtFile.Text, txtOutput.Text, Val(cmbBitrate.Text), SampleRate, Mode, AddressOf EnumEncoding)

AND IT WORKS FINE WITHOUT ANY PROBLEM.
In PB i tried by this way:

Procedure.l EnumEncoding(nStatus.l)
SetGadgetText(1,Str(nStatus))
EndProcedure

Code: Select all


#BE_MP3_MODE_STEREO = 0
#BE_MP3_MODE_JSTEREO = 1
#BE_MP3_MODE_DUALCHANNEL = 2 
#BE_MP3_MODE_MONO = 3 

Infile.s ="c:\windows\escritorio\1_Sweet.wav"
OutFile.s = "c:\windows\escritorio\1_SweetPB.Mp3"
BitRate.l = 128
SampleRate.l =   44100
Mode.b=#BE_MP3_MODE_STEREO

If OpenLibrary(0, "MP3Enc.dll")
              *F = IsFunction(0, "EncodeMp3")
              If *F
                Result.l = CallFunctionFast(*F,Infile,OutFile,BitRate,SampleRate,Mode,@EnumEncoding())
              EndIf
              CloseLibrary(0)
              MessageRequester("Result",Str(Result),0)
          EndIf
And this DOSENT WORKS!!

Any idea for solve this situation?

Thanks in advance!!




Best Regards

Ricardo

Dont cry for me Argentina...
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by tinman.
Originally posted by ricardo

Procedure.l EnumEncoding(nStatus.l)
nStatus should be a .w I think?



--
It's not minimalist - I'm increasing efficiency by reducing input effort.
(Win98first ed. + SP1, PB3.40)
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by ricardo.
nStatus should be a .w I think?
I tried too. In fact the declaration is AS ANY, but i tried long, string, word, etc.

I think that the problem is on the MODE or on the callback.

If i call it like this @Mode then dont crash and return an "wrong arguments" failure.

Code: Select all

CallFunctionFast(*F,Infile,OutFile,BitRate,Samplerate,@Mode,@EnumEncoding())
I think that is the callback (i tried to send @MyVar and receive the value in a var too) because it runs a few seconds and then crash as if crash when sending a return value.




Best Regards

Ricardo

Dont cry for me Argentina...
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by freak.

I think this is the Problem:

Mode.b=#BE_MP3_MODE_STEREO

try:

Mode.l=#BE_MP3_MODE_STEREO ;<--- Long

I think that because: 'EncMode As EncodeMode' in VB just means, that EncMode is one of these Constant values, it doesn't say of which type.

Usually, if no type is given, it is Long.

I'm not shure, just try it.

The Callback thing should be ok the way you've done it.

Timo
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by ricardo.
try:
Mode.l=#BE_MP3_MODE_STEREO ;<--- Long
Hi,

Dosent works : )
I put Mode.b because iv tried ecery way possible (even word, pointer, etc) and cant make it run and in VB it runs smoothly.

In PB its creates the OutFile but crashes and the file is void.




Best Regards

Ricardo

Dont cry for me Argentina...
Post Reply