Author Topic: Bass.dll problem  (Read 1495 times)

ragdog

  • Member
  • ****
  • Posts: 572
Bass.dll problem
« on: December 03, 2017, 03:34:32 AM »
Hello

I playing with the Bass.dll from un4seen.com all works fine if i run my code in a (exe project)
If i run my code in a (Dll project) it does not works.

I have debug my code LoadLibrary and GetProcadress all works fine it have a poblem with BASS_Init procedur
And can not debug this Proc.

Has any same problem?


Code: [Select]
.data?
hBassDll dd ?
pBASS_Init dd ?
pBASS_StreamCreateFile dd ?
pBASS_ChannelPlay dd ?

invoke LoadLibrary, chr$("bass24100.dll")
.if (eax)
mov hBassDll,eax
invoke GetProcAddress,hBassDll,chr$("BASS_Init")
.if (eax)
mov pBASS_Init,eax
push 0
push hWnd
push 0
push 44100
push -1
call dword ptr [pBASS_Init] ;<<<<<<<<<<<<<
.if (eax)
invoke GetProcAddress,hBassDll,chr$("BASS_StreamCreateFile")
.if (eax)
mov pBASS_StreamCreateFile,eax
push 0
push dword ptr [qwSize+4]
push dword ptr [qwSize]
push dword ptr [qwSize+4]
push dword ptr [qwSize]
push chr$ ("music.mp3")
push FALSE
call dword ptr [pBASS_StreamCreateFile]
.if (eax)
mov ebx,eax
invoke GetProcAddress,hBassDll,chr$("BASS_ChannelPlay")
.if (eax)
mov pBASS_ChannelPlay,eax

push 0
push ebx
call dword ptr [pBASS_ChannelPlay]
.endif
.endif
.endif
.endif
.endif
.endif

felipe

  • Member
  • ****
  • Posts: 867
  • Eagles are just great!
Re: Bass.dll problem
« Reply #1 on: December 03, 2017, 05:56:04 AM »
 :idea:

Maybe you need to put more information here for get help. I mean you can't debug the proc, but where is the source code of the proc?


If not available maybe you need to get information from that proc (assuming is a proc from the Bass.dll) with some tool.

Felipe.

fearless

  • Member
  • ***
  • Posts: 333
    • LetTheLightIn
Re: Bass.dll problem
« Reply #2 on: December 03, 2017, 06:05:54 AM »
Is the resource (music file) stored in the compiled dll? if so then you probably need to use findresource, lockresource etc to use it when loading it from the dll itself, otherwise resources loaded will use the hInstance of the main program that uses the dll, and look for the resource in the main program and not in the dll resources. I think.
fearless

CM690II Case, HX1000 PSU, Asus Z97, Intel i7-4790K, Seidon 120v Cooler, 16GB DDR3, MSI GTX 980TI

www.LetTheLight.in  My Github  Twitter

ragdog

  • Member
  • ****
  • Posts: 572
Re: Bass.dll problem
« Reply #3 on: December 03, 2017, 06:38:56 AM »
Hi thanks for trying to help

Quote
Maybe you need to put more information here for get help. I mean you can't debug the proc, but where is the source code of the proc?


If not available maybe you need to get information from that proc (assuming is a proc from the Bass.dll) with some tool.

This is my source code of the proc i cannot debug this bass dll correctly in hangs in bass_init by directsound and my debugger works any more.


@fear
i use not a resource file i load from a path.
The music file load ok but before i load the music must i initialize the bass with BASS_Init
If i have a  exe project works all fine but not by a dll project.

AW

  • Member
  • *****
  • Posts: 1357
  • Let's Make ASM Great Again!
Re: Bass.dll problem
« Reply #4 on: December 03, 2017, 07:34:24 AM »
I don't see any procedure. I see sparse code.
If that sparse code is called in the entry point it is guaranteed to freeze.

ragdog

  • Member
  • ****
  • Posts: 572
Re: Bass.dll problem
« Reply #5 on: December 03, 2017, 07:46:52 AM »
The code works fine i have make test in a exe aplication
and it give not any procdur or should I now make a procdedur like xyz

xyz proc
Bass int code
and play mp3
xyz endp

 I said allready in my exe project and test works fine but not in a dll project Bass_init is fail.

nidud

  • Member
  • *****
  • Posts: 1529
    • https://github.com/nidud/asmc
Re: Bass.dll problem
« Reply #6 on: December 03, 2017, 08:09:33 AM »
If I insert this code into WinMain() it loads just fine:
Code: [Select]
_CType equ <stdcall>

include windows.inc

BASSInitT typedef proto :SINT, :DWORD, :DWORD, :HWND, :ptr

    .code

WinMain proc hInstance:HINSTANCE, hPrevInstance:HINSTANCE, lpCmdLine:LPSTR, nShowCmd:SINT

    LOCAL wc:WNDCLASSEX
    LOCAL msg:MSG
    LOCAL hwnd:HANDLE
    LOCAL BASSInit:ptr BASSInitT

    mov wc.cbSize,SIZEOF WNDCLASSEX
    mov wc.style,CS_HREDRAW or CS_VREDRAW
    mov eax,OFFSET WndProc
    mov wc.lpfnWndProc,eax

    xor eax,eax
    mov wc.cbClsExtra,eax
    mov wc.cbWndExtra,eax
    mov ecx,hInstance
    mov wc.hInstance,ecx
    mov wc.hbrBackground,COLOR_WINDOW+1
    mov wc.lpszMenuName,eax

    mov wc.lpszClassName,@CStr("WndClass")
    mov wc.hIcon,LoadIcon(0,IDI_APPLICATION)
    mov wc.hIconSm,eax
    mov wc.hCursor,LoadCursor(0,IDC_ARROW)

    RegisterClassEx(&wc)

    mov eax,CW_USEDEFAULT
    mov hwnd,CreateWindowEx(0,"WndClass","Window",WS_OVERLAPPEDWINDOW,
        eax,eax,eax,eax,0,0,hInstance,0)

    ShowWindow(hwnd,SW_SHOWNORMAL)
    UpdateWindow(hwnd)

    .if LoadLibrary("bass.dll")
        .if GetProcAddress(eax,"BASS_Init")
            mov BASSInit,eax
            .if BASSInit(-1, 44100, 0, hwnd, 0)
                MessageBox(NULL, "OK", "BASS_Init", MB_OK)
            .endif
        .endif
    .endif

    .while GetMessage(&msg,0,0,0)

        TranslateMessage(&msg)
        DispatchMessage(&msg)
    .endw

    mov eax,msg.wParam
    ret

WinMain ENDP

WndProc PROC hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM

    .if uMsg == WM_DESTROY

        PostQuitMessage(0)
        xor eax,eax
    .else
        DefWindowProc(hWnd, uMsg, wParam, lParam)
    .endif
    ret

WndProc ENDP

    END

Same in 64-bit
Code: [Select]
include windows.inc

BASSInitT typedef proto :SINT, :DWORD, :DWORD, :HWND, :ptr

    .win64: rbp
    .code

WinMain PROC hInstance: HINSTANCE,
     hPrevInstance: HINSTANCE,
         lpCmdLine: LPSTR,
          nShowCmd: SINT

    LOCAL wc:WNDCLASSEX
    LOCAL msg:MSG
    LOCAL hwnd:HANDLE
    LOCAL Bass:ptr BASSInitT

    mov wc.cbSize,SIZEOF WNDCLASSEX
    mov wc.style,CS_HREDRAW or CS_VREDRAW
    mov rax,OFFSET WndProc
    mov wc.lpfnWndProc,rax

    xor rax,rax
    mov wc.cbClsExtra,eax
    mov wc.cbWndExtra,eax
    mov wc.hInstance,rcx
    mov wc.hbrBackground,COLOR_WINDOW+1
    mov wc.lpszMenuName,rax

    lea rax,@CStr("WndClass")
    mov wc.lpszClassName,rax
    mov wc.hIcon,LoadIcon(0,IDI_APPLICATION)
    mov wc.hIconSm,rax
    mov wc.hCursor,LoadCursor(0,IDC_ARROW)

    RegisterClassEx(&wc)

    mov eax,CW_USEDEFAULT
    mov hwnd,CreateWindowEx(0,"WndClass","Window",WS_OVERLAPPEDWINDOW,
        eax,eax,eax,eax,0,0,hInstance,0)

    ShowWindow(hwnd,SW_SHOWNORMAL)
    UpdateWindow(hwnd)

    .if LoadLibrary("bass.dll")
        .if GetProcAddress(rax,"BASS_Init")
            mov Bass,rax
            .if Bass(-1, 44100, 0, hwnd, 0)

                MessageBox(NULL, "OK", "BASS_Init", MB_OK)
            .endif
        .endif
    .endif

    .while GetMessage(&msg,0,0,0)

        TranslateMessage(&msg)
        DispatchMessage(&msg)
    .endw

    mov rax,msg.wParam
    ret

WinMain ENDP

    .win64: rsp nosave

WndProc PROC hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM

    .if edx == WM_DESTROY

        PostQuitMessage(0)
        xor rax,rax
    .else
        DefWindowProc(rcx, edx, r8, r9)
    .endif
    ret

WndProc ENDP

    END

ragdog

  • Member
  • ****
  • Posts: 572
Re: Bass.dll problem
« Reply #7 on: December 03, 2017, 08:16:27 AM »
Yes works fine in WinMain proc oder DlgMain Proc called by DialogBoxParam
But my dll call this in a DllEntry

The sdk help from Bass say

Quote
BOOL BASS_Init(
    int device,
    DWORD freq,
    DWORD flags,
    HWND win,
    GUID *clsid

win The application's main window... 0 = the desktop window (use this for console applications). 
);

i have change in Bass_Init remove hWnd to NULL for desktop
Code: [Select]
push 0
push    0;hWnd  <<
push 0
push 44100
push -1
call dword ptr [pBASS_Init] ;<<<<<<<<<<<<<

but is same fail

ps: nidud
is this a hjwasm code?

nidud

  • Member
  • *****
  • Posts: 1529
    • https://github.com/nidud/asmc
Re: Bass.dll problem
« Reply #8 on: December 03, 2017, 08:44:29 AM »
win The application's main window... 0 = the desktop window (use this for console applications). 
);

Yes, it loads fine in the console as well:
Code: [Select]
include stdio.inc
include winbase.inc

BASSInitT typedef proto :SINT, :DWORD, :DWORD, :HWND, :ptr

    .code

main proc

 local Bass:ptr BASSInitT

    .if LoadLibrary("bass.dll")
        .if GetProcAddress(rax,"BASS_Init")
            mov Bass,rax
            .if Bass(-1, 44100, 0, 0, 0)
                printf("BASS_Init OK..\n")
            .endif
        .endif
    .endif
    xor eax,eax
    ret

main endp

    END

Quote
i have change in Bass_Init remove hWnd to NULL for desktop
...
but is same fail

What actually happens? crash?

Quote
ps: nidud
is this a hjwasm code?

No it's a Dialog sample for Asmc.

AW

  • Member
  • *****
  • Posts: 1357
  • Let's Make ASM Great Again!
Re: Bass.dll problem
« Reply #9 on: December 03, 2017, 11:55:04 AM »
The code works fine i have make test in a exe aplication
and it give not any procdur or should I now make a procdedur like xyz

xyz proc
Bass int code
and play mp3
xyz endp

 I said allready in my exe project and test works fine but not in a dll project Bass_init is fail.

You did not get the point of my comment.
I said that if you call that in the entry point it will freeze. So, you are calling that in the entry point of the DLL and believe it is absolutely normal and should work.  :badgrin:
It will never work.

ragdog

  • Member
  • ****
  • Posts: 572
Re: Bass.dll problem
« Reply #10 on: December 03, 2017, 06:47:30 PM »
Quote
You did not get the point of my comment.
I said that if you call that in the entry point it will freeze. So, you are calling that in the entry point of the DLL and believe it is absolutely normal and should work.  :badgrin:
It will never work.

Why?

The dll is loaded when the Main.exe window is created (WM_INITDIALOG)

Or give a better soulution?

AW

  • Member
  • *****
  • Posts: 1357
  • Let's Make ASM Great Again!
Re: Bass.dll problem
« Reply #11 on: December 03, 2017, 07:03:17 PM »
Or give a better soulution?

You were expected to know it  :dazzled:
Quoting Microsoft:
"The entry-point function should perform only simple initialization or termination tasks. It must not call the LoadLibrary or LoadLibraryEx function (or a function that calls these functions), because this may create dependency loops in the DLL load order. This can result in a DLL being used before the system has executed its initialization code."





ragdog

  • Member
  • ****
  • Posts: 572
Re: Bass.dll problem
« Reply #12 on: December 03, 2017, 07:40:43 PM »
I forgot

But i use now a Procedur for this code and call it with GetProcAdress

example:
Code: [Select]
invoke LoadLibrary, chr$("Player.dll")
invoke GetProcAddress,eax,chr$("Player_Init")
call  eax

Player_Init proc

invoke LoadLibrary, chr$("bass24100.dll")
.if (eax)
mov hBassDll,eax
invoke GetProcAddress,hBassDll,chr$("BASS_Init")
.if (eax)
mov pBASS_Init,eax
push 0
pushNULL
push 0
push 44100
push -1
call dword ptr [pBASS_Init] ;<<<<<<<<<<<<<
                    .endif
           .endif
Player_Init endp

is the same problem with Bass_init

AW

  • Member
  • *****
  • Posts: 1357
  • Let's Make ASM Great Again!
Re: Bass.dll problem
« Reply #13 on: December 03, 2017, 07:55:24 PM »
OK, what I have seen so far is that you forget the basics so bugs can happen anywhere. Since we are too lazy to do it, may be someone would bother to reconstructed a demo from your sparse snippets, and check it.

nidud

  • Member
  • *****
  • Posts: 1529
    • https://github.com/nidud/asmc
Re: Bass.dll problem
« Reply #14 on: December 03, 2017, 10:12:17 PM »
I made a simple test case:
Code: [Select]
_CType equ <stdcall>
include winbase.inc

BASSInitT typedef proto :SINT, :DWORD, :DWORD, :HWND, :ptr

    .code

Player_Init proc export

 local Bass:ptr BASSInitT

    .if LoadLibrary("bass.dll")
        .if GetProcAddress(eax, "BASS_Init")
            mov Bass,eax
            Bass(-1, 44100, 0, 0, 0)
        .endif
    .endif
    ret

Player_Init endp

LibMain proc Module, dwReason, dwReserved
    mov eax,1
    ret
LibMain endp

    end LibMain

Code: [Select]
include stdio.inc
include winbase.inc

    .code

main proc

    .if LoadLibrary("Player.dll")
        .if GetProcAddress(eax, "_Player_Init@0")
            printf("Player_Init: %d\n", eax())
        .endif
    .endif
    xor eax,eax
    ret

main endp

    END

I attached the binaries including bass.dll, so you may try that as appose to bass24100.dll and see if that helps.

The output from test.exe should be:
Code: [Select]
Player_Init: 1