Skip to content

Commit

Permalink
Dllclose (#144)
Browse files Browse the repository at this point in the history
* Close DLL's when Vcc closes; consolidate logger

This addresses issue #47;  Cartridge modeless dialogs do not close
when Vcc closes.

Fix was to call UnloadDLL in Vcc main window when close event occurs.
Previously the unload was being attempted after the execution loop
exited which was failing because resources held by some dll's (mpi.dll)
were preventing loop exit.

Also consolidated acia logger to use main Vcc logger.  Logger is only
used for debugging Vcc code. Consolidation permits uniform logging
with modules.

* Remove logging call erronously left in acia.c

* Reset BUS on Vcc exit.  Acia load rom on dll load

1) Reset pak interface bus on Vcc exit.  This forces acia
reset when Vcc exits.

2)Remove acia rom load from reset to load.  This seems to resolve
issues with GO TO "BASIC" function in program pak.

* Fix config dialog creation for mpi and acia DLLs

This patch, part of the effort to get DLL dialogs to close properly
when Vcc closes, changes the behaviour of the subject dialogs. The
dialogs are still modeless but will no longer be covered by the VCC
window.  (MS standards require modeless dialog windows not be be
occluded by the window's owner)

DialogBox() was being used to create the config dialog boxes for
mpi and acia DLLs.  DialogBox() is only for modal dialogs but will
create a modeless dialogs if the parent window is specified as NULL.
This usage causes Vcc to crash when DLLs are unloaded without first
closing the dialog.

The incorrect calls were replaced with CreateDialog() which properly
creates modeless dialogs.

At this point the fd502 DLL still has the issue. To demonstrate run
fd-502 config from the Cartridge menu then while dialog is open either
unload the mpi module or eject FD-502 from it's mpi slot.  Vcc will
crash as soon as any event is sent to the still visible dialog.

* Cleanups on command parsing

* Changes to fd502, harddrive, and becker dialogs

Config dialogs modeless but now stay on top of VCC window.
New disk file dialogs are changed to modal

* fd502 destroy config window on unload.

Config window was not being destroyed when DLL unloaded.

---------

Co-authored-by: ejaquay <[email protected]>
  • Loading branch information
ejaquay and ejaquay authored Oct 11, 2023
1 parent bd407b9 commit 89806a9
Show file tree
Hide file tree
Showing 16 changed files with 167 additions and 225 deletions.
6 changes: 4 additions & 2 deletions CommandLine.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ int GetCmdLineArgs(char *CmdString)
// Default config file is "vcc.ini"
case 'i':
strncpy(CmdArg.IniFile,token+2,CL_MAX_PATH);
CmdArg.IniFile[CL_MAX_PATH-1]=0;
break;

// "-d[level]" enables logging console and sets log level (default=1)
Expand Down Expand Up @@ -158,6 +159,7 @@ int GetCmdLineArgs(char *CmdString)
// First (currently only) positional arg is Quick Load filename.
case 1:
strncpy(CmdArg.QLoadFile,token,CL_MAX_PATH);
CmdArg.QLoadFile[CL_MAX_PATH-1]=0;
break;

// Extra positional argument returns an error
Expand Down Expand Up @@ -195,9 +197,9 @@ char * ParseCmdString(char *CmdString, const char *ValueRequired)
// Initial call sets command string. Subsequent calls expect a NULL
if (CmdString) {
while (*CmdString == ' ') CmdString++; // Skip leading blanks
strncpy(cmdline,CmdString,510); // Make a copy of what is left
strncpy(cmdline,CmdString,512); // Make a copy of what is left
strcat(cmdline," "); // Make sure args are terminated
cmdline[511]='\0'; // Be sure string is terminated
strcat(cmdline," "); // Be sure args are terminated
NxtTokenPtr = cmdline; // Save it's location

// Mark unquoted blanks
Expand Down
15 changes: 11 additions & 4 deletions FD502/fd502.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ void SaveConfig(void);
long CreateDiskHeader(char *,unsigned char,unsigned char,unsigned char);
void Load_Disk(unsigned char);

static HWND g_hConfDlg;
static HINSTANCE g_hinstDLL;
static unsigned long RealDisks=0;
long CreateDisk (unsigned char);
Expand All @@ -82,6 +83,7 @@ BOOL WINAPI DllMain(
{
for (unsigned char Drive=0;Drive<=3;Drive++)
unmount_disk_image(Drive);
if (g_hConfDlg) DestroyWindow(g_hConfDlg);
}
else
{
Expand Down Expand Up @@ -109,6 +111,7 @@ extern "C"
{
__declspec(dllexport) void ModuleConfig(unsigned char MenuID)
{
HWND h_own = GetActiveWindow();
switch (MenuID)
{
case 10:
Expand All @@ -133,7 +136,8 @@ extern "C"
SaveConfig();
break;
case 16:
DialogBox(g_hinstDLL, (LPCTSTR)IDD_CONFIG, NULL, (DLGPROC)Config);
CreateDialog(g_hinstDLL,(LPCTSTR)IDD_CONFIG,h_own,(DLGPROC)Config);
ShowWindow(g_hConfDlg,1);
break;
case 17:
Load_Disk(3);
Expand Down Expand Up @@ -254,6 +258,7 @@ LRESULT CALLBACK Config(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
char VirtualNames[5][16]={"None","Drive 0","Drive 1","Drive 2","Drive 3"};
OPENFILENAME ofn ;

g_hConfDlg = hDlg;
switch (message)
{
case WM_INITDIALOG:
Expand Down Expand Up @@ -406,7 +411,8 @@ void Load_Disk(unsigned char disk)
if (hr==INVALID_HANDLE_VALUE)
{
NewDiskNumber=disk;
DialogBox(g_hinstDLL, (LPCTSTR)IDD_NEWDISK, NULL, (DLGPROC)NewDisk); //CreateFlag =0 on cancel
HWND h_own = GetActiveWindow();
DialogBox(g_hinstDLL, (LPCTSTR)IDD_NEWDISK, h_own, (DLGPROC)NewDisk); //CreateFlag =0 on cancel
}
else
CloseHandle(hr);
Expand Down Expand Up @@ -491,7 +497,8 @@ void BuildDynaMenu(void)
long CreateDisk (unsigned char Disk)
{
NewDiskNumber=Disk;
DialogBox(g_hinstDLL, (LPCTSTR)IDD_NEWDISK, NULL, (DLGPROC)NewDisk);
HWND h_own = GetActiveWindow();
DialogBox(g_hinstDLL, (LPCTSTR)IDD_NEWDISK, h_own, (DLGPROC)NewDisk);
return(0);
}

Expand Down Expand Up @@ -738,4 +745,4 @@ unsigned char LoadExtRom( unsigned char RomType,char *FilePath) //Returns 1 on i
fclose(rom_handle);
}
return(RetVal);
}
}
17 changes: 12 additions & 5 deletions Vcc.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ static unsigned char AutoStart=1;
static unsigned char Qflag=0;
static char CpuName[20]="CPUNAME";

char QuickLoadFile[256];
char QuickLoadFile[256]; // No real purpose

/***Forward declarations of functions included in this code module*****/
BOOL InitInstance (HINSTANCE, int);
Expand Down Expand Up @@ -138,11 +138,15 @@ int APIENTRY WinMain(HINSTANCE hInstance,
OleInitialize(NULL); //Work around fixs app crashing in "Open file" system dialogs (related to Adobe acrobat 7+
LoadString(hInstance, IDS_APP_TITLE,g_szAppName, MAX_LOADSTRING);

if (strlen(lpCmdLine)>0) GetCmdLineArgs(lpCmdLine); //Parse command line
// Parse command line
memset(&CmdArg,0,sizeof(CmdArg));
if (strlen(lpCmdLine)>0) GetCmdLineArgs(lpCmdLine);

if ( strlen(CmdArg.QLoadFile) !=0)
{
strcpy(QuickLoadFile, CmdArg.QLoadFile);
strncpy(QuickLoadFile, CmdArg.QLoadFile, CL_MAX_PATH);
QuickLoadFile[CL_MAX_PATH-1]=0;
// Rest of this does not accomplish much
strcpy(temp1, CmdArg.QLoadFile);
PathStripPath(temp1);
_strlwr(temp1);
Expand Down Expand Up @@ -305,6 +309,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)

case ID_FILE_EXIT:
BinaryRunning=0;
UnloadDll();
break;

case ID_FILE_RESET:
Expand Down Expand Up @@ -397,6 +402,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)

case WM_CLOSE:
BinaryRunning=0;
UnloadDll();
break;

case WM_CHAR:
Expand Down Expand Up @@ -645,6 +651,7 @@ void OnCommand(HWND hWnd, int iID, HWND hwndCtl, UINT uNotifyCode)
void OnDestroy(HWND )
{
BinaryRunning = false;
UnloadDll();
PostQuitMessage(0);
}
/*--------------------------------------------------------------------------*/
Expand Down Expand Up @@ -929,7 +936,7 @@ unsigned __stdcall EmuLoop(void *Dummy)
if ((Qflag==255) & (FrameCounter==30))
{
Qflag=0;
QuickLoad(QuickLoadFile);
QuickLoad(CmdArg.QLoadFile);
}

StartRender();
Expand Down Expand Up @@ -1017,7 +1024,7 @@ void FullScreenToggle(void)
return;
}
void PauseUnPause_Emulation() {
// User selected 'Pause' from the menu. Pause the emulation and
// User selected 'Pause' from the menu. Pause the emulation and
// temporarily disable the sound in case it was paused during a sample.
if (!emu_paused) {
emu_paused = true;
Expand Down
30 changes: 16 additions & 14 deletions acia/acia.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

#include "acia.h"
#include "sc6551.h"
#include "logger.h"
#include "../logger.h"

//------------------------------------------------------------------------
// Local Functions
Expand All @@ -33,15 +33,15 @@ typedef void (*ASSERTINTERUPT) (unsigned char,unsigned char);
void (*DynamicMenuCallback)(char *,int,int)=NULL;
void BuildDynaMenu(void);

LRESULT CALLBACK ConfigDlg(HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK Config(HWND, UINT, WPARAM, LPARAM);
void LoadConfig(void);
void SaveConfig(void);

//------------------------------------------------------------------------
// Globals
//------------------------------------------------------------------------
static HINSTANCE g_hDLL = NULL; // DLL handle
static HWND hConfigDlg = NULL; // Config dialog
static HWND g_hDlg = NULL; // Config dialog
static char IniFile[MAX_PATH]; // Ini file name
static char IniSect[MAX_LOADSTRING]; // Ini file section

Expand All @@ -63,11 +63,14 @@ typedef void (*DYNAMICMENUCALLBACK)( char *,int, int);
BOOL APIENTRY
DllMain(HINSTANCE hinst, DWORD reason, LPVOID foo)
{
// PrintLogF("acia dll %d\n",reason);
if (reason == DLL_PROCESS_ATTACH) {
g_hDLL = hinst;
LoadExtRom("RS232.ROM");

} else if (reason == DLL_PROCESS_DETACH) {
if (hConfigDlg) SendMessage(hConfigDlg,WM_CLOSE,6666,0);
if (g_hDlg) DestroyWindow(g_hDlg);
g_hDlg = NULL;
sc6551_close();
AciaStat[0]='\0';
}
Expand Down Expand Up @@ -113,8 +116,6 @@ PackPortRead(unsigned char Port)
//-----------------------------------------------------------------------
__declspec(dllexport) void ModuleReset(void)
{
LoadExtRom("RS232.ROM");
SendMessage(hConfigDlg, WM_CLOSE, 0, 0);
sc6551_close();
return;
}
Expand Down Expand Up @@ -180,7 +181,9 @@ __declspec(dllexport) void ModuleStatus(char *status)
//-----------------------------------------------------------------------
__declspec(dllexport) void ModuleConfig(unsigned char MenuID)
{
DialogBox(g_hDLL, (LPCTSTR) IDD_PROPPAGE, NULL, (DLGPROC) ConfigDlg);
HWND owner = GetActiveWindow();
CreateDialog(g_hDLL,(LPCTSTR)IDD_PROPPAGE,owner,Config);
ShowWindow(g_hDlg,1);
return;
}

Expand Down Expand Up @@ -286,7 +289,7 @@ void SaveConfig(void)
// IDC_TEXTMODE Translate CR <> CRLF if checked
//-----------------------------------------------------------------------

LRESULT CALLBACK ConfigDlg(HWND hDlg,UINT msg,WPARAM wParam,LPARAM lParam)
LRESULT CALLBACK Config(HWND hDlg,UINT msg,WPARAM wParam,LPARAM lParam)
{
int button;
HANDLE hCtl;
Expand All @@ -299,23 +302,23 @@ LRESULT CALLBACK ConfigDlg(HWND hDlg,UINT msg,WPARAM wParam,LPARAM lParam)
case WM_INITDIALOG:

// Kill previous instance
if (hConfigDlg) EndDialog(hConfigDlg,0);
hConfigDlg = hDlg;
DestroyWindow(g_hDlg);
g_hDlg = hDlg;

SetWindowPos(hDlg, HWND_TOP, 10, 10, 0, 0, SWP_NOSIZE);

// Set Button as per Base Port
switch (AciaBasePort) {
case BASE_PORT_RS232:
CheckDlgButton(hDlg,IDC_T_RS232,BST_CHECKED);
CheckDlgButton(hDlg,IDC_T_RS232,BST_CHECKED);
CheckDlgButton(hDlg,IDC_T_MODEM,BST_UNCHECKED);
break;
case BASE_PORT_MODEM:
CheckDlgButton(hDlg,IDC_T_RS232,BST_UNCHECKED);
CheckDlgButton(hDlg,IDC_T_RS232,BST_UNCHECKED);
CheckDlgButton(hDlg,IDC_T_MODEM,BST_CHECKED);
break;
default:
CheckDlgButton(hDlg,IDC_T_RS232,BST_CHECKED);
CheckDlgButton(hDlg,IDC_T_RS232,BST_CHECKED);
CheckDlgButton(hDlg,IDC_T_MODEM,BST_UNCHECKED);
AciaBasePort = BASE_PORT_RS232;
break;
Expand Down Expand Up @@ -380,7 +383,6 @@ LRESULT CALLBACK ConfigDlg(HWND hDlg,UINT msg,WPARAM wParam,LPARAM lParam)

case WM_COMMAND:


button = LOWORD(wParam);
switch (button) {

Expand Down
2 changes: 1 addition & 1 deletion acia/acia.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@
<PrecompiledHeaderOutputFile Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
</PrecompiledHeaderOutputFile>
</ClCompile>
<ClCompile Include="logger.c" />
<ClCompile Include="..\logger.c" />
<ClCompile Include="console.c" />
<ClCompile Include="sc6551.c" />
<ClCompile Include="file.c" />
Expand Down
2 changes: 1 addition & 1 deletion acia/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include <errno.h>
#include <string.h>
#include "acia.h"
#include "logger.h"
#include "../logger.h"

FILE * FileStream = NULL;

Expand Down
81 changes: 0 additions & 81 deletions acia/logger.c

This file was deleted.

Loading

0 comments on commit 89806a9

Please sign in to comment.