Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8081567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T16:46:14+00:00 2026-06-05T16:46:14+00:00

Alright so i need to open a .txt file that will be created in

  • 0

Alright so i need to open a .txt file that will be created in the same file as the program.

I would like to use ShellExecute(); to do this and i have done a lot of research on it and i just cant seem to get the syntax correct mostly because i dont know what to do with the parameter “HWND”

I looked here for the answers and got all the info except what to put in HWND

Here is how i need the code used:

ShellExecute(0,"open","c:\\debug.txt",NULL,NULL,1);

Thanks advance for the help ask if you are unsure what i am talking about! 🙂

This is the program that i use to test the function:

  #include "DAL.h"
//DAL.h added to Testing file to make compiling easier
//Created to test show_debug()
int main(void)
{
  int test1,test2,final;

  puts("Enter 2 numbers to add (2,2)");
  scanf("%d,%d",&test1,&test2);

  log_debug(test1);
  log_debug(test2);

  view_debug();

  final= test1+test2;
  printf("%d\n",final);

  log_debug(final);

  return(0);
}

view_debug(); is the function that includes ShellExecute

void view_debug(void)//WIP
//Opens the debug.txt in notepad
{
    LoadLibrary( "shell32.dll" );
    ShellExecute(0,"open","c:\\debug.txt",NULL,NULL,1);
}

This is log_debug();

int log_debug(int test_variable)
//This function simply tests the programmers desired veriable & displays it for help in keeping track of a veriables value(integer).
//The function has support for upto 1 variable for testing
{
    time_t now;
    time(&now);

    FILE *debug; //Creates file to write debug info

    debug=fopen("debug.txt", "a+");
    fprintf(debug,"DEBUG %.24s: <%d>\n", ctime(&now),test_variable);
    //TODO: Allow more than one variable

    fclose(debug);

    return(0);
}

The file is created by the function log_debug(); and it does work but must be opened manually because ShellExecute does not work.

Full Source Here.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T16:46:15+00:00Added an answer on June 5, 2026 at 4:46 pm

    This should work for you:

    #include <windows.h>
    #include <ShellApi.h>
    
    void view_debug(const char* pszFileName)
    {
        ShellExecuteA(GetDesktopWindow(),"open",pszFileName,NULL,NULL,SW_SHOW);
    }
    
    int main()
    {
        view_debug("c:\\debug.txt");
    }
    

    If it doesn’t work, then there are likely two or three reasons:

    1. You created the debug.txt with your program code, but the file is still locked because you didn’t close the file handle (e.g. depending on how you opened the file with log_debug: fclose(), CloseHandle(), close(), etc…) or because you opened the file without the FILE_SHARE_READ flag.

    2. You don’t actually have permissions to read from the root of the c:\ drive. Which is usually true for non-admin accounts.

    3. c:\debug.txt doesn’t actually exist like you think it does.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Alright, i need to make a string defined as rootString that looks like this:
Alright, currently I have my SWF hitting a php file that will go and
Alright, so i need to be able to match strings in ways that give
Alright simple question I have integriters like 5 188 4634 And they all need
Alright, this one's interesting. I have a solution, but I don't like it. The
Alright everyone this is a bit of a complicated setup so if I need
I need an expression that will only accept: numbers normal letters (no special characters)
Alright so to start this is strictly for Windows and I'd prefer to use
Alright, what I need is a command-line application that allows you to take a
Alright, so I have a table that I need to store in a database.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.