Unmanaged DLL

A

Ady

Hi

I am trying to call a function in C# that I wrote in unmanaged C++.

I am getting the following error.

An unhandled exception of type 'System.EntryPointNotFoundException' occurred
in TestApp2.exe

Additional information: Unable to find an entry point named DllMain in DLL
levelreader.DLL.

My C++ looks like this

#include "stdafx.h"
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return TRUE;
}

bool fileLoaded = false;
FILE * levelHandle;
extern "C" {
bool LevelOpen(char*fileName);
};
bool LevelOpen(char * fileName)
{
return FALSE;
}

and my c# looks like this

namespace TestApp2
{
public class Level
{
bool levelOpen;
[DllImport("levelreader.DLL",EntryPoint="DllMain")]
private static extern bool LevelOpen(string fileName);
public Level()
{
levelOpen = false;
}

public bool Open(string fileName)
{
levelOpen = LevelOpen ( fileName );
return ( levelOpen );
}
}
}


Any reason for this exception?

Thanks

Ady.
 
W

Willy Denoyette [MVP]

Ady said:
Hi

I am trying to call a function in C# that I wrote in unmanaged C++.

I am getting the following error.

An unhandled exception of type 'System.EntryPointNotFoundException' occurred
in TestApp2.exe

Additional information: Unable to find an entry point named DllMain in DLL
levelreader.DLL.

Remove the Entrypoint from the DllImport declarations. Please read the doc's
<ms-help://MS.MSDNQTR.2003JUL.1033/cpguide/html/cpconentrypointobjectfield.htm> carefully, Entrypoint refers to the function name
entry not DllMain.

Willy.
 
A

Ady

Hi,

I do not have this document is it on the MSDN website as I cant find it

Thanks

Ady.

Willy Denoyette said:
Remove the Entrypoint from the DllImport declarations. Please read the doc's
<ms-help://MS.MSDNQTR.2003JUL.1033/cpguide/html/cpconentrypointobjectfield.h
tm> carefully, Entrypoint refers to the function name
 
A

Ady

I have done what it says there but am still getting the exception anybody
help?

Thanks

Ady.
 
M

Mattias Sjögren

I have done what it says there but am still getting the exception anybody
help?

Try running Dumpbin.exe /exports on the DLL to see under what name the
function is actually exported.



Mattias
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top