Home All Groups Group Topic Archive Search About

Export function problem (unmanged to managed)

Author
5 Oct 2006 9:31 AM
Yoavo
Hi,
I am trying to call an Unmanaged code (MFC C++) from Managed code (c#)
I have declared in the unmanaged code the function:
extern "C"
{
_declspec(dllexport) int get_DocName();
}

In the c# code I write:
[DllImport("C:\\MyProj.dll", EntryPoint="get_DocName",
ExactSpelling=false,CallingConvention=CallingConvention.Cdecl)]
static extern int get_DocName();

When I try to compile the c# code, I get the error:
C:\C#Test\Form1.cs(21,78): error CS1518: Expected class, delegate, enum,
interface, or struct
C:\C#Test\Form1.cs(21,63): error CS0106: The modifier 'extern' is not valid
for this item

Can someone please explain ?

Yoav.

Author
5 Oct 2006 9:12 PM
Mattias Sjögren
>In the c# code I write:
>[DllImport("C:\\MyProj.dll", EntryPoint="get_DocName",
>ExactSpelling=false,CallingConvention=CallingConvention.Cdecl)]
>static extern int get_DocName();
>
>When I try to compile the c# code, I get the error:
>C:\C#Test\Form1.cs(21,78): error CS1518: Expected class, delegate, enum,
>interface, or struct
>C:\C#Test\Form1.cs(21,63): error CS0106: The modifier 'extern' is not valid
>for this item
>
>Can someone please explain ?


Like any other method declaration, it must be placed inside a class
(or struct). C# doesn't support global methods.


Mattias

--
Mattias Sjögren [C# MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

AddThis Social Bookmark Button