Search:
Namespaces
Discussions
.NET v1.1
Feedback
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
Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us
-
Terms of Use
-
Privacy Policy
-
www.dotnet247.com