?
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
?
506 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

How to Create Failover DNS Record Sets in Route 53

Route 53 has the ability to easily configure DNS record sets specifically for failover scenarios. These failover record sets can be configured to failover to full-blown deployments in other regions or to a static HTML page that informs your customers of the issue.

Question has a verified solution.

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

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
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…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

801 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