Solved

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

Posted on 2003-11-23
3
488 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
ID: 9808458
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
ID: 9808650
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
ID: 9810020
AlexFM

Thanks very much.  

djc
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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.   …
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

895 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

15 Experts available now in Live!

Get 1:1 Help Now