Windows Service failes to start with "Path '.' not found" - c++

Disclaimer: the error message is translated from Swedish (and it's a pain to find the exact corresponding error message in English, Microsoft take note...)
The error message could also be "Path ' ' not found" or "Path not found". It's a bit unclear due to the Swedish message not enclosing the path in ' '.
This is similar to this question, but not exactly: New Windows Service installed, fails to start: "System error 2 ... system cannot find the file specified"
I have written the service myself. It is an exe written in unmanaged C++ and is using the following external code:
libntlm - loaded as dynamic library (libntlm-0.dll placed in same location as executable)
OpenSSL - loaded as static library
pugixml - compiled directly into code
The problem I'm having is that it doesn't start when Windows starts, but it does start if I manually start it!
I am stumped as to what could be wrong. The only thing I can think of is if perhaps the dll can't be found, but I don't know why it wouldn't. Something with the environment variables being different perhaps?
What I have tried:
Checked registry, path is correct
Path is to local disk
Changed to a number of different paths (no change)
Made sure there are no spaces in the path
Logging at start of program (nothing written to log, so it's not an internal path not found error)
Dll is in same path
Set to start with my own network account (no change)
Tried renaming exe to be the same as service name (no change)
Tried registering libntlm-0.dll with regsrv32 but that didn't work
Put libntlm-0.dll in System32 (no change)

For posterity it seems like the delayed start suggested by 51k seems to work. I don't know why that should make any difference, but as long as it works I'm happy.

Related

Managed debugging does not work anymore, due to wrong version of mscordbi.dll

I'm trying to debug a memory dump, using Visual Studio, as managed, but this fails with following error message:
Managed debugging is not available for this minidump.
A required library for managed minidump debugging,'mscordbi.dll', version '4.0.30319.0', could not be located.
Restart your debug session after trying one of more of the following steps:
If this computer is not currently connected to the internet, connect so the dll can be downloaded from Microsoft.
Specify the path to 'mscordbi.dll' in Symbol Settings under Debugger options.
Select 'Debug with Native Only'.
While checking my Symbol Settings, there are following Symbol file (.pdb) locations (all are checked):
Environment Variable: _NT_SYMBOL_PATH
Microsoft Symbol Servers
C:\Dump_Repository\... (not relevant for this question)
A cache directory is foreseen, and the automatic loading preference is set to Load all modules, unless excluded. The only excluded one is user32.dll.
The value of the _NT_SYMBOL_PATH environment variable is the following:
cache*;srv*C:\Dump_Analyse*C:\build_machine1;cache*;srv*C:\Dump_Analyse*\\build_machine2\Development\Symbols;cache*;srv*C:\Dump_Analyse*\\build_machine1\Symbols;cache*;srv*https://msdl.microsoft.com/download/symbols;cache*;srv*C:\ProgramData\dbg\sym
In the mentioned directory C:\Dump_Analyse, there is a directory mscordbi.dll, with three subdirectories, each containing the mentioned mscordbi.dll DLL:
Prompt>find ./ -name "mscordbi.dll" 2>/dev/null
./Dump_Analyse/mscordbi.dll (this is a directory)
./Dump_Analyse/mscordbi.dll/4BA1DA2Deb000/mscordbi.dll
./Dump_Analyse/mscordbi.dll/563C0E8E10b000/mscordbi.dll
./Dump_Analyse/mscordbi.dll/583E5AAD10b000/mscordbi.dll
The two last ones seem not that relevant, but the first one has file version 4.0.30319.1 (which is very near to the requested version).
My computer is connected to the internet, my account seems to be ok (I have recently modified the password of my Windows account, but I'm logged in on Visual Studio under another account).
Does anybody know what might be happening here and how I can solve this issue?
The problem is solved:
While trying further, I wanted to clear the symbol cache, which did not work (a user permission was said not to be correct).
That cache symbols was a directory, containing a tilde character: ~ (something like C:\Users\Dominique~1\AppData\Local\Temp\SymbolCache).
I've replaced this by the real directory name (by clicking the Browse button):
C:\Users\DominiqueDS\AppData\Local\Temp\SymbolCache
In other words (for searching purposes): in Visual Studio Symbol settings, the symbols cache directory should not contain a ~ (tilde) character.

System error - "the code cannot proceed because .dll was not found."

I'm getting this error when I try to run my app:
I checked and there is no reason that I can see that it wouldn't be able to find libnlopt-0.dll. Here it is (note GlassModelCalcualator is the DLL that uses libnlopt-0.dll), in the GlassModelCalcualatorDLL folder:
and in the debug folder of GlassModelCalcualatorDLL:
I have a different program that has a console which uses GlassModelCalcualator.dll and that also has this issue. To fix that, I had to put libnlopt-0.dll in the Debug folder of GlassModelCalcualator.
I'm assuming this is not the same problem here since you can clearly see that libnlopt-0.dll is in GlassModelCalcualator's Debug folder.
Any ideas?
Windows will follow a hierarchical order when searching for dll's.
You could place your dll in the same directory as the exe or even in the Windows system folders (only if you're absolutely sure you want to keep this dll forever as there's no cleanup)
https://msdn.microsoft.com/en-us/library/windows/desktop/ms682586(v=vs.85).aspx

Xml parsing exception on relative path with Eclipse gdb DSF debug

I'm using Eclipse Mars, with gdb 7.2.
While trying to debug a C++ application in Eclipse gdb DSF, I'm getting a parse exception. But I don't get the parse exception when I run the same program with gdb outside of Eclipse.
The exception states: "Fatal error during XML Parsing: unable to open primary document entity /path/to/file.xml"
But the actual path in xml is a relative path: "../../../../path/to/file.xml".
The C++ application is reading in the XML and trying to open this file.
It's as if the ../..'s are just getting chopped off, and that's why the error states essentially "I don't know about a /path/to/file.xml"
I imagine that something is wrong with my gdb setup in Eclipse, but I'm not sure what. I've tried many different things, none of which seem to work.
I imagine that this has something to do with relative paths not being recognized by gdb, or the working path being different in Eclipse vs gdb.
Does anyone have an idea what is wrong?
You need to make sure the Working Directory matches the location of the executable in the File System.
https://sourceware.org/gdb/onlinedocs/gdb/Working-Directory.html
Actually, this was a simple issue: It turns out that my Working Directory(in Debug Configurations under the Arguments tab) had to be set to the full path of the location of my executable.
I also had to set the path of my executable to the full File System path of the executable.
It works as expected now.

Running exe code from Matlab. The exact same instruction that works in cmd (dos) fails from Matlab

This is driving me crazy, I must admit. After finally being able to successfully compile two functions I need to process voice files, from C/C++ code that I downloaded from a trustworthy online repository (code that had been thoroughly tested in Linux), I am now struggling to launch those files from Matlab...
When I type the following command in cmd (dos)
Analysis b2.wav config_default
it works, no problem (see here Works).
Then, I build the exact same command into a string and feed it to the "system" Matlab function. Then the code crashes... (see here Fails) I've tried with full paths (c:\b2.wav, etc) but still does not work...
Any ideas as to why this might be happening?
Your image shows that the program Analysis stopped unexpectedly.
It might be a lot of reasons why, so let's go step by step:
1) Try executing Analysis from Terminal and passing wrong parameters (a file that doesn't exist, only one param (missing the config_defalut), no parameters at all, three parameters, etc...)
Can you make the program crash from terminal by passing wrong params?
2) Try creating the command first, checking that it's correct (\b is actually \b instead of a string modifier)
command_to_be_run = 'C:\Analysis C:\b2.wav C:\config_default'
disp(command_to_be_run) % is it showing exacly what you want?
system(command_to_be_run); % if so, run it.
3) Try creating a dummy executable dummy.exe in C that accepts two parameters and prints the received parameters (keep it super simple, just printing). Call it from Terminal. Does it work? Call it from Matlba. Does it Work?
With this 3 tests you can considerably narrow down where your error comes from.
By the way, is "config_default" a file or just a string that tells analysis how to behave? In some examples you treat it as a file, in others as a parameter without path.
Based on what's been tried so far and the outputs, here's my theory:
Premise: Analysis.exe came from code that's well tested in Linux. It works in Windows command line when run from the same directory where both it and the target file reside. But it stops working from Matlab console.
Assertion 1: Matlab console does not operate within the context of the directory where the binary is but rather within the Matlab directory. As such, Analysis.exe will try to find the target from the Matlab directory.
Validation for Assertion 1: Try putting the binary and the target wav in the Matlab directory. Then run system with the binary and target specified just by name (no path).
Assertion 2: If the file's full path is specified to address this issue, it still doesn't work. This may be because the code assumed a Linux file system where the delimiter is "/" rather than "\".
Validation for Assertion 2: Run with paths specified from the command line while in a diferent directory to see if it fails or not.
Possible Solution 1: Add the directory where both Analysis.exe and the target are into the Matlab path: (1) On the Home tab, in the Environment section, click Set Path. Add the path there. (2) addpath (folderName1,...,folderNameN) adds the specified folders to the top of the search path for the current MATLAB session. -> Then run the system command without the full paths.
Possible Solution 2: Add the directory where both Analysis.exe and the target are into the Windows environment path. Then run the system command without the full paths.
EDIT: Possible hackish solution - Create a batch file where: (1) you would cd to the directory where Analysis.exe and the target wav are; and (2) do a Matlab system call to the batch file.
EDIT 2: Possible experiment to validate assertion 2.

Visual Studio - DLL dependency not found DESPITE Environment variable being set

I have written a C application that depends on a few DLLs and am having some trouble when using the local debugger. It's this well documented error message:
"This program can't start because xxx.dll is missing from your
computer."
Right now it's portaudio_x86.dll but the DLL is arbitrary as I'm getting the same behaviour for a bunch of others (libfftw3-3.dll, libsamplerate-0.dll, libsndfile-1.dll...)
I have been to Configuration Properties\Debugging and changed the Environment to:
PATH =
C:\portaudioASIO\portaudio\lib;%PATH%
(where the portaudio dll is)
and Merge Environment is 'Yes' (I've tried every combination and permutation of the PATH with appending, prepending, having $(ProjectDir) in the mix - all to no avail)
but this doesn't resolve it and I still get the error message "dll not found" when I debug.
I'm currently working around it by including the DLLs in the debug folder but this seems like a bit of a hack to me and from reading all the other posts [ 1, 2, 3 ] about setting the Environment PATH variable I can't see why it doesn't work.
Any tips on how to get the PATH variable to behave properly ? Cheers!
This is using MSVS Community 2015, the app is in C but the same thing happens with a C++ version.