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 6791557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:51:39+00:00 2026-05-26T17:51:39+00:00

When I compile my program in debug mode GetOpenFileName(&ofn) never returns. It works perfectly

  • 0

When I compile my program in debug mode GetOpenFileName(&ofn) never returns.

It works perfectly fine in release mode. The only difference I can spot is that a lot of things are being optimized away in release mode.

OPENFILENAME ofn;
TCHAR szFile[MAX_PATH];

szFile[0] = '\0';
szFile[1] = '\0';

//Initialize OPENFILENAME
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = NULL;
ofn.lpstrFile = szFile;
ofn.lpstrFile[0] = '\0';
ofn.nMaxFile = MAX_PATH;
ofn.lpstrFilter = TEXT("Images (*.jpg;*.png;*.bmp;*.tga;*.psd)\0*.jpg;*.png;*.bmp;*.tga;*.psd\0\0");
ofn.lpstrInitialDir = TEXT(".");
ofn.lpstrTitle = TEXT("Open 512x512 image");
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
...
GetOpenFileName(&ofn)

I’m compiling using Unicode character set.

If I remove \0 from the middle of ofn.lpstrFilter it works in debug mode, but obviously the filter doesn’t function correctly.

This is how the string looks like in the memory in both debug and release mode around the \0 spot:

...snip...
0x00364BB4  70 00  p.
0x00364BB6  73 00  s.
0x00364BB8  64 00  d.
0x00364BBA  29 00  ).
0x00364BBC  00 00  ..
0x00364BBE  2e 00  ..
0x00364BC0  6a 00  j.
0x00364BC2  70 00  p.
0x00364BC4  67 00  g.
0x00364BC6  3b 00  ;.
...snip...

I’m probably doing something silly (I don’t have much winapi /w Unicode experience), but I can’t figure out what. Any ideas?

EDIT: Updated with current code.

Basically

ofn.lpstrFilter = TEXT("Images (*.jpg;*.png;*.bmp;*.tga;*.psd)*.jpg;*.png;*.bmp;*.tga;*.psd\0");
                                                              ^

works, but

ofn.lpstrFilter = TEXT("Images (*.jpg;*.png;*.bmp;*.tga;*.psd)\0*.jpg;*.png;*.bmp;*.tga;*.psd\0");
                                                              ^

doesn’t.

EDIT: Tried reproducing same error in fresh Visual Studio project and I couldn’t. It works. Did a diff on project settings and there aren’t any mayor differences.

  • 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-05-26T17:51:40+00:00Added an answer on May 26, 2026 at 5:51 pm

    I finally isolated the only difference between the builds:

    I was using Visual Leak Detector in my debug build. After removing it, it started to work.

    I’ll try to get to the bottom why it happens, but I just wanted to thank every one trying to help me. I wish I could reward more points.

    Some more people having similar problems:

    • http://vld.codeplex.com/workitem/9519
    • http://vld.codeplex.com/discussions/277407
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a program that must be compiled only in DEBUG mode. (testing purpose)
Expected output & output I get in debug mode, and release mode under VS2010,
If I understand correctly then the release mode enables a program to run faster
I get a strange behavior when I compile the same program in Release in
SUMMARY: How to compile in Release mode...I cannot get it to take what I
My program will not successfully compile in /MT (MultiThreaded) mode. It Compiles in /MD
I think that I understand the difference between Release and Debug build modes. The
Is there any reason for a program to leak when compiled in Debug mode
Tutorials for gdb suggest compiling with 'gcc -g' to compile the program with debug
because of compatibility issues, I compile my project in VS2008 in release mode, but

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.