Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

Posted on 2003-11-23
3
492 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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

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…
In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

766 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