Using custom script files with C++ project in Visual Studio 2019 - c++

TL;DR
My project uses a custom script file at runtime.
My project builds fine in VS and runs on the command line.
However when running in VS an error is thrown implying the file doesn't exist.
Full Details
My c++ project uses a custom scripting file to apply some settings at run time:
these are javascript like but not actual javascript
having these settings not in compiled files means they may be changed without recompiling
Everything builds fine, the script is copied using xcopy in a post build event.
When running in VS2019 it doesn't seem to be able to find the scripting file.
An opaque, library specific error is issued: A GenApi error has occurred
But when running the resulting .exe from cmd everything works, the script is used no problem.
If the script file is removed from the output dir and the .exe is run again I get the same A GenApi error has occurred.
I have tried:
running in release and debug.
including and excluding the file from the build.
I don't want to debug the script, I just need it to be used during start up so I can debug the rest of the program which is in C++.....
Example Code
Main.cpp
#include <iostream>
#include <EGrabber.h>
void configure() {
Euresys::EGenTL gentl;
Euresys::EGrabber<> grabber(gentl);
grabber.runScript("config.js");
}
int main() {
try {
configure();
} catch (const std::exception &e) {
std::cout << "error: " << e.what() << std::endl;
}
}
config.js
var grabber = grabbers[0];
var FPS = 150;
// camera configuration
grabber.RemotePort.set("TriggerMode", "On");
grabber.RemotePort.set("TriggerSource", "CXPin");
grabber.RemotePort.set("ExposureMode", "TriggerWidth");
// frame grabber configuration
grabber.DevicePort.set("CameraControlMethod", "RG");
grabber.DevicePort.set("CycleTriggerSource", "Immediate");
grabber.DevicePort.set("CycleMinimumPeriod", 1e6 / FPS);
More info:
script documentation

based on #john 's comment:
There is a different current working directory when running from VS and when running from the command line.
When run from VS the current working directory is the project directory not the output directory.
The script was in project-dir\src not the immediate project dir.
Moving the script up to the project directory solved everything.
Alternative solutions, which worked:
Use the full path: C:\\full\\path\\config.js
(the application startup path can be extracted from argv[0])
Change the debug working directory in VS:
Project -> Properties -> Configuration Properties -> Debugging -> Working Directory
Enter output path, eg: $(SolutionDir)bin$(Platform)$(Configuration)\

Related

xlwings: "Run main" cannot find filepath?

I'm new to xlwings - started with trying to understand basics but it is not working ...
Created .py and .xlsx files (with same name) in same folder; inserted basic "Hello World" code as main() in .py file.
Using Run main button in Excel file gives:
Run-time error '53': File not found
Tried to trouble-shoot why this could be: debugging via VBA interface found that the routine was searching in the folder C:\Users\MYNAME\AppData\LocalTemp\ (not the project's folder) and coming up with a very long .log filename which changes each time I attempt to run it (eg. xlwings-374ABEE7-4C51-8622-AB5B-D42C5294C2B8.log)
Is this a bug which needs to be corrected? or have I done something incorrectly?
Using:
Windows 10;
MS Office 365;
xlwings ver: 0.19.5

Save a file and make the console not to close: Visual Studio 2019

I am new to C++ and I am using the free version of Microsoft Visual Studio 2019.
I have written a small code which I use to integrate some differential equations (by using odeint libraries provided by Boost).
After the integration process ends, the time evolutions of the state variables are stored in the matrix mat (I use the Eigen libraries to define it row by row):
MatrixXd mat(t,4);
for (int i = 0; i <= t-1; i++)
{
mat.row(i) << times[i], x_vec[i][0], x_vec[i][1], x_vec[i][2] ;
};
Then I save the content of the matrix in a .txt file:
ofstream file("mat_save.txt");
if (file.is_open())
{ file << mat << '\n'; }
file.close();
However the .txt file is created only if I run the code in Debug mode, while if I only compile it the file is no longer created and no output can be displayed in the Console, since it is only opened when Debug mode is chosen.
Is there a way to make the Console appear and remain open and also to make the .txt file to be successfully saved, simply "compiling" the code avoiding debugging?
If so, I would save lot of time because the debugging is quite slow.
Thanks in advance!!
I'm not sure if by debug you mean running the code in Visual Studio vs compiling and then running the created exe. It Kind of sounds like a relative path issue.
Try using a full path. Or try opening a command prompt, cding to the path with the exe and then running it and check to see if the file is created in the folder you cded to.
You can also try opening the exe in Visual Studio like it was a project. Another thing to try is attaching VS to a running process to debug: http://msdn.microsoft.com/en-us/library/c6wf8e4z.aspx
The Windows Powertool "Handle" can display what handles a process is currently using which could be useful in determining if it is writing a file somewhere unexpected: https://learn.microsoft.com/en-us/sysinternals/downloads/handle

OpenCV program compiles but doesn't run

I am working on Windows 8 with OpenCV 2.4.13 and MinGW 4.9.
I wrote a simple and small opencv program to check if everything was installed properly. Following is the code:
#include <opencv2/highgui/highgui.hpp>
int main () {
printf("in main\n");
for (int i = 0; i<10; i++) {
printf("here\n");
IplImage * image = cvLoadImage("C:/{...}/test.jpg");
cvReleaseImage(&image);
}
return 0;
}
I compiled it with the following command at the command prompt:
g++ -o test test.cpp -LC:\{...}\opencv\build\x64\vc11\lib -lopencv_core2413 -lopencv_highgui2413 -IC:\{...}\opencv\build\include
{...} is the path to the specified folder/file.
This command runs properly and compilation is successful without any errors. However, when I run it with:
test
in main and one here gets printed after which I get the error message as 'test.exe has stopped working. Windows is looking for a solution.'
What all I have tried:
For installation of OpenCV, ran the downloaded opencv executable file (which extracts all files) and added the system variable OPENCV_DIR and edited the system PATH for location of DLLs (which reside in %OPENCV_DIR%\bin) as per:
http://docs.opencv.org/2.4/doc/tutorials/introduction/windows_install/windows_install.html#installation-by-using-the-pre-built-libraries
Tried adding the required DLLs in the same directory as the .exe.
Tried doing the whole thing from vc12 directory.
After the error message appears, it gives an option of debugging. On pressing that, the Just In Time Debugger opens up and says 'An unhandled win32 exception occurred in test.exe'. I googled this and tried inspecting the registry key as directed here
https://support.microsoft.com/en-us/kb/811191
but it was already properly set. So, there was nothing for me to change in that.
Nothing is working for me at all. Please let me know if any more information is required. I'm desperately looking for a solution to this.
For those who might be encountering the same problem, I compiled the program with OpenCV dynamic (.dll) libraries instead of the .lib files and it ran just fine at runtime for some reason.

OCCI app crashes when running in debug mode in Visual Studio 2005

I'm attempting to get a development environment up and running for developing applications with Oracle C++ Call Interface (OCCI) in Visual Studio 2005.
My system specs are:
OS: Windows 7, 64-bit
Oracle: 11g release 11.2.0.2, 32-bit
Instant Client: BasicLite and SDK version 11.2.0.4 32-bit
Visual Studio 2005 Professional Edition version 8.0 with 32-bit tools enabled
I've followed this guide by Mark Williams and I got the example running but only in release mode. When I switch to debug mode the app will build, but when I run it I get the following error:
Problem signature:
Problem Event Name: APPCRASH
Application Name: OCCITest.exe
Application Version: 0.0.0.0
Application Timestamp: 53f5dfdd
Fault Module Name: KERNELBASE.dll
Fault Module Version: 6.1.7601.18229
The small example program that triggers this error is:
#include "employees.h"
using namespace std;
using namespace oracle::occi;
int main (void)
{
Employees *pEmployees = new Employees();
delete pEmployees;
return 0;
}
Employees::Employees()
{
user = "hr";
passwd = "hr";
db = "localhost:1521/service_name";
env = Environment::createEnvironment(Environment::DEFAULT);
try
{
con = env->createConnection(user, passwd, db);
}
catch (SQLException& ex)
{
cout << ex.getMessage();
exit(EXIT_FAILURE);
}
}
Employees::~Employees()
{
env->terminateConnection (con);
Environment::terminateEnvironment (env);
}
If I remove all calls to OCCI functionality the application doesn’t crash. That is, this program runs error-free:
#include "employees.h"
using namespace std;
using namespace oracle::occi;
int main (void)
{
Employees *pEmployees = new Employees();
delete pEmployees;
return 0;
}
Employees::Employees()
{
user = "hr";
passwd = "hr";
db = "localhost:1521/service_name";
cout<<"Look at me, I'm running"<<endl;
}
Employees::~Employees()
{}
In the guide Mark mentions that when running in debug mode, the linker should use the library file oraocci11d.lib. However, this file is not included in the Instant Client SDK version 11.2.0.4, so I’m using the input file oraocci11.lib for both the release and debug version.
I'm running out of ideas about how to proceed in solving this problem, and I would greatly appreciate any and all help.
If the Oracle DLL receives and/or passes objects such as std::string or any other object that either:
Manipulates the heap in any way, or
The objects could have differing internals between app and DLL,
then you have no choice but to use the correct library to link with. Otherwise you wind up with binary or heap incompatible objects being passed, which leads to what you're seeing now.
See here: http://docs.oracle.com/cd/E11882_01/appdev.112/e10764/install.htm#CBHGBBJI
The link above mentions both the debug import library and debug version of the DLL. Also this is stated at the link:
Applications that link to MSVCRTD.DLL, a debug version of Microsoft C-Runtime, /MDd compiler flag, should link with these specific OCCI libraries: oraocci11d.lib and oraocci11d.dll.
Since it took me quite some time to get the debug environment working I figured I'd answer my own question now that I did.
I got a variety of errors throughout the ordeal, but the error that I got most stuck on was an error saying:
'The application was unable to start correctly (0xc0150002).
Click OK to close the application.'
Also, I used http://www.dependencywalker.com which repeatedly told me that either oraocci11d.dll or a the following list of dll's could not be found.
API-MS-WIN-APPMODEL-RUNTIME-L1-1-0.DLL
API-MS-WIN-CORE-WINRT-ERROR-L1-1-0.DLL
API-MS-WIN-CORE-WINRT-L1-1-0.DLL
API-MS-WIN-CORE-WINRT-ROBUFFER-L1-1-0.DLL
API-MS-WIN-CORE-WINRT-STRING-L1-1-0.DLL
API-MS-WIN-SHCORE-SCALING-L1-1-1.DLL
DCOMP.DLL
IESHIMS.DLL
However, what was really missing was for the executable to be able to find oci.dll. I'm just mentioning the errors in case someone else runs into these.
Here is what was needed to make it work:
First of all, the Instant Client does not contain the oraocci11d.lib or oraocci11d.dll, so it is necessary to install the full Oracle Client.
Next, the following must be added to the PATH:
C:\Program Files\Oracle\11.2.0\OCI\lib\MSVC\vc8
C:\Program Files\Oracle\11.2.0\BIN
In Visual Studio, select Tools -> Options, unfold 'Projects and Solutions' and select VC++ Directories. In 'Show directories for' under:
Include Files add C:\Program Files\Oracle\11.2.0\OCI\include
Library files add C:\Program Files\Oracle\11.2.0\OCI\lib\MSVC\vc8
In the property page for your project under Configuration Properties -> Linker select Input and under Additional Dependencies add oraocci11d.lib (or oraocci11.lib for release mode). Then select debug/release mode in the Configuration Manager
I have a related problem in that I am successfully using oraocci12d.dll/msvcr100d.dll, but this in turn is using oci.dll/msvcr100.dll. ie, oci.dll is not using the debug version of msvcr100.
My program seems to run okay, but any memory leak reporting disappears on exit.

CascadeClassifier.load() error in release only

I want to ask about cascadeclassfier load doesn't work in release.
I using Microsoft Visual Studio 2010 and OpenCV 2.4.7.
my code:
CascadeClassifier cascade;
if(!cascade.load("D:/data/training.xml"))
{
printf("Error load XML!\n");
return -1;
}
Things i've tried so far:
Tried to specify the path manually using ""
Tried to use / or \ in the path
Tried to give user permission
Tried to call the xml without using absolute path
Tried to use many kind of codes i've found when searching this error
Tried to seperate the xml by creating a new folder for them
Additional Information:
Running in debug mode work 100% perfectly
Running in release while using visual studio trigger a break
Running using the exe created while building only show "Error load XML!"
i really confused right now, so i decided to ask..
Thanks before.
I've had similar problems when switch from Debug to Release Mode. I had copy config from Debug to Release and mistake at Linker > Input > Additional Dependencies. And I had fix this problem by using opencv_world320d.lib for Debug mode and opencv_world320.lib for Release mode.