[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

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

Posted on 2003-11-23
3
Medium Priority
?
511 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
[X]
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
  • 2
3 Comments
 
LVL 48

Accepted Solution

by:
AlexFM earned 2000 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

650 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