win 7 I have used C to write a project, and compile it to dll to be used in a big program writing with python.After finished using the DLL, although I have used the closing com port function in the dll, the com port was still be used.
In the end of the dll, all the thread was terminated but I suspect a memory overflow problem so I want to forcely kill all the process at the end of the dll. I tried pid_t pid = getpid() but it could not be used and I think it may only be used in linux, so how to terminate all the process so the com port could be released after using the dll?
#include <windows.h>
#include <tchar.h>
#include <sys/types.h>
#include <stdio.h>
#include <conio.h>
#include <signal.h>
#include "getopt.h"
#include "download_main.h"
......
#ifdef CREATE_SEND_THREAD
TerminateSendThread();
#endif
TerminateMonitorThread();
release_async_io();
if (hCom != INVALID_HANDLE_VALUE) {
unconfig_serial_port();
fSuccess = CloseHandle(hCom);
if (!fSuccess) {
TRACE("CloseHandle failed with error %d", GetLastError());
} else {
hCom = INVALID_HANDLE_VALUE;
TRACE("Serial port %s successfully closed", commPort);
}
}
free_programmer_data();
//free_flash_data();
deinit_download_var();
deinit_pyext_sync_event();
if(!!g_dldtool_exit_code)
app_ev_notify(ev_wm_exit_invalid, 0);
else
app_ev_notify(ev_wm_exit_valid, 0);
TRACE("download exit code:%d\n",g_dldtool_exit_code);
pid_t pid = getpid();
system("tskill pid");
return g_dldtool_exit_code;
}
In the end of the dll, all the thread was terminated but I suspect a memory overflow problem so I want to forcely kill all the process at the end of the dll. I tried pid_t pid = getpid() but it could not be used and I think it may only be used in linux, so how to terminate all the process so the com port could be released after using the dll?
#include <windows.h>
#include <tchar.h>
#include <sys/types.h>
#include <stdio.h>
#include <conio.h>
#include <signal.h>
#include "getopt.h"
#include "download_main.h"
......
#ifdef CREATE_SEND_THREAD
TerminateSendThread();
#endif
TerminateMonitorThread();
release_async_io();
if (hCom != INVALID_HANDLE_VALUE) {
unconfig_serial_port();
fSuccess = CloseHandle(hCom);
if (!fSuccess) {
TRACE("CloseHandle failed with error %d", GetLastError());
} else {
hCom = INVALID_HANDLE_VALUE;
TRACE("Serial port %s successfully closed", commPort);
}
}
free_programmer_data();
//free_flash_data();
deinit_download_var();
deinit_pyext_sync_event();
if(!!g_dldtool_exit_code)
app_ev_notify(ev_wm_exit_invalid, 0);
else
app_ev_notify(ev_wm_exit_valid, 0);
TRACE("download exit code:%d\n",g_dldtool_exit_code);
pid_t pid = getpid();
system("tskill pid");
return g_dldtool_exit_code;
}