# C++ XP compile problem

**URL:** <https://boards.straightdope.com/t/c-xp-compile-problem/319303>\
**Category:** Factual Questions\
**Created:** [August 30, 2005, 7:01pm UTC](https://boards.straightdope.com/t/c-xp-compile-problem/319303 "2005-08-30T19:01:01Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![ccwaterback](https://avatars.discourse-cdn.com/v4/letter/c/df705f/32.png) [@ccwaterback](https://boards.straightdope.com/u/ccwaterback)\
**Post date:** [August 30, 2005, 7:01pm UTC](https://boards.straightdope.com/t/c-xp-compile-problem/319303/1 "2005-08-30T19:01:01Z")

</div>

Why won’t this code compile on my system?

* * *

#include \<windows.h\>  
#include \<winbase.h\>  
#include \<stdio.h\>

(snip …)

mpDev[0] = ‘F’;  
mpDev[1] = ‘:’;  
mpDev[2] = ‘\’;  
mpDev[3] = 0;

DeleteVolumeMountPoint( (LPCTSTR) &mpDev[0] );

(snip …)

* * *

The compiler says: DeleteVolumeMountPoint: undeclared identifier.

Any ideas?

> **[Technical documentation](https://docs.microsoft.com/en-us/documentation/)**
>
> Search for in-depth articles on Microsoft developer tools and technologies.

---

<div class="post-metadata">

**Author:** ![Rysto](https://avatars.discourse-cdn.com/v4/letter/r/ecccb3/32.png) [@Rysto](https://boards.straightdope.com/u/Rysto)\
**Post date:** [August 30, 2005, 7:05pm UTC](https://boards.straightdope.com/t/c-xp-compile-problem/319303/2 "2005-08-30T19:05:53Z")

</div>

From your link

> [@](#):
>
> To compile an application that uses this function, define the \_WIN32\_WINNT macro as 0x0500 or later. For more information, see Using the SDK Headers.

---

<div class="post-metadata">

**Author:** ![spinky](https://avatars.discourse-cdn.com/v4/letter/s/59ef9b/32.png) [@spinky](https://boards.straightdope.com/u/spinky)\
**Post date:** [August 30, 2005, 7:50pm UTC](https://boards.straightdope.com/t/c-xp-compile-problem/319303/3 "2005-08-30T19:50:49Z")

</div>

And to answer the follow up question (“why do I have to do that?”), this allows you to write code which will compile to be run on older versions of windows that don’t have that particular API. If you’re writing a program that’s supposed to run on Win98, then you **want** to get an error if you try to use an API that doesn’t exist there. You use the \_WIN32\_WINNT macro to indicate the minimum platform you’re writing for.

---

<div class="post-metadata">

**Author:** ![ccwaterback](https://avatars.discourse-cdn.com/v4/letter/c/df705f/32.png) [@ccwaterback](https://boards.straightdope.com/u/ccwaterback)\
**Post date:** [August 31, 2005, 12:06am UTC](https://boards.straightdope.com/t/c-xp-compile-problem/319303/4 "2005-08-31T00:06:31Z")

</div>

Cool, thanks.

But, did that, same problem.

---

<div class="post-metadata">

**Author:** ![Bytegeist](https://avatars.discourse-cdn.com/v4/letter/b/9dc877/32.png) [@Bytegeist](https://boards.straightdope.com/u/Bytegeist)\
**Post date:** [August 31, 2005, 12:09am UTC](https://boards.straightdope.com/t/c-xp-compile-problem/319303/5 "2005-08-31T00:09:56Z")

</div>

> [@ccwaterback](#):
>
> Cool, thanks. But, did that, same problem.

Did you define the macro _before_ the ‘include’ directives?

---

<div class="post-metadata">

**Author:** ![ccwaterback](https://avatars.discourse-cdn.com/v4/letter/c/df705f/32.png) [@ccwaterback](https://boards.straightdope.com/u/ccwaterback)\
**Post date:** [August 31, 2005, 12:34am UTC](https://boards.straightdope.com/t/c-xp-compile-problem/319303/6 "2005-08-31T00:34:33Z")

</div>

Yes I did. I double and triple checked I had it typed in right too.

I installed the “general” SDK this morning. I have been programming for over 20 years.

I can’t figure it out. It finds windows.h and winbase.h, why not DeleteVolumeMountPoint?

Thanks for the ideas.

---

<div class="post-metadata">

**Author:** ![CaveMike](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/cavemike/32/16379_2.png) [@CaveMike](https://boards.straightdope.com/u/CaveMike)\
**Post date:** [August 31, 2005, 2:07am UTC](https://boards.straightdope.com/t/c-xp-compile-problem/319303/7 "2005-08-31T02:07:55Z")

</div>

> [@ccwaterback](#):
>
> I can’t figure it out. It finds windows.h and winbase.h, why not DeleteVolumeMountPoint?

No typo?

```auto

#define _WIN32_WINNT 0x0500

```

Are you using precompiled headers (e.g. stdafx.h)?

---

<div class="post-metadata">

**Author:** ![ccwaterback](https://avatars.discourse-cdn.com/v4/letter/c/df705f/32.png) [@ccwaterback](https://boards.straightdope.com/u/ccwaterback)\
**Post date:** [August 31, 2005, 2:35am UTC](https://boards.straightdope.com/t/c-xp-compile-problem/319303/8 "2005-08-31T02:35:25Z")

</div>

Well I cut and paste the #define out of the documentation. I don’t believe I am using any pre-compiled headers, just the 3 .h files I listed.

---

<div class="post-metadata">

**Author:** ![spinky](https://avatars.discourse-cdn.com/v4/letter/s/59ef9b/32.png) [@spinky](https://boards.straightdope.com/u/spinky)\
**Post date:** [August 31, 2005, 2:36am UTC](https://boards.straightdope.com/t/c-xp-compile-problem/319303/9 "2005-08-31T02:36:41Z")

</div>

[assuming you’re using Visual Studio…]  
A good way to troubleshoot this if you’re really stumped is to go into the properties dialog for the source file, look at the compiler settings, and look at the bottom of the window where it shows the actual command line it is going to use to compile. Copy that command line, open a “Visual Studio Command Prompt”, cd to the directory with your source file, and paste the command line into your shell. You should get the exact same error. Now paste the command line into notepad, add a /P option to it, and paste it into your shell again. This time, the compiler will create a .i file that matches your .cpp or .c file (e.g. foobar.cpp -\> foobar.i). This file will be very large, but also very informative. It is what results from running your source file through the preprocessor, and you can see what all the macros got converted into, and you can see what parts of header files have been skipped over because they got ifdef’d out. Examining this file should give you clues for determining if your \_WIN32\_WINNT macro is set correctly.

---

<div class="post-metadata">

**Author:** ![ccwaterback](https://avatars.discourse-cdn.com/v4/letter/c/df705f/32.png) [@ccwaterback](https://boards.straightdope.com/u/ccwaterback)\
**Post date:** [August 31, 2005, 2:37am UTC](https://boards.straightdope.com/t/c-xp-compile-problem/319303/10 "2005-08-31T02:37:05Z")

</div>

Maybe it’s LPCTSTR giving me the problem? I will try using that elsewhere and see if it complains.

---

<div class="post-metadata">

**Author:** ![ultrafilter](https://avatars.discourse-cdn.com/v4/letter/u/3d9bf3/32.png) [@ultrafilter](https://boards.straightdope.com/u/ultrafilter)\
**Post date:** [August 31, 2005, 4:08am UTC](https://boards.straightdope.com/t/c-xp-compile-problem/319303/11 "2005-08-31T04:08:48Z")

</div>

> [@ccwaterback](#):
>
> Maybe it’s LPCTSTR giving me the problem? I will try using that elsewhere and see if it complains.

Seems highly unlikely, given the error message you cited. If you haven’t already, try doing a clean build.

---

<div class="post-metadata">

**Author:** ![CaveMike](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/cavemike/32/16379_2.png) [@CaveMike](https://boards.straightdope.com/u/CaveMike)\
**Post date:** [August 31, 2005, 6:47am UTC](https://boards.straightdope.com/t/c-xp-compile-problem/319303/12 "2005-08-31T06:47:46Z")

</div>

Just throwing a few more silly things out:

1. Do you have more than one version of VC installed? Make sure it is pointing to the winbase.h that you think it is.
2. You can compile using /P to see how it processes winbase.h.
3. Do you have any of the STRICT or LEAN\_AND\_MEAN #defines enabled?
4. Try creating a bare-bones file that calls that function. Just pass 0 in for all of the args.

---

<div class="post-metadata">

**Author:** ![ccwaterback](https://avatars.discourse-cdn.com/v4/letter/c/df705f/32.png) [@ccwaterback](https://boards.straightdope.com/u/ccwaterback)\
**Post date:** [August 31, 2005, 3:30pm UTC](https://boards.straightdope.com/t/c-xp-compile-problem/319303/13 "2005-08-31T15:30:28Z")

</div>

I cut and pasted this example into a source file:

> **[Technical documentation](https://docs.microsoft.com/en-us/documentation/)**
>
> Search for in-depth articles on Microsoft developer tools and technologies.

I created a project under VC++ and tried to build it.

Same error.

---

<div class="post-metadata">

**Author:** ![ultrafilter](https://avatars.discourse-cdn.com/v4/letter/u/3d9bf3/32.png) [@ultrafilter](https://boards.straightdope.com/u/ultrafilter)\
**Post date:** [August 31, 2005, 3:51pm UTC](https://boards.straightdope.com/t/c-xp-compile-problem/319303/14 "2005-08-31T15:51:45Z")

</div>

I guess I’d find the declaration of DeleteVolumeMountPoint and make sure it’s not wrapped in some other #ifdef/#ifndef section.

---

<div class="post-metadata">

**Author:** ![ccwaterback](https://avatars.discourse-cdn.com/v4/letter/c/df705f/32.png) [@ccwaterback](https://boards.straightdope.com/u/ccwaterback)\
**Post date:** [August 31, 2005, 4:10pm UTC](https://boards.straightdope.com/t/c-xp-compile-problem/319303/15 "2005-08-31T16:10:04Z")

</div>

OK, sounds good. I can use my editor to search files. Back later.

---

<div class="post-metadata">

**Author:** ![Ponder\_Stibbons](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/ponder_stibbons/32/343_2.png) [@Ponder\_Stibbons](https://boards.straightdope.com/u/Ponder_Stibbons)\
**Post date:** [August 31, 2005, 6:08pm UTC](https://boards.straightdope.com/t/c-xp-compile-problem/319303/16 "2005-08-31T18:08:50Z")

</div>

I have just gone into Visual Studio and created a console app from the source linked above and it compiled for me with no problems at all. Looking at winbase.h, the only #define I see around DeleteVolumeMountPoint is the version one mentioned previously.

I suspect that something is set up in your search paths so that an older version of winbase.h is being used.

---

<div class="post-metadata">

**Author:** ![ccwaterback](https://avatars.discourse-cdn.com/v4/letter/c/df705f/32.png) [@ccwaterback](https://boards.straightdope.com/u/ccwaterback)\
**Post date:** [September 1, 2005, 6:00am UTC](https://boards.straightdope.com/t/c-xp-compile-problem/319303/17 "2005-09-01T06:00:07Z")

</div>

Indeed that is the problem, multiple .h files. I think if I can get my paths setup right I should eventually get this to work. Thanks.

---

<div class="post-metadata">

**Author:** ![CaveMike](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/cavemike/32/16379_2.png) [@CaveMike](https://boards.straightdope.com/u/CaveMike)\
**Post date:** [September 3, 2005, 2:49am UTC](https://boards.straightdope.com/t/c-xp-compile-problem/319303/18 "2005-09-03T02:49:15Z")

</div>

Did that work **ccwaterback**?

---

<div class="post-metadata">

**Author:** ![ccwaterback](https://avatars.discourse-cdn.com/v4/letter/c/df705f/32.png) [@ccwaterback](https://boards.straightdope.com/u/ccwaterback)\
**Post date:** [September 3, 2005, 3:13am UTC](https://boards.straightdope.com/t/c-xp-compile-problem/319303/19 "2005-09-03T03:13:22Z")

</div>

I haven’t had a lot of time to work on it. But, I did a build with everything I know of pointing in the right direction, and it still didn’t work. I think the next thing I will try is shipping the “old” .h files to some other country before I try another build!!!

One of the problems is, I have several compilers on this machine. We have to support all kinds of systems at several different version levels.

I haven’t given up yet.

🙂

---

<div class="post-metadata">

**Author:** ![spinky](https://avatars.discourse-cdn.com/v4/letter/s/59ef9b/32.png) [@spinky](https://boards.straightdope.com/u/spinky)\
**Post date:** [September 3, 2005, 9:37am UTC](https://boards.straightdope.com/t/c-xp-compile-problem/319303/20 "2005-09-03T09:37:07Z")

</div>

This isn’t a big mystery if you just do some legwork. Go into the properties dialog for the .cpp file in question. Look at the compiler settings, particularly the bottom part that shows the actual command line that compiles the file. One of the options on the command line will be responsible for including an incorrect include path (probably a /I option) that gets you the wrong winbase.h (or possibly some other wrong header which fails to include winbase.h – you can find out for sure if you follow my advice and painstakingly plow through the preprocessor output). Figure out which option is causing this, and then figure out which thing in the compiler settings (e.g. “additional include directories”) is causing that option to be added to the command line.

[Next page](https://boards.straightdope.com/t/c-xp-compile-problem/319303.md?page=2)
