473,396 Members | 1,799 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

managed type or function cannot be used in an unmanaged function

I am switching from VS2003 .NET to VS2005 and I receive the following
errorwhen compiling my project:

error C3821: 'File': managed type or function cannot be used in an unmanaged
function c:\...\DataBase.cpp

I looked at the knowledgebase:
http://msdn2.microsoft.com/en-us/library/4756a450.aspx and tried to fix the
problem from there but with little success.

Can anyone make a suggestion how to overcom this problem?

File: Database.cpp

int CSendDoc::DbOpenIMDOFile (String * File)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState())
int nDotPos;
CString sTextFileName;
CString sIMDOFileName;
char * st,st2[100];
int l,x;
int DbCt;
CFileStatus status;
CFile * pScript;

CString FileName;

---> FileName = File;
// open the script file specified by the user
if (!CFile::GetStatus(FileName, status))
{
return 0;
}

try
{
pScript = new CFile(FileName,CFile::modeRead | CFile::shareDenyWrite);
}
catch( CFileException* e )
{
CString sError = "IMDO to text file input file: " + sIMDOFileName;
GetErrorText (sError, e->m_lOsError);
e->Delete();
//return SCRIPT_FILE_OPEN_FAILED;
}

CArchive ar(pScript,CArchive::load);
// read in the script file contents
ASSERT( DatabaseIMDOList.IsSerializable() );

DatabaseIMDOList.Serialize(ar);

ar.Close();
delete pScript;

if(!DatabaseIMDOList.IsEmpty())
{
DbCt = DatabaseIMDOList.GetCount();
DbPos = DatabaseIMDOList.GetHeadPosition();
}
else
DbCt = 0;
return DbCt;
}
Dec 5 '05 #1
4 5856
This could be beacuse File is a class in the .Net framework, part of the
System::IO namespace. I'd suggest you rename the variable and see if that
helps.

Colin

"RedJoy" wrote:
I am switching from VS2003 .NET to VS2005 and I receive the following
errorwhen compiling my project:

error C3821: 'File': managed type or function cannot be used in an unmanaged
function c:\...\DataBase.cpp

I looked at the knowledgebase:
http://msdn2.microsoft.com/en-us/library/4756a450.aspx and tried to fix the
problem from there but with little success.

Can anyone make a suggestion how to overcom this problem?

File: Database.cpp

int CSendDoc::DbOpenIMDOFile (String * File)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState())
int nDotPos;
CString sTextFileName;
CString sIMDOFileName;
char * st,st2[100];
int l,x;
int DbCt;
CFileStatus status;
CFile * pScript;

CString FileName;

---> FileName = File;
// open the script file specified by the user
if (!CFile::GetStatus(FileName, status))
{
return 0;
}

try
{
pScript = new CFile(FileName,CFile::modeRead | CFile::shareDenyWrite);
}
catch( CFileException* e )
{
CString sError = "IMDO to text file input file: " + sIMDOFileName;
GetErrorText (sError, e->m_lOsError);
e->Delete();
//return SCRIPT_FILE_OPEN_FAILED;
}

CArchive ar(pScript,CArchive::load);
// read in the script file contents
ASSERT( DatabaseIMDOList.IsSerializable() );

DatabaseIMDOList.Serialize(ar);

ar.Close();
delete pScript;

if(!DatabaseIMDOList.IsEmpty())
{
DbCt = DatabaseIMDOList.GetCount();
DbPos = DatabaseIMDOList.GetHeadPosition();
}
else
DbCt = 0;
return DbCt;
}

Dec 6 '05 #2
"RedJoy" <Re****@discussions.microsoft.com> wrote
I am switching from VS2003 .NET to VS2005 and I receive the following
errorwhen compiling my project:

error C3821: 'File': managed type or function cannot be used in an
unmanaged
function c:\...\DataBase.cpp

As I understand, you get this diagnostic when you use managed
functionality in the function's body. In that case, MSIL must be
emitted for the function. For some reason, however, managed
code is not an option for the function.

The String^ to CString conversion requires managed code
in your case.

That could be due to:
#pragma unmanaged or
inline assembler or
?

I don't see the later in your code. Can you try to add a
#pragma managed
above the function?

I don't see though, why this should be different in VC 7.1.

-hg
Dec 6 '05 #3
Thank you Colin. I have tried that before and it did not solve my problem.

"Colin Desmond" wrote:
This could be beacuse File is a class in the .Net framework, part of the
System::IO namespace. I'd suggest you rename the variable and see if that
helps.

Colin

"RedJoy" wrote:
I am switching from VS2003 .NET to VS2005 and I receive the following
errorwhen compiling my project:

error C3821: 'File': managed type or function cannot be used in an unmanaged
function c:\...\DataBase.cpp

I looked at the knowledgebase:
http://msdn2.microsoft.com/en-us/library/4756a450.aspx and tried to fix the
problem from there but with little success.

Can anyone make a suggestion how to overcom this problem?

File: Database.cpp

int CSendDoc::DbOpenIMDOFile (String * File)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState())
int nDotPos;
CString sTextFileName;
CString sIMDOFileName;
char * st,st2[100];
int l,x;
int DbCt;
CFileStatus status;
CFile * pScript;

CString FileName;

---> FileName = File;
// open the script file specified by the user
if (!CFile::GetStatus(FileName, status))
{
return 0;
}

try
{
pScript = new CFile(FileName,CFile::modeRead | CFile::shareDenyWrite);
}
catch( CFileException* e )
{
CString sError = "IMDO to text file input file: " + sIMDOFileName;
GetErrorText (sError, e->m_lOsError);
e->Delete();
//return SCRIPT_FILE_OPEN_FAILED;
}

CArchive ar(pScript,CArchive::load);
// read in the script file contents
ASSERT( DatabaseIMDOList.IsSerializable() );

DatabaseIMDOList.Serialize(ar);

ar.Close();
delete pScript;

if(!DatabaseIMDOList.IsEmpty())
{
DbCt = DatabaseIMDOList.GetCount();
DbPos = DatabaseIMDOList.GetHeadPosition();
}
else
DbCt = 0;
return DbCt;
}

Dec 6 '05 #4
Holger,

I tried the '#pragma managed' above the function but ended up putting it at
the beginning of my *.h file instead and it compiled without any warnings or
errors.
Danke,
Michael
Dec 6 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Jón Sveinsson | last post by:
Hello everyone I have been trying to read and write struct to binary files, I'm using to functions to convert the struct to bytes and bytes to struct, I always receive the following error ...
7
by: Z-Mechanic | last post by:
Hello everybody! I have a question. Anybody knows why managed function calls faster in MC++ rather than unmanaged function (defined with #pragma umanaged)? The differences is about 4 times...
1
by: Ghost | last post by:
Hi all, I wrote a program in C# and now I have to "translate" it i visual C++ (MFC) using .NET, but I had a little problem: *ERRORS* error C3181: 'CTestDlg' : invalid operand for __typeof,...
1
by: slugster | last post by:
Hi, i originally posted this via another portal, but after giving it time to propagate it still hasn't shown up. My apologies for the multiposting. This might be a very simple question, but i...
3
by: Ben Voigt | last post by:
This smells like a bug to me, since literals are substituted at compile time. I'm using VS2005 SP1 beta. // literal_unmanaged.cpp : main project file. ref class TheClass { literal int...
2
by: andy6 via DotNetMonster.com | last post by:
I took a c++ 6.0 project and converted it to c++ .net 2005 project. I want to make a web service out of it. One of the new files I created was a cpp where I have the webmethod pointing to a...
0
by: MarukoS | last post by:
I am converting a MFC solution from VS2003 to VS2005. And I got the following error: error C3821: 'System::Xml::XmlDocument *': managed type or function cannot be used in an unmanaged function I...
4
by: Andrus | last post by:
I tried to use type parameter to call static method but got compile error 'T' is a 'type parameter', which is not valid in the given context. Why this is not allowed ? Should I really use a lot...
0
by: querry | last post by:
Hi all, I have someting like this... xyz.h #using <mscorlib.dll> #include <vcclr.h> using namespace std;
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.