Close all processes - c++

I'm trying to make a command which will close all processes, but it will not work for me.
#include "StdAfx.h"
int _tmain(int argc, _TCHAR* argv[])
{
// Get the list of process identifiers.
DWORD ExitCode;
DWORD aProcesses[1024], cbNeeded, cProcesses;
unsigned int i;
if (!EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded ) )
{
return 1;
}
// Calculate how many process identifiers were returned.
cProcesses = cbNeeded / sizeof(DWORD);
// exit each process.
for ( i = 0; i < cProcesses; i++ )
{
std::cout<<"end";
if( aProcesses[i] != 0 )
{
GetExitCodeProcess(OpenProcess(PROCESS_ALL_ACCESS,false,aProcesses[i]),&ExitCode);
ExitProcess(ExitCode);
}
}
}
In addition, I get those errors:
> 'check2.exe': Loaded 'C:\Users\Barak Shriky\Documents\Visual Studio 2010\Projects\check2\Debug\check2.exe', Symbols loaded.
'check2.exe': Loaded 'C:\Windows\SysWOW64\ntdll.dll', Symbols loaded (source information stripped).
'check2.exe': Loaded 'C:\Windows\SysWOW64\kernel32.dll', Symbols loaded (source information stripped).
'check2.exe': Loaded 'C:\Windows\SysWOW64\KernelBase.dll', Symbols loaded (source information stripped).
'check2.exe': Loaded 'C:\Windows\SysWOW64\msvcp100d.dll', Symbols loaded (source information stripped).
'check2.exe': Loaded 'C:\Windows\SysWOW64\msvcr100d.dll', Symbols loaded (source information stripped).
'check2.exe': Loaded 'C:\Windows\SysWOW64\psapi.dll', Symbols loaded (source information stripped).
The program '[3292] check2.exe: Native' has exited with code -858993460 (0xcccccccc).
Can someone please help me with this issue?

1) You are not getting any errors
2) ExitProcess is ending your process. Please read the documentation.

Looks to me like it's working just fine - you just haven't got symbols installed for some system DLL's, which is normal.
Of course, you would get a more meaningful message of why the process exited if you actually set ExitCode to something - say ExitCode = 0xDeadBeef; - and then you would see that it was YOUR process that killed itself.
Doing this seems like a very bad thing to do (assuming it is "successful" in closing the process in the first place), since there are certainly plenty of processes in Windows that when stopped causes the rest of the system to not work very well. Such as the page-in/out process, for example, which is also used to load/unload executables. Being SLIGHTLY more selective in which processes you kill will probably be useful.

see the code below where I used terminate process...
// exit each process.
for ( i = 0; i < cProcesses; i++ )
{
std::cout<<"end";
if( aProcesses[i] != 0)
{
GetExitCodeProcess(OpenProcess(PROCESS_ALL_ACCESS,false,aProcesses[i]),&ExitCode);
TerminateProcess(aProcesses[i], ExitCode);
}
}
}

Related

OpenCV unhandled exception

I am a hardware (arduino hobbyist) programmer trying to get into OpenCV but struggling with a random error.
I have been following Adam Hacks youtibe guide to OpenCV and up to very recently it has worked great. I had compiled OpenCV as 32bit as the prebuilt was only available in x64 and my intended application (driving a set of servos via a FT232H usb to I2C adapter) was in 32 bit.
I typed in his code for "Using OpenCV and Haar Cascades to Detect Faces in a Video [C++]" and it worked fine (see below). It identified my face (some of the time) and drew a box round it. Yeah I was very happy.
The code:
#include <opencv2/opencv.hpp>
#include <vector>
using namespace std;
/* Include D2XX header*/
#include "ftd2xx.h"
/* Include libMPSSE header */
#include "libMPSSE_i2c.h"
#include "FT232.h"
using namespace cv;
int main()
{
//FT232 ft232;
//ft232.setUpFT232H();
double scale = 1.0;
CascadeClassifier faceCascade;
faceCascade.load("C:\\OpenCV32\\etc\\haarcascade_frontalface_alt.xml");
VideoCapture cap(0);
if (!cap.isOpened())
return -1;
for (;;)
{
Mat frame;
cap >> frame;
Mat grayscale;
cvtColor(frame, grayscale, COLOR_BGR2GRAY);
resize(grayscale, grayscale, Size(grayscale.size().width / scale, grayscale.size().height / scale));
vector <Rect> faces;
faceCascade.detectMultiScale(grayscale, faces, 1.1, 3, 0, Size(30, 30));
for (Rect area : faces) {
Scalar drawColor = Scalar(255, 0, 0);
rectangle(frame, Point(cvRound(area.x * scale), cvRound(area.y * scale)),
Point(cvRound((area.x + area.width-1)*scale), cvRound((area.y + area.height - 1) * scale)), drawColor);
}
imshow("Webcam Frame", frame);
if (waitKey(30) >= 0)
break;
}
return 0;
}
Then with no intentional changes on my part other that swapping about from one haarcascade to another the program stopped working and threw an unhandled error.
Unhandled exception at 0x76979862 in OpenCV_Nerf.exe: Microsoft C++ exception: cv::Exception at memory location 0x00EFF428. occurred
in this part of the system.cpp code
void error( const Exception& exc )
{
#ifdef CV_ERROR_SET_TERMINATE_HANDLER
{
cv::AutoLock lock(getInitializationMutex());
if (!cv_terminate_handler_installed)
{
if (param_setupTerminateHandler)
cv_old_terminate_handler = std::set_terminate(cv_terminate_handler);
cv_terminate_handler_installed = true;
}
cv_terminate_handler_exception = exc;
}
#endif
if (customErrorCallback != 0)
customErrorCallback(exc.code, exc.func.c_str(), exc.err.c_str(),
exc.file.c_str(), exc.line, customErrorCallbackData);
else if (param_dumpErrors)
{
dumpException(exc);
}
if(breakOnError)
{
static volatile int* p = 0;
*p = 0;
}
throw exc;
#ifdef __GNUC__
# if !defined __clang__ && !defined __APPLE__
// this suppresses this warning: "noreturn" function does return [enabled by default]
__builtin_trap();
// or use infinite loop: for (;;) {}
# endif
#endif
}
the error box pointing to the very last line.
The camera still functions and I have narrowed it down to the line
faceCascade.detectMultiScale(grayscale, faces, 1.1, 3, 0, Size(30, 30));
Build output: (I don't remember the warnings about loss of data first few time,, but I can't be sure)
1>------ Rebuild All started: Project: OpenCV_Nerf, Configuration: Debug Win32 ------
1>Source.cpp
1>D:\Vincent\Documents\Programming\Visual Studio Projects\OpenCV_Nerf\Source.cpp(32,93): warning C4244: 'argument': conversion from 'double' to '_Tp', possible loss of data
1> with
1> [
1> _Tp=int
1> ]
1>D:\Vincent\Documents\Programming\Visual Studio Projects\OpenCV_Nerf\Source.cpp(32,60): warning C4244: 'argument': conversion from 'double' to '_Tp', possible loss of data
1> with
1> [
1> _Tp=int
1> ]
1>OpenCV_Nerf.vcxproj -> D:\Vincent\Documents\Programming\Visual Studio Projects\OpenCV_Nerf\Debug\OpenCV_Nerf.exe
1>Done building project "OpenCV_Nerf.vcxproj".
Debug output (last bit as it was over character count)
'OpenCV_Nerf.exe' (Win32): Loaded 'C:\Windows\System32\DriverStore\FileRepository\nv_dispi.inf_amd64_95bdb3a23d6478de\NvCamera\NvCameraWhitelisting32.dll'. Symbol loading disabled by Include/Exclude setting.
'OpenCV_Nerf.exe' (Win32): Unloaded 'C:\Windows\System32\DriverStore\FileRepository\nv_dispi.inf_amd64_95bdb3a23d6478de\NvCamera\NvCameraWhitelisting32.dll'
'OpenCV_Nerf.exe' (Win32): Loaded 'C:\Windows\System32\DriverStore\FileRepository\nv_dispi.inf_amd64_95bdb3a23d6478de\NvCamera\NvCameraWhitelisting32.dll'. Symbol loading disabled by Include/Exclude setting.
'OpenCV_Nerf.exe' (Win32): Unloaded 'C:\Windows\System32\DriverStore\FileRepository\nv_dispi.inf_amd64_95bdb3a23d6478de\NvCamera\NvCameraWhitelisting32.dll'
'OpenCV_Nerf.exe' (Win32): Loaded 'C:\Windows\System32\DriverStore\FileRepository\nv_dispi.inf_amd64_95bdb3a23d6478de\NvCamera\NvCameraWhitelisting32.dll'. Symbol loading disabled by Include/Exclude setting.
'OpenCV_Nerf.exe' (Win32): Unloaded 'C:\Windows\System32\DriverStore\FileRepository\nv_dispi.inf_amd64_95bdb3a23d6478de\NvCamera\NvCameraWhitelisting32.dll'
'OpenCV_Nerf.exe' (Win32): Loaded 'C:\Windows\System32\DriverStore\FileRepository\nv_dispi.inf_amd64_95bdb3a23d6478de\NvCamera\NvCameraWhitelisting32.dll'. Symbol loading disabled by Include/Exclude setting.
'OpenCV_Nerf.exe' (Win32): Unloaded 'C:\Windows\System32\DriverStore\FileRepository\nv_dispi.inf_amd64_95bdb3a23d6478de\NvCamera\NvCameraWhitelisting32.dll'
The thread 0x31a8 has exited with code 0 (0x0).
The thread 0x1f70 has exited with code 0 (0x0).
The thread 0x3668 has exited with code 0 (0x0).
The thread 0x3698 has exited with code 0 (0x0).
The thread 0x3a34 has exited with code 0 (0x0).
The thread 0x374 has exited with code 0 (0x0).
The thread 0x5d8 has exited with code 0 (0x0).
The thread 0x3288 has exited with code 0 (0x0).
The thread 0x35bc has exited with code 0 (0x0).
The thread 0x348c has exited with code 0 (0x0).
The thread 0x3968 has exited with code 0 (0x0).
The thread 0x8c0 has exited with code 0 (0x0).
The thread 0x1068 has exited with code 0 (0x0).
The thread 0x1ef8 has exited with code 0 (0x0).
The thread 0x3a30 has exited with code 0 (0x0).
The thread 0x184c has exited with code 0 (0x0).
The thread 0x37f8 has exited with code 0 (0x0).
The thread 0x18b4 has exited with code 0 (0x0).
The thread 0x3380 has exited with code 0 (0x0).
The thread 0x3bf8 has exited with code 0 (0x0).
'OpenCV_Nerf.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvproc.dll'. Symbol loading disabled by Include/Exclude setting.
Exception thrown at 0x76979862 in OpenCV_Nerf.exe: Microsoft C++ exception: cv::Exception at memory location 0x00FCF7EC.
Unhandled exception at 0x76979862 in OpenCV_Nerf.exe: Microsoft C++ exception: cv::Exception at memory location 0x00FCF7EC.
I am completely stumped and would really appreciate any help or pointers I could get.
Regards

SetDllDirectory by thread

To use in different threads a non-reentrant DLL, I'm copying it in 4 different folders. It's ugly but mandatory...
This DLL is manually loaded by my application and uses another sublib (which is implicitly linked to the other). So I have something like this :
folder1/
lib1.dll
sublib.dll
folder2/
lib2.dll
sublib.dll
I managed to load the different versions of lib.dll (lib1 and lib2) but the loaded sublib.dll remains the same for both.
I tried the SetDllDirectory and, AddDllDirectory but it's not loading multiple sublib.dll.
for (size_t i { 1 }; i <= threadsCount; ++i)
{
SetDllDirectoryA(nullptr); // Reset.
//SetDllDirectoryA(""); // Plug "binary planting" security hole. `
SetDllDirectoryA(dirPath(i).c_str()); // folderX
HMODULE module = LoadLibraryExA(libPath(i).c_str(), nullptr, LOAD_LIBRARY_SEARCH_USER_DIRS);
if (!module )
{
std::cout << "error loading dll" << std::endl;
return false;
}
// Used after
// FooPrototype foo = (FooPrototype) GetProcAddress(module, "foo");
}
// Run threads with the different 'foo'
Is it possible to load 2 instances of sublib.dll ??
Thanks !

c++ std::map deleting pointers [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
I will link the classes and output from execution below.
The problem is, the std::map is iterating through and the pointer stored in the second which is of type void* is not deleting from the heap and freeing. The std::map iterated through in the void ShutDown(void); method of the class Engine which is called in the destructor for that class.
I will post the code and output from execution.
Engine header file:
#ifndef _TEST_ENGINE_H_
#define _TEST_ENGINE_H_
#include "test_graphics_system.h"
#include <iostream>
#include <map>
namespace Core {
enum class EngineStatus {
Invalid,
Constructing,
Setup,
Running,
ShutDown,
Destroying
};
class Engine
{
public:
Engine(void);
~Engine(void);
template<class T> T * GetSystem(SystemType systemType)
{
if (mSystems[systemType])
{
return (T*)mSystems[systemType];
}
else
{
std::wcout << "System doe not exist" << std::endl;
}
return nullptr;
}
int Run(void);
private:
template<class T> void AddSystem(T * system)
{
size_t count = mSystems.size();
auto pair = std::make_pair(system->GetType(), (T*)system);
mSystems.insert(pair);
if (count == mSystems.size())
std::wcout << "System failed to be added" << std::endl;
else
std::wcout << "System added" << std::endl;
}
void Setup(void);
void ShutDown(void);
void SetupGraphicsSystem(void);
static EngineStatus mEngineStatus;
std::map<SystemType, void*> mSystems;
bool mRunning;
};
}
#endif _TEST_ENGINE_H_
Engine source file:
#include "test_engine.h"
using namespace std;
using namespace Core;
EngineStatus Engine::mEngineStatus = EngineStatus::Invalid;
Engine::Engine(void)
{
mEngineStatus = EngineStatus::Constructing;
Setup();
}
Engine::~Engine(void)
{
mEngineStatus = EngineStatus::Destroying;
ShutDown();
}
int Engine::Run(void)
{
mEngineStatus = EngineStatus::Running;
return 0;
}
void Engine::Setup(void)
{
mEngineStatus = EngineStatus::Setup;
SetupGraphicsSystem();
}
void Engine::ShutDown(void)
{
mEngineStatus = EngineStatus::ShutDown;
wcout << endl;
int count = 0;
size_t total = mSystems.size();
for (auto obj : mSystems)
{
safe_delete(obj.second);
wcout << "\rSystem(s) deleted: " << ++count << " of " << total;
}
}
void Engine::SetupGraphicsSystem(void)
{
GraphicsSystem * gs = new GraphicsSystem(mSystems.size(), L"GraphicsSystem01", SystemType::Graphics);
AddSystem(gs);
}
Main source file:
#include "safe_del_rel.h"
#include "strings.h"
#include "test_engine.h"
using namespace std;
using namespace Core;
void _DebugMemLeakDetection(void) {
#if defined(_DEBUG) || defined(DEBUG)
int flag = _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
flag |= _CRTDBG_LEAK_CHECK_DF; // Turn on leak-checking bit
_CrtSetDbgFlag(flag);
_CrtSetBreakAlloc(0);
#endif
}
int main(int argv, char argc[])
{
_DebugMemLeakDetection();
Engine * eng = new Engine();
eng->Run();
system("pause");
safe_delete(eng);
return 0;
}
Output from last runtime:
'test_engine_console.exe' (Win32): Loaded 'C:\vs_projects\test_engine\x64\Debug\test_engine_console.exe'. Symbols loaded.
'test_engine_console.exe' (Win32): Loaded 'C:\Windows\System32\ntdll.dll'. Cannot find or open the PDB file.
'test_engine_console.exe' (Win32): Loaded 'C:\Windows\System32\kernel32.dll'. Cannot find or open the PDB file.
'test_engine_console.exe' (Win32): Loaded 'C:\Windows\System32\KernelBase.dll'. Cannot find or open the PDB file.
'test_engine_console.exe' (Win32): Loaded 'C:\Windows\System32\msvcp140d.dll'. Cannot find or open the PDB file.
'test_engine_console.exe' (Win32): Loaded 'C:\Windows\System32\ucrtbased.dll'. Cannot find or open the PDB file.
'test_engine_console.exe' (Win32): Loaded 'C:\Windows\System32\vcruntime140d.dll'. Cannot find or open the PDB file.
'test_engine_console.exe' (Win32): Loaded 'C:\Windows\System32\vcruntime140d.dll'. Cannot find or open the PDB file.
'test_engine_console.exe' (Win32): Unloaded 'C:\Windows\System32\vcruntime140d.dll'
'test_engine_console.exe' (Win32): Loaded 'C:\Windows\System32\kernel.appcore.dll'. Cannot find or open the PDB file.
'test_engine_console.exe' (Win32): Loaded 'C:\Windows\System32\msvcrt.dll'. Cannot find or open the PDB file.
'test_engine_console.exe' (Win32): Loaded 'C:\Windows\System32\rpcrt4.dll'. Cannot find or open the PDB file.
The thread 0x4134 has exited with code 0 (0x0).
The thread 0x46ac has exited with code 0 (0x0).
The thread 0x307c has exited with code 0 (0x0).
Detected memory leaks!
Dumping objects ->
{161} normal block at 0x00000293DD5E2680, 48 bytes long.
Data: <G r a p h i c s > 47 00 72 00 61 00 70 00 68 00 69 00 63 00 73 00
{160} normal block at 0x00000293DD5E1820, 16 bytes long.
Data: < R] > A0 52 5D DD 93 02 00 00 00 00 00 00 00 00 00 00
Object dump complete.
The program '[12764] test_engine_console.exe' has exited with code 0 (0x0).
If someone can help plesae do.
Deleting a void * pointer causes undefined behavior, most compilers will issue a warning about this. While the storage for the GraphicsSystem will be freed, its destructor will not be called.
Typically in C++ you would declare std::map<SystemType, Base*> mSystems; where Base is some class all your systems derive from, although mapping to smart pointers to Base is almost always a better idea. If this isn't possible (e.g. GraphicsSystem is an external class) then you could, for example, wrap it in a templated handle that derives from Base.

Visual Studio 2017 C++ Console not outputting everything

I was following a video on YouTube that was about hash tables, and while testing some output I realized that my console was skipping quite a few lines.
So my hash table originally was of size 10. When I run the program, everything shows up properly. But when I up the size to 20, my console skips the first 3 indices. I don't know if the problem is with my code, or Visual Studio, but I was hoping someone here would know.
This is a picture of the console output with size 20:
Size 10:
Hash::Hash() {
for (int i = 0; i < tableSize; i++) {
HashTable[i] = new item;
HashTable[i]->name = "empty";
HashTable[i]->drink = "empty";
HashTable[i]->next = NULL;
}
}
int Hash::hashFunction(std::string key) {
int hash = 0;
int index;
for (int i = 0; i < key.length(); i++) {
hash = (hash + (int)key[i]) * 17;
}
index = hash % tableSize;
return index;
}
void Hash::addItem(std::string name, std::string drink) {
int index = hashFunction(name);
if (HashTable[index]->name == "empty") {
HashTable[index]->name = name;
HashTable[index]->drink = drink;
}
else {
item* ptr = HashTable[index];
item* n = new item;
n->name = name;
n->drink = drink;
n->next = NULL;
while (ptr->next != NULL) {
ptr = ptr->next;
}
ptr->next = n;
}
}
int Hash::numItemsIndex(int index){
int count = 0;
if (HashTable[index]->name == "empty")
return count; //0
else {
count++;
item* ptr = HashTable[index];
while (ptr->next != NULL) {
count++;
ptr = ptr->next;
}
}
return count;
}
void Hash::printTable(){
int number;
for (int i = 0; i < tableSize; i++) {
number = numItemsIndex(i);
cout << "-------------------------\n";
cout << "Index = " << i << endl;
cout << HashTable[i]->name << endl;
cout << HashTable[i]->drink << endl;
cout << "# of items = " << number << endl;
cout << "-------------------------\n";
}
}
void Hash::printItemsInIndex(int index){
item* Ptr = HashTable[index];
if (Ptr->name == "empty")
cout << "Index " << index << " is empty. \n";
else {
cout << "Index " << index << " contains the following items: \n";
while (Ptr != NULL) {
cout << "-------------------------\n";
cout << Ptr->name << endl;
cout << Ptr->drink << endl;
cout << "-------------------------\n";
Ptr = Ptr->next;
}
}
}
int main(int argc, char* argv[]) {
Hash Hashy; //create of tablesize 10 and initialize
// all with items -> empty, empty, NUll.
Hashy.addItem("Paul", "Locha");
Hashy.addItem("Kim", "Iced Mocha");
Hashy.addItem("Emma", "Strawberry Smoothie");
Hashy.addItem("Annie", "Hot Chocolate");
Hashy.addItem("Sarah", "Passion Tea");
Hashy.addItem("Pepper", "Caramel Mocha");
Hashy.addItem("Mike", "Chai Tea");
Hashy.addItem("Steve", "Apple Cider");
Hashy.addItem("Bill", "Root Beer");
Hashy.addItem("Marie", "Skinny Latte");
Hashy.addItem("Susan", "Water");
Hashy.addItem("Joe", "Green Tea");
Hashy.printTable();
//Hashy.printItemsInIndex(8);
system("pause");
return 0;
}
There are some things in the output section, but I don't know what they mean:
'LetsHash.exe' (Win32): Loaded 'C:\Users\Rohan Vidyarthi\Desktop\LetsHash\Debug\LetsHash.exe'. Symbols loaded.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ntdll.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\kernel32.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Unloaded 'C:\Windows\SysWOW64\kernel32.dll'
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\kernel32.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\KernelBase.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\vcruntime140d.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\WRusr.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ucrtbased.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcrt.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcp140d.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\user32.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\win32u.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\gdi32.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\gdi32full.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\shell32.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\cfgmgr32.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\windows.storage.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\combase.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ucrtbase.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\rpcrt4.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\sspicli.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\cryptbase.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\bcryptprimitives.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\sechost.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\powrprof.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\advapi32.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\shlwapi.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\kernel.appcore.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\SHCore.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\profapi.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ole32.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\psapi.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ws2_32.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\oleaut32.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\wininet.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\oleacc.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcp_win.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\urlmon.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\secur32.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msimg32.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\iertutil.dll'. Cannot find or open the PDB file.
'LetsHash.exe' (Win32): Loaded 'C:\Windows\SysWOW64\imm32.dll'. Cannot find or open the PDB file.
The thread 0xbc8 has exited with code 252968960 (0xf140000).
The thread 0x1700 has exited with code 0 (0x0).
The thread 0x19bc has exited with code 0 (0x0).
The thread 0x1b70 has exited with code 0 (0x0).
The program '[3484] LetsHash.exe' has exited with code 0 (0x0).
Your hash function does not produce a unique number for each string, therefore some of the indices will be duplicate. You can see this if you print out the index for each string:
Paul, 0
Kim, 3
Emma, 6
Annie, 7
Sarah, 1
Pepper, 2
Mike, 2
Steve, 9
Bill, 9
Marie, 0
Susan, 6
Joe, 8
You will need a much larger range for the hash values to avoid hash collisions. 0..9 is too small range and it will almost generate a collision with your current approach.
The error are due to you dont have symbol files for ntdll and all other. What you can do to avoid this error are :- There are multiple options you can have.
Download symbol package provided by microsoft. This will download PDB for all system libraries. Extract it to "c:\symbolcache"
Set symbol path to SRVc:\symbolcachehttp://msdl.microsoft.com/download/symbols. In this case this will download PDB files into "c:\symbolcache" if not present.
Then you have to set "c:\symbolcache" as your symbol file path into whatever crash dump analysis tool you are using.
For the error can you share the code how are you calling the hash.

error with using memcpy

I try to connect c++ to matlab for figure function. for the example
Engine *m_pEngine;
m_pEngine = engOpen("null"); //open matlab engine
const int arraysize = 1000;
const double degTorad = .0174;
double SinArray[arraysize];
double CosArray[arraysize];
double Degrees[arraysize];
for (int iii = 0; iii < arraysize; iii++)
{
Degrees[iii] = iii;//gets the degree
SinArray[iii] = sin(iii*degTorad);
CosArray[iii] = cos(iii*degTorad);
}
cout << "Example 1 or 2?"<<"\n";
char Sim = '1';
cin >> Sim;
// example 1 below
// we will pass an entire array to be plotted
if (Sim == '1')
{
mxArray* SIN = mxCreateDoubleMatrix(arraysize, 1, mxREAL);
memcpy((void *)mxGetPr(SIN), (void *)SinArray, sizeof(double)*arraysize);
engPutVariable(m_pEngine, "SinGraph", SIN);
mxArray* COS = mxCreateDoubleMatrix(arraysize, 1, mxREAL);
memcpy((void *)mxGetPr(COS), (void *)CosArray, sizeof(double)*arraysize);
engPutVariable(m_pEngine, "CosGraph", COS);
mxArray* DEG = mxCreateDoubleMatrix(arraysize, 1, mxREAL);
memcpy((void *)mxGetPr(DEG), (void *)Degrees, sizeof(double)*arraysize);
engPutVariable(m_pEngine, "Degrees", DEG);
engEvalString(m_pEngine, "figure('units','normalized','outerposition',(0 0 1 1))"); //opens up matlab figure window
engEvalString(m_pEngine, "plot(Degrees,SinGraph,'r',Degrees,CosGraph,'b'),grid minor,title('our Matlab Plot')");
system("pause");
}
it runs well and I can get the correct results. that means the environment setting in my computer is correct. but when run the code below:
for (int i = 0; i < 141; i++)
{
x.push_back(((-141 / 2 + 1 - 1+i)*0.0003));
y.push_back(((-141 / 2 + 1 - 1+i)*0.0003));
}
engine *m_pEngine;
m_pEngine = engOpen("null"); //open matlab engine
mxArray *xxx = mxCreateDoubleMatrix(1, 141, mxREAL);
memcpy((void*)mxGetM(xxx), &x, sizeof(double)*x.size());
engPutVariable(m_pEngine, "x", xxx);
mxArray *yyy = mxCreateDoubleMatrix(1, 141, mxREAL);
memcpy((void*)mxGetM(yyy), &y, sizeof(double)*y.size());
engPutVariable(m_pEngine, "y", yyy);
it breaks for: Unhandled exception at 0x00007FFFB193AA69 (msvcr120d.dll) in PlanarforwardC.exe: 0xC0000005: Access violation writing location 0x0000000000000001.
and it also says that:
'PlanarforwardC.exe' (Win32): Loaded 'C:\Program Files\MATLAB\R2012b\bin\win64\libmwcholmod.dll'. Cannot find or open the PDB file.
'PlanarforwardC.exe' (Win32): Loaded 'C:\Program Files\MATLAB\R2012b\bin\win64\graphics_util.dll'. Cannot find or open the PDB file.
'PlanarforwardC.exe' (Win32): Loaded 'C:\Program Files\MATLAB\R2012b\bin\win64\libmwplatform_res.dll'. Cannot find or open the PDB file.
'PlanarforwardC.exe' (Win32): Loaded 'C:\Windows\System32\msimg32.dll'. Symbols loaded.
'PlanarforwardC.exe' (Win32): Loaded 'C:\Program Files\MATLAB\R2012b\bin\win64\libmwamd.dll'. Cannot find or open the PDB file.
'PlanarforwardC.exe' (Win32): Loaded 'C:\Program Files\MATLAB\R2012b\bin\win64\libmwcolamd.dll'. Cannot find or open the PDB file.
'PlanarforwardC.exe' (Win32): Loaded 'C:\Program Files\MATLAB\R2012b\bin\win64\libmwblas.dll'. Cannot find or open the PDB file.
'PlanarforwardC.exe' (Win32): Loaded 'C:\Program Files\MATLAB\R2012b\bin\win64\libmwlapack.dll'. Cannot find or open the PDB file.
'PlanarforwardC.exe' (Win32): Loaded 'C:\Windows\System32\SHCore.dll'. Symbols loaded.
'PlanarforwardC.exe' (Win32): Loaded 'C:\Program Files\MATLAB\R2012b\bin\win64\libmwbinder.dll'. Cannot find or open the PDB file.
'PlanarforwardC.exe' (Win32): Loaded 'C:\Program Files\MATLAB\R2012b\bin\win64\libmwompwrapper.dll'. Cannot find or open the PDB file.
DBGHELP: Symbol Search Path: C:\Users\Gabrielle\Desktop\PlanarforwardC\x64\Debug
DBGHELP: C:\Users\Gabrielle\Desktop\PlanarforwardC\x64\Debug\m_interpreter.pdb - file not found
DBGHELP: C:\Users\Gabrielle\Desktop\PlanarforwardC\x64\Debug\dll\m_interpreter.pdb - file not found
DBGHELP: C:\Users\Gabrielle\Desktop\PlanarforwardC\x64\Debug\symbols\dll\m_interpreter.pdb - file not found
DBGHELP: y:\R2012bd\build\matlab\bin\win64\m_interpreter.pdb - file not found
DBGHELP: m_interpreter - export symbols
DBGHELP: C:\Users\Gabrielle\Desktop\PlanarforwardC\x64\Debug\msvcr90.amd64.pdb - file not found
DBGHELP: C:\Users\Gabrielle\Desktop\PlanarforwardC\x64\Debug\dll\msvcr90.amd64.pdb - file not found
DBGHELP: C:\Users\Gabrielle\Desktop\PlanarforwardC\x64\Debug\symbols\dll\msvcr90.amd64.pdb - file not found
DBGHELP: msvcr90.amd64.pdb - file not found
memcpy((void*)mxGetM(xxx), &x, sizeof(xx));
I also tried to find the solution and use double xx[141]and double yy[141]replace vector x and vector y.
mxArray *xxx = mxCreateDoubleMatrix(1, num_x, mxREAL);
memcpy((void*)mxGetM(xxx), (void*)xx, sizeof(xx));
engPutVariable(m_pEngine, "x", xxx);
mxArray *yyy = mxCreateDoubleMatrix(1, num_x, mxREAL);
memcpy((void*)mxGetM(yyy), (void*)yy, sizeof(double)*y.size());
engPutVariable(m_pEngine, "y", yyy);
it still didn't work.
can anyone give me some suggestions about this? I tested line by line and the problem is in :
many thanks
mxGetM returns the size of the array. This size is used as an pointer in memcpy, which definitely leads to an invalid memory address.