Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
#Compiler PBWin 10
#Compile EXE "dll_inside.exe"
#Dim All
%Unicode=1
#Include "Win32API.inc"
#Resource RcData, 9999, "winmsg.dll" '<---- put name of DLL file here
%IDC_Extract = 500 : %IDC_Load = 501 : %IDC_Use = 502
$MyDLL = "winmsg.dll"
Global hDlg,hLib,pAddress As Dword
Declare Function WinMsg (ByVal MsgNum As Long) As String 'take out LIB and ALIAS sections
Function PBMain() As Long
Dialog New Pixels, 0, "gbCodeInside - DLL Version",300,300,240,140, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, %IDC_Extract,"Extract DLL", 40,10,125,25
Control Add Button, hDlg, %IDC_Load,"Load the DLL", 40,45,125,25
Control Add Button, hDlg, %IDC_Use,"Do Something With DLL", 40,80,125,25
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Select Case Cb.Msg
Case %WM_Command
Select Case Cb.Ctl
Case %IDC_Extract : ExtractDLL
Case %IDC_Load : LoadDLL
Case %IDC_Use : UseDLL
End Select
Case %WM_Destroy
FreeLibrary hLib
End Select
End Function
Sub ExtractDLL
Local temp$
temp$ = Resource$(RcData,9999)
Open $MyDLL For Output As #1 '<--- will be in CurDir (where the EXE in this case)
Print #1, temp$;
Close #1
End Sub
Sub LoadDLL
Local pAddr As Dword
Local FreeToUserQuota&&, SizeOfDisk&&, TotalFree&&
If IsFile($MyDLL) Then
hLib = LoadLibrary($MyDLL)
pAddress = GetProcAddress(hLib, "WindowMessageA") 'use the Alias
If pAddress = 0 Then
MsgBox "DLL did not load: " + $MyDLL, %MB_Ok + %MB_IconExclamation, "Load DLL"
End If
Else
MsgBox "DLL missing: " + $MyDLL, %MB_Ok + %MB_IconExclamation, "Load DLL"
End If
End Sub
Sub UseDLL
Local Result$
If pAddress <> 0 Then Call Dword pAddress Using WinMsg(%WM_InitDialog) To Result$
MsgBox Result$, %MB_Ok + %MB_IconInformation, "Display DLL Result"
End Sub
'gbs_00740
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm