Hi DW, I'm getting this error when I try to debug, it says it can't open "c:\users\myusername\Documents\Visual Studio 2010\Projects\myprojectname\debug\myprojectname.exe"

How can I solve this?

Recommended Answers

All 19 Replies

Given only this I won't be able to do more than comment how I use the Visual Studio system to debug my app.

  1. I open the project.
  2. I set the build to "Debug".
  3. I set breakpoints on lines of code I suspect to be problematic.
  4. I run the app while in Visual Studio.

That's usually enough to track down what I did wrong.

When you browse the file system, does that file exist and is it accessible by the logged-in user? (Sorry, no VS experience.)

commented: The file is not generated +8

@rproffitt I tried that with no luck

Since the file is not generated, try a full compile. Be sure you change to Debug for this build.
You usually can't debug what you didn't compile.

Example: There were compile or build errors which stopped the creation of the .exe file. But no mention of compile errors so I wouldn't write about that here.

I've seen this happen from Windows Defender nuking Visual Studio's compile process.
Make sure the PC is set to Developer Mode.
Whitelist the directories involved in Windows Defender.
This could happen after a Windows Update.

Check the "defender" log and see if there is any file(s) to restore.
Restarting the PC will resolve any hung/background processes that may or may not be running from VS.

I've explored self app signing and certificates, as well as giving the app raised privilages by default. There's no way I'll ever pay for a DigiCert or some other Certificate Authority (CA) for Microsoft.

I hate false positives.

I tried saving logs and going through it but I don't see where it indicate where's the problem.

Can you please save the log as a text file and attach it as an attached file here? Much thanks! :)

Here's the log, I had posted it yesterday I don't know what happened to it now or it was removed?

1>C:\Users\mypcname\Documents\Visual Studio 2010\Projects\myprojectname\Debug\myprojectname.exe : fatal error LNK1120: 16 unresolved externals

This is why you don't have an executable file.

Example:

1>myprojectname.obj : error LNK2020: unresolved token (0A0000DF) "unsigned short MyProjectName::m_hservice" (?m_hservice@MyProjectName@@$$Q3GA)
1>starter.obj : error LNK2020: unresolved token (0A0000DB) "unsigned short MyProjectName::m_hservice" (?m_hservice@MyProjectName@@$$Q3GA)
1>home1.obj : error LNK2020: unresolved token (0A0000DB) "unsigned short MyProjectName::m_hservice" (?m_hservice@MyProjectName@@$$Q3GA)

You need to define these symbols somewhere in your code for it to compile an executable.

When compiling no relevant libraries have been included for linker to link so the executable won't run as it can't be compiled with missing libraries.

In C and C++ code, the library header includes are at the top of the page.

E.g.:
#include <iostream>

Go through each error where code requires a library to be linked and add those includes at the top then recompile and hopefully you have linked all relevant libraries for your code to compile and a valid .exe file will be generated and be able to be open and run.

For function strncpy, you need these to be included at top of program:

#include <stdio.h>
#include <string.h>

Unreferenced local variable means they have not been declared in scope. Declare those variables like:
data
WfsVersion

Error says use strncpy_s instead of strncpy. Try doing that.

I followed the build process and when I hit OpenXFS_V0.0.0.5 I went looking for that project to see if folk were having build problems.

Where is this OpenXFS project to be found?

I worry this is from some Linux project and may not be ready for Win and VS2010.

I like the challenge, but hate when errors like these occur.

Check for a syntax error on line 2 in starter.h
starter.h(2): warning C4067: unexpected tokens following preprocessor directive - expected a newline

Hard to say without seeing code. Some cases m_hservice may require you to use the .lib file Advapi32.lib it if it isn't automatically linked. #pragma comment(lib, "Advapi32.lib")
Add what you need to the Project Properties > Linker > Input > Additional Dependencies

Check to make sure you have all your .lib files and paths included in the project.
E.g., verify the .lib or header file for _wfsversion.

You can also do Build > Clean Solution, and Rebuild. If you change the order of functions, and reuse old object files, you can run into this.

You can also use #define _CRT_SECURE_NO_WARNINGS before your header declarations to suppress those warnings.

Determine where these definitions are, and what is required for them:

unsigned short MyProjectName::m_hservice
struct _wfsversion MyProjectName::m_verSion
long MyProjectName::m_hr
unsigned long MyProjectName::m_dwRVersion

Here is an example using them.

#include <windows.h>
#include <iostream>

#pragma comment(lib, "Advapi32.lib")

struct _wfsversion {
    int major;
    int minor;
    int build;
};

class MyProjectName {
public:
    SC_HANDLE m_hservice;  
    SC_HANDLE m_hSCManager;  
    struct _wfsversion m_verSion; 
    long m_hr;  
    unsigned long m_dwRVersion;  

    MyProjectName() : m_hservice(nullptr), m_hSCManager(nullptr), m_hr(0) {
        m_verSion = { 1, 6, 10 }; 
        m_dwRVersion = (m_verSion.major << 16) | (m_verSion.minor << 8) | m_verSion.build;
    }

    bool OpenServiceHandle(const std::wstring& serviceName) {
        m_hSCManager = OpenSCManager(nullptr, nullptr, SC_MANAGER_CONNECT);
        if (!m_hSCManager) {
            m_hr = GetLastError();
            std::cerr << "Failed to open Service Control Manager. Error: " << m_hr << "\n";
            return false;
        }

        // Open service
        m_hservice = OpenService(m_hSCManager, serviceName.c_str(), SERVICE_START | SERVICE_QUERY_STATUS);
        if (!m_hservice) {
            m_hr = GetLastError();
            std::wcerr << L"Failed to open service '" << serviceName << L"'. Error: " << m_hr << L"\n";
            CloseServiceHandle(m_hSCManager);
            return false;
        }

        std::wcout << L"Successfully opened service handle for '" << serviceName << L"'.\n";
        return true;
    }

    bool StartService() {
        if (!m_hservice) {
            std::cerr << "Service handle is invalid.\n";
            return false;
        }

        // Start service
        if (!::StartService(m_hservice, 0, nullptr)) {
            m_hr = GetLastError();
            std::cerr << "Failed to start service. Error: " << m_hr << "\n";
            return false;
        }

        std::cout << "Service started successfully.\n";
        return true;
    }

    void PrintVersion() {
        std::cout << "Service Version: " << m_verSion.major << "."
            << m_verSion.minor << "." << m_verSion.build << "\n";
        std::cout << "Raw Version Code: " << std::hex << m_dwRVersion << std::dec << "\n";
    }

    void CloseHandles() {
        if (m_hservice) {
            CloseServiceHandle(m_hservice);
            m_hservice = nullptr;
        }
        if (m_hSCManager) {
            CloseServiceHandle(m_hSCManager);
            m_hSCManager = nullptr;
        }
    }

    ~MyProjectName() {
        CloseHandles();
    }
};

int main() {
    MyProjectName serviceManager;
    std::wstring serviceName = L"wuauserv";  // Windows Update service

    if (serviceManager.OpenServiceHandle(serviceName)) {
        serviceManager.PrintVersion();
        serviceManager.StartService();
    }
    return 0;
}

Output:

Successfully opened service handle for 'wuauserv'.
Service Version: 1.6.10
Raw Version Code: 1060a
Failed to start service. Error: 1056 //already running

or

Successfully opened service handle for 'wuauserv'.
Service Version: 1.6.10
Raw Version Code: 1060a
Service started successfully.

I've tried doing the extern to all these variables but still.

Let me clarify, the project was running fine, only started experiencing this in few weeks ago.

Regarding the question about the OpenXFS project (Library) the library is here and it's linked.

What I will do is try commenting out all the code and try debugging and see if it will debug and if it does I will uncomment one line of code at a time and see if I will figure out where's the problem if it's within the code

Let me clarify, the project was running fine, only started experiencing this in few weeks ago.#

https://en.wikipedia.org/wiki/Git

Start using it.

Every time you make forward progress, you make a commit.

Every time you make a mess of it, you revert to the last known good state and try again.

Thanks, I've never used Git before.

I've commented out all the code but still. What I think might be producing this problem is the resources.

I added a new item then changed the default to a new icon. But I did run the project successfully that time.

This is the only thing I suspect might be a result of this problem. How can I clean the resource file to make sure there are no broken link or something?

I've seen this problem before with the .rc and resource.h files, when changing icons.

Backup what you have. I remember I had to remove the resource files from the project, and the additional resource (e.g., resource1.h, resource2.h) generated headers from the project folder, when adding a new icon to replace the default.

It's probably easier to just start a new project and copy the code and redo the library with the default icon and practice your steps of replacing the icon.

I ruled it the auto-generated files everytime you delete something to cause the issue.

Does that sound familiar?

However, the compiler errors still point to some .lib or .dll file(s), function call order, and syntax error.

//Incorrect starter.h

#include "Forms1.h";

#define MY_MACRO 1 // Comment
You cannot comment after a #define or have any whitespace, tabs, spaces after.

Hope this helps. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.