Skip to content

Commit 89806a9

Browse files
ejaquayejaquay
andauthored
Dllclose (#144)
* 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]>
1 parent bd407b9 commit 89806a9

File tree

16 files changed

+167
-225
lines changed

16 files changed

+167
-225
lines changed

CommandLine.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ int GetCmdLineArgs(char *CmdString)
130130
// Default config file is "vcc.ini"
131131
case 'i':
132132
strncpy(CmdArg.IniFile,token+2,CL_MAX_PATH);
133+
CmdArg.IniFile[CL_MAX_PATH-1]=0;
133134
break;
134135

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

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

203205
// Mark unquoted blanks

FD502/fd502.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ void SaveConfig(void);
6868
long CreateDiskHeader(char *,unsigned char,unsigned char,unsigned char);
6969
void Load_Disk(unsigned char);
7070

71+
static HWND g_hConfDlg;
7172
static HINSTANCE g_hinstDLL;
7273
static unsigned long RealDisks=0;
7374
long CreateDisk (unsigned char);
@@ -82,6 +83,7 @@ BOOL WINAPI DllMain(
8283
{
8384
for (unsigned char Drive=0;Drive<=3;Drive++)
8485
unmount_disk_image(Drive);
86+
if (g_hConfDlg) DestroyWindow(g_hConfDlg);
8587
}
8688
else
8789
{
@@ -109,6 +111,7 @@ extern "C"
109111
{
110112
__declspec(dllexport) void ModuleConfig(unsigned char MenuID)
111113
{
114+
HWND h_own = GetActiveWindow();
112115
switch (MenuID)
113116
{
114117
case 10:
@@ -133,7 +136,8 @@ extern "C"
133136
SaveConfig();
134137
break;
135138
case 16:
136-
DialogBox(g_hinstDLL, (LPCTSTR)IDD_CONFIG, NULL, (DLGPROC)Config);
139+
CreateDialog(g_hinstDLL,(LPCTSTR)IDD_CONFIG,h_own,(DLGPROC)Config);
140+
ShowWindow(g_hConfDlg,1);
137141
break;
138142
case 17:
139143
Load_Disk(3);
@@ -254,6 +258,7 @@ LRESULT CALLBACK Config(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
254258
char VirtualNames[5][16]={"None","Drive 0","Drive 1","Drive 2","Drive 3"};
255259
OPENFILENAME ofn ;
256260

261+
g_hConfDlg = hDlg;
257262
switch (message)
258263
{
259264
case WM_INITDIALOG:
@@ -406,7 +411,8 @@ void Load_Disk(unsigned char disk)
406411
if (hr==INVALID_HANDLE_VALUE)
407412
{
408413
NewDiskNumber=disk;
409-
DialogBox(g_hinstDLL, (LPCTSTR)IDD_NEWDISK, NULL, (DLGPROC)NewDisk); //CreateFlag =0 on cancel
414+
HWND h_own = GetActiveWindow();
415+
DialogBox(g_hinstDLL, (LPCTSTR)IDD_NEWDISK, h_own, (DLGPROC)NewDisk); //CreateFlag =0 on cancel
410416
}
411417
else
412418
CloseHandle(hr);
@@ -491,7 +497,8 @@ void BuildDynaMenu(void)
491497
long CreateDisk (unsigned char Disk)
492498
{
493499
NewDiskNumber=Disk;
494-
DialogBox(g_hinstDLL, (LPCTSTR)IDD_NEWDISK, NULL, (DLGPROC)NewDisk);
500+
HWND h_own = GetActiveWindow();
501+
DialogBox(g_hinstDLL, (LPCTSTR)IDD_NEWDISK, h_own, (DLGPROC)NewDisk);
495502
return(0);
496503
}
497504

@@ -738,4 +745,4 @@ unsigned char LoadExtRom( unsigned char RomType,char *FilePath) //Returns 1 on i
738745
fclose(rom_handle);
739746
}
740747
return(RetVal);
741-
}
748+
}

Vcc.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ static unsigned char AutoStart=1;
7777
static unsigned char Qflag=0;
7878
static char CpuName[20]="CPUNAME";
7979

80-
char QuickLoadFile[256];
80+
char QuickLoadFile[256]; // No real purpose
8181

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

141-
if (strlen(lpCmdLine)>0) GetCmdLineArgs(lpCmdLine); //Parse command line
141+
// Parse command line
142+
memset(&CmdArg,0,sizeof(CmdArg));
143+
if (strlen(lpCmdLine)>0) GetCmdLineArgs(lpCmdLine);
142144

143145
if ( strlen(CmdArg.QLoadFile) !=0)
144146
{
145-
strcpy(QuickLoadFile, CmdArg.QLoadFile);
147+
strncpy(QuickLoadFile, CmdArg.QLoadFile, CL_MAX_PATH);
148+
QuickLoadFile[CL_MAX_PATH-1]=0;
149+
// Rest of this does not accomplish much
146150
strcpy(temp1, CmdArg.QLoadFile);
147151
PathStripPath(temp1);
148152
_strlwr(temp1);
@@ -305,6 +309,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
305309

306310
case ID_FILE_EXIT:
307311
BinaryRunning=0;
312+
UnloadDll();
308313
break;
309314

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

398403
case WM_CLOSE:
399404
BinaryRunning=0;
405+
UnloadDll();
400406
break;
401407

402408
case WM_CHAR:
@@ -645,6 +651,7 @@ void OnCommand(HWND hWnd, int iID, HWND hwndCtl, UINT uNotifyCode)
645651
void OnDestroy(HWND )
646652
{
647653
BinaryRunning = false;
654+
UnloadDll();
648655
PostQuitMessage(0);
649656
}
650657
/*--------------------------------------------------------------------------*/
@@ -929,7 +936,7 @@ unsigned __stdcall EmuLoop(void *Dummy)
929936
if ((Qflag==255) & (FrameCounter==30))
930937
{
931938
Qflag=0;
932-
QuickLoad(QuickLoadFile);
939+
QuickLoad(CmdArg.QLoadFile);
933940
}
934941

935942
StartRender();
@@ -1017,7 +1024,7 @@ void FullScreenToggle(void)
10171024
return;
10181025
}
10191026
void PauseUnPause_Emulation() {
1020-
// User selected 'Pause' from the menu. Pause the emulation and
1027+
// User selected 'Pause' from the menu. Pause the emulation and
10211028
// temporarily disable the sound in case it was paused during a sample.
10221029
if (!emu_paused) {
10231030
emu_paused = true;

acia/acia.c

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
#include "acia.h"
2222
#include "sc6551.h"
23-
#include "logger.h"
23+
#include "../logger.h"
2424

2525
//------------------------------------------------------------------------
2626
// Local Functions
@@ -33,15 +33,15 @@ typedef void (*ASSERTINTERUPT) (unsigned char,unsigned char);
3333
void (*DynamicMenuCallback)(char *,int,int)=NULL;
3434
void BuildDynaMenu(void);
3535

36-
LRESULT CALLBACK ConfigDlg(HWND, UINT, WPARAM, LPARAM);
36+
LRESULT CALLBACK Config(HWND, UINT, WPARAM, LPARAM);
3737
void LoadConfig(void);
3838
void SaveConfig(void);
3939

4040
//------------------------------------------------------------------------
4141
// Globals
4242
//------------------------------------------------------------------------
4343
static HINSTANCE g_hDLL = NULL; // DLL handle
44-
static HWND hConfigDlg = NULL; // Config dialog
44+
static HWND g_hDlg = NULL; // Config dialog
4545
static char IniFile[MAX_PATH]; // Ini file name
4646
static char IniSect[MAX_LOADSTRING]; // Ini file section
4747

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

6971
} else if (reason == DLL_PROCESS_DETACH) {
70-
if (hConfigDlg) SendMessage(hConfigDlg,WM_CLOSE,6666,0);
72+
if (g_hDlg) DestroyWindow(g_hDlg);
73+
g_hDlg = NULL;
7174
sc6551_close();
7275
AciaStat[0]='\0';
7376
}
@@ -113,8 +116,6 @@ PackPortRead(unsigned char Port)
113116
//-----------------------------------------------------------------------
114117
__declspec(dllexport) void ModuleReset(void)
115118
{
116-
LoadExtRom("RS232.ROM");
117-
SendMessage(hConfigDlg, WM_CLOSE, 0, 0);
118119
sc6551_close();
119120
return;
120121
}
@@ -180,7 +181,9 @@ __declspec(dllexport) void ModuleStatus(char *status)
180181
//-----------------------------------------------------------------------
181182
__declspec(dllexport) void ModuleConfig(unsigned char MenuID)
182183
{
183-
DialogBox(g_hDLL, (LPCTSTR) IDD_PROPPAGE, NULL, (DLGPROC) ConfigDlg);
184+
HWND owner = GetActiveWindow();
185+
CreateDialog(g_hDLL,(LPCTSTR)IDD_PROPPAGE,owner,Config);
186+
ShowWindow(g_hDlg,1);
184187
return;
185188
}
186189

@@ -286,7 +289,7 @@ void SaveConfig(void)
286289
// IDC_TEXTMODE Translate CR <> CRLF if checked
287290
//-----------------------------------------------------------------------
288291

289-
LRESULT CALLBACK ConfigDlg(HWND hDlg,UINT msg,WPARAM wParam,LPARAM lParam)
292+
LRESULT CALLBACK Config(HWND hDlg,UINT msg,WPARAM wParam,LPARAM lParam)
290293
{
291294
int button;
292295
HANDLE hCtl;
@@ -299,23 +302,23 @@ LRESULT CALLBACK ConfigDlg(HWND hDlg,UINT msg,WPARAM wParam,LPARAM lParam)
299302
case WM_INITDIALOG:
300303

301304
// Kill previous instance
302-
if (hConfigDlg) EndDialog(hConfigDlg,0);
303-
hConfigDlg = hDlg;
305+
DestroyWindow(g_hDlg);
306+
g_hDlg = hDlg;
304307

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

307310
// Set Button as per Base Port
308311
switch (AciaBasePort) {
309312
case BASE_PORT_RS232:
310-
CheckDlgButton(hDlg,IDC_T_RS232,BST_CHECKED);
313+
CheckDlgButton(hDlg,IDC_T_RS232,BST_CHECKED);
311314
CheckDlgButton(hDlg,IDC_T_MODEM,BST_UNCHECKED);
312315
break;
313316
case BASE_PORT_MODEM:
314-
CheckDlgButton(hDlg,IDC_T_RS232,BST_UNCHECKED);
317+
CheckDlgButton(hDlg,IDC_T_RS232,BST_UNCHECKED);
315318
CheckDlgButton(hDlg,IDC_T_MODEM,BST_CHECKED);
316319
break;
317320
default:
318-
CheckDlgButton(hDlg,IDC_T_RS232,BST_CHECKED);
321+
CheckDlgButton(hDlg,IDC_T_RS232,BST_CHECKED);
319322
CheckDlgButton(hDlg,IDC_T_MODEM,BST_UNCHECKED);
320323
AciaBasePort = BASE_PORT_RS232;
321324
break;
@@ -380,7 +383,6 @@ LRESULT CALLBACK ConfigDlg(HWND hDlg,UINT msg,WPARAM wParam,LPARAM lParam)
380383

381384
case WM_COMMAND:
382385

383-
384386
button = LOWORD(wParam);
385387
switch (button) {
386388

acia/acia.vcxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@
159159
<PrecompiledHeaderOutputFile Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
160160
</PrecompiledHeaderOutputFile>
161161
</ClCompile>
162-
<ClCompile Include="logger.c" />
162+
<ClCompile Include="..\logger.c" />
163163
<ClCompile Include="console.c" />
164164
<ClCompile Include="sc6551.c" />
165165
<ClCompile Include="file.c" />

acia/file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#include <errno.h>
2727
#include <string.h>
2828
#include "acia.h"
29-
#include "logger.h"
29+
#include "../logger.h"
3030

3131
FILE * FileStream = NULL;
3232

acia/logger.c

Lines changed: 0 additions & 81 deletions
This file was deleted.

0 commit comments

Comments
 (0)