Solved

I get a compiler error when I try to use System::IO::GetCurrentDirectory.  See error below.

Posted on 2003-11-23
3
484 Views
Last Modified: 2008-02-01
I get the following error:

e:\cpp\MoagicCom\MoagicCom\MainForm1.h(209): error C2039: 'GetCurrentDirectoryA' : is not a member of 'System::IO::Directory'

when I use GetCurrentDirectory in a C++ .NET form.

When I use it in a console application it works fine.

I am having the same problem w/ MessageBox::Show.  I must be doing something stupid, but can't figure it out for the life of me.

djc
0
Comment
Question by:dcornish
  • 2
3 Comments
 
LVL 48

Accepted Solution

by:
AlexFM earned 500 total points
Comment Utility
This happens because GetCurrentDirectory is defined as GetCurrentDirectoryA or GetCurrentDirectoryW in some API (not managed) header file. Possibly you are using mixed code C++ - managed and not managed. When I made some exersizes reading this article:

Using IJW in Managed C++
http://www.codeproject.com/managedcpp/nishijw01.asp

I encountered such problem too. Nish answered my question in article comments, you can read this.

Question:
How to resolve names clash?

Having the file with IJW call to MessageBox API I tried to call MessageBox::Show in the same file. The result is the names clash which I cannot resolve:

System::Windows::Forms::MessageBox::Show(this, str, sTitle);
error C2039: 'MessageBoxA' : is not a member of 'System::Windows::Forms'

or:

MessageBox::Show(this, str, sTitle);
error C2653: 'MessageBoxA' : is not a class or namespace name

In the start of cpp file I have:

#include "stdafx.h"
#using "mscorlib.dll"
#include "tchar.h"
#include "windows.h"
#using "System.dll"
#using "System.Drawing.dll"
#using "System.Windows.Forms.dll"

using namespace System;
using namespace System::Runtime::InteropServices;
using namespace System::ComponentModel;
using namespace System::Drawing;
using namespace System::Windows::Forms;

#include "MainForm.h"


Answers:
1. Do this before you try to do a MessageBox::Show -

#undef MessageBox

2. You can do this -

#pragma push_macro("MessageBox")
#undef MessageBox      MessageBox::Show(...)      
#pragma pop_macro("MessageBox")      
MessageBox("...",...);

0
 
LVL 48

Expert Comment

by:AlexFM
Comment Utility
I think last lines should be:

#pragma push_macro("MessageBox")
MessageBox::Show(...) ;                       // using managed message box

#pragma pop_macro("MessageBox")    
MessageBox("...",...);                            // using unmanaged message box
0
 

Author Comment

by:dcornish
Comment Utility
AlexFM

Thanks very much.  

djc
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
This video discusses moving either the default database or any database to a new volume.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now