News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Question about DLLs

Started by G`HOST, November 19, 2005, 06:07:07 PM

Previous topic - Next topic

G`HOST

Hi
   Today I created my first Dll  :thumbu
So as u can expect i have few queries
1.Can i link an .rc file to a dll (masm ofcource)?How?
2.How can i incorporate pictures in an dll?something like done with the icons.

Vortex

Hi G`HOST,

Here is an example for you. The image resource ( bitmap file ) is attached to the DLL and the main application displays the bitmap from DLL.

[attachment deleted by admin]

G`HOST

Thanx mate  :U sorry for replying so late :toothy
but why the LoadBitmap call isnt working in the below code:
.386
.MODEL FLAT,STDCALL
option casemap:none

include \masm32\include\Windows.inc
include \masm32\include\Kernel32.inc
include \masm32\include\User32.inc
include \masm32\include\Winmm.inc
include \masm32\include\Gdi32.inc
include \masm32\macros\macros.asm
include \masm32\include\debug.inc

includelib \masm32\lib\Kernel32.lib
includelib \masm32\lib\User32.lib
includelib \masm32\lib\Winmm.lib
includelib \masm32\lib\Gdi32.lib
includelib \masm32\lib\debug.lib

.DATA
    ButtonBitmap1 db "StartBit1",0
    ButtonBitmap2 db "StartBit2",0
    Shell         db "Shell_TrayWnd",0
    ButtonClass db "BUTTON",0
.DATA?
    hwndStart HWND ?
    hBitmap HANDLE ?
    hInstance dd ?
.CODE
     DLLENTRY proc hInstDll:HINSTANCE,reason:DWORD,reserved1:DWORD
     
      mov eax,TRUE     
      ret

     DLLENTRY endp
     
     Bitmap proc 
     
      invoke FindWindow,ADDR Shell,NULL
      .if eax==0
      invoke MessageBox,NULL,chr$("FindWindow Failure"),chr$("ShellTray"),MB_OK or MB_ICONERROR
      .else
      invoke FindWindowEx,eax,NULL,ADDR ButtonClass,NULL
      .if eax==0
      invoke MessageBox,NULL,chr$("FindWindowEx Failure"),chr$("StartButton"),MB_OK or MB_ICONERROR
      .else
      mov hwndStart,eax
      invoke LoadBitmap,hInstance,ADDR ButtonBitmap1
      PrintError
      mov hBitmap,eax
      invoke SendMessage,hwndStart,BM_SETIMAGE,IMAGE_BITMAP,hBitmap
      PrintError
      .endif
      .endif
    ret

     Bitmap endp

I get this error : "The system cannot find the file specified. "its the PrintError of LoadBitmap call

Vortex

Concerning LoadBitmap, you should use the instance value of the DLL not the EXE

.data?

hInstance dd ?

.code

LibMain PROC instance:DWORD,reason:DWORD,unused:DWORD

    push    instance    ; <----- get the instance of the DLL
    pop     hInstance
    mov     eax,1
    ret

LibMain ENDP

LoadBitmapfromDLL PROC ResNumb:DWORD

    invoke  LoadBitmap,hInstance,ResNumb
    ret

LoadBitmapfromDLL ENDP

G`HOST

 :thumbu :thumbu :thumbu :thumbu :thumbu