Unmanaged DLL

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ady

    Unmanaged DLL

    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.EntryPo intNotFoundExce ption' 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_c all,
    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("leve lreader.DLL",En tryPoint="DllMa in")]
    private static extern bool LevelOpen(strin g fileName);
    public Level()
    {
    levelOpen = false;
    }

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


    Any reason for this exception?

    Thanks

    Ady.


  • Willy Denoyette [MVP]

    #2
    Re: Unmanaged DLL



    "Ady" <adrian.hirst@t cm.co.uk> wrote in message news:%23u%2309V DfDHA.2328@TK2M SFTNGP09.phx.gb l...[color=blue]
    > 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.EntryPo intNotFoundExce ption' occurred
    > in TestApp2.exe
    >
    > Additional information: Unable to find an entry point named DllMain in DLL
    > levelreader.DLL .
    >[/color]

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

    Willy.


    Comment

    • Ady

      #3
      Re: Unmanaged DLL

      Hi,

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

      Thanks

      Ady.

      "Willy Denoyette [MVP]" <willy.denoyett e@pandora.be> wrote in message
      news:e43YvaDfDH A.1212@TK2MSFTN GP12.phx.gbl...[color=blue]
      >
      >
      > "Ady" <adrian.hirst@t cm.co.uk> wrote in message[/color]
      news:%23u%2309V DfDHA.2328@TK2M SFTNGP09.phx.gb l...[color=blue][color=green]
      > > 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.EntryPo intNotFoundExce ption'[/color][/color]
      occurred[color=blue][color=green]
      > > in TestApp2.exe
      > >
      > > Additional information: Unable to find an entry point named DllMain in[/color][/color]
      DLL[color=blue][color=green]
      > > levelreader.DLL .
      > >[/color]
      >
      > Remove the Entrypoint from the DllImport declarations. Please read the[/color]
      doc's[color=blue]
      >[/color]
      <ms-help://MS.MSDNQTR.2003 JUL.1033/cpguide/html/cpconentrypoint objectfield.h
      tm> carefully, Entrypoint refers to the function name[color=blue]
      > entry not DllMain.
      >
      > Willy.
      >
      >[/color]


      Comment

      • Willy Denoyette [MVP]

        #4
        Re: Unmanaged DLL

        Online MSDN library.




        Comment

        • Ady

          #5
          Re: Unmanaged DLL

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

          Thanks

          Ady.

          "Willy Denoyette [MVP]" <willy.denoyett e@pandora.be> wrote in message
          news:%239ev1WEf DHA.1212@TK2MSF TNGP12.phx.gbl. ..[color=blue]
          > Online MSDN library.
          >
          >[/color]
          http://msdn.microsoft.com/library/de...bjectfield.asp[color=blue]
          >
          >[/color]


          Comment

          • Mattias Sjögren

            #6
            Re: Unmanaged DLL

            [color=blue]
            >I have done what it says there but am still getting the exception anybody
            >help?[/color]

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



            Mattias

            --
            Mattias Sjögren [MVP] mattias @ mvps.org

            Please reply only to the newsgroup.

            Comment

            Working...