Greg Dolley’s Weblog

A Blog about Graphics Programming, Game Programming, Tips and Tricks

  • Archives

  • January 2008
    M T W T F S S
    « Dec   Feb »
  • Blog Stats

    • 1,051,574 hits
  • Subscribers

  • Twitter

    Error: Twitter did not respond. Please wait a few minutes and refresh this page.

How to Fix – "C2039: ‘GetCurrentDirectoryA()’ : is Not a Member of ‘System::IO::Directory’"

Posted by gregd1024 on January 10, 2008

Have you ever received either one of these annoying error messages from the MSVC++ 9.0 compiler?

“C2039: ‘GetCurrentDirectoryW’ : is not a member of ‘System::IO::Directory'”

“C2039: ‘GetCurrentDirectoryA’ : is not a member of ‘System::IO::Directory'”

You’ll get this error when converting a native C++ project to a MC++ (managed) project and somewhere in your code there is a call to Directory::GetCurrentDirectory(). Below is a very simple example:

#include “stdafx.h”

#include <windows.h>


using namespace System;
using namespace System::IO;


int main(array<System::String ^> ^args)
    Console::WriteLine(L”Dir: “+Directory::GetCurrentDirectory()); // Error!
    return 0;

The reason for the error is that “GetCurrentDirectory” is also defined as a macro in windows.h. The macro expands to “GetCurrentDirectoryA” or “GetCurrentDirectoryW.” So in the example above, the compiler actually sees “Directory::GetCurrentDirectoryW” which obviously isn’t defined in the “Directory” class.

The fix is simple – just “#undef” the macro:

#include “stdafx.h”

#include <windows.h>


using namespace System;

using namespace System::IO;


#undef GetCurrentDirectory


int main(array<System::String ^> ^args)

    Console::WriteLine(L”Dir: “+Directory::GetCurrentDirectory()); // OK


    return 0;


Now the compiler sees the real “GetCurrentDirectory” function and there are no compile errors. 🙂

-Greg Dolley

Subscribe via RSS here. Want email updates instead? Click here.

5 Responses to “How to Fix – "C2039: ‘GetCurrentDirectoryA()’ : is Not a Member of ‘System::IO::Directory’"”

  1. prateek kumar said

    Thanks dude… that stuff was really cool. keep sharing similar interesting tid-bits 😀

  2. Abhay said

    Thanks a lot. Really saved an hours work for me!!! 😀

  3. Alex said

    Thanks man,
    Short description, well explained fix -> perfect!

  4. Martin said

    Thanks, great tip, well explained.


  5. Shail said

    Thanks,Good explaination and quite useful.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: