.NETGURU
DllImport in C++Express2005?
Messages   Related Types
This message was discovered on microsoft.public.dotnet.languages.vc.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.
Post a new message to this list...

BeanDog (VIP)
I've never used DllImport in C++ before. I'm attemping to import the Windows
FindWindow function into my Visual C++ Express project like so:

using namespace System::Runtime::InteropServices;

public class Win32
    {
        [DllImport("User32.dll")];
        public:
            extern static int FindWindow(String ^lpClassName,String ^lpWindowName);
    };

This produces numerous compile errors:
Form1.h(22) : error 3750:
'System::Runtime::InteropServices::DllImportAttribute': a custom attribute
may not be used in an anonymous attribute block unless it is scoped for
assembly or module
Form1.h(22) : error 3303:
'System::Runtime::InteropServices::DllImportAttribute': attribute can only be
used on 'methods'
Form1.h(24) : error C2159: more than one storage class specified
Form1.h(24) : error C2720: 'svchost::Win32::FindWindow' : 'extern'
storage-class specifier illegal on members

What am I missing?

~BenDilts( void );
Reply to this message...
 
    
Doug Harrison [MVP] (VIP)
BeanDog wrote:

[Original message clipped]

DllImport is an attribute and must be attached to the thing it modifies,
e.g.

[DllImport("User32.dll")]
static int FindWindow(String ^lpClassName, String ^lpWindowName);

See this MSDN topic for more:

Using the DllImport Attribute
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore/html/vcwlkSysimportAttributeTutorial.asp

Also, it's illegal to declare something both static and extern, and it's
illegal to use extern on class members. As a class member, your FindWindow
must be declared static.

--
Doug Harrison
Microsoft MVP - Visual C++
Reply to this message...
 
 
System.Runtime.InteropServices.DllImportAttribute




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification