Re: calling from c# into a dll

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Al the programmer (Altheprogrammer_at_discussions.microsoft.com)
Date: 03/18/05


Date: Fri, 18 Mar 2005 06:19:11 -0800

Thanks for the info. I remember the mangling issue from when I had to call C
code from C++, but the C# docs are silent on the issue.

What do I do when I want to export a C++ class in a dll to a C# program?

Al

"Willy Denoyette [MVP]" wrote:

> Make sure the exported C function is not mangled (has C linkage), make also
> sure the calling convention is cdecl (CallingConvention.Cdecl)]).
>
> Willy.
>
> "Al the programmer" <Altheprogrammer@discussions.microsoft.com> wrote in
> message news:1466DA50-01F4-4B7A-9324-C81AD4A5417D@microsoft.com...
> >I have a dll that consists of unmanaged C++ routines. I can call a
> >function
> > in the dll from a C++ executable, but not from a C# executable. I am
> > calling
> > an independent function, not a class. C# gives me a runtime exception
> > saying
> > the entry point to the dll cannot be found.
> >
> > I declare the function in C# with the following lines:
> > [DllImport("simpleDLL.dll", CallingConvention=CallingConvention.Cdecl)]
> > public static extern int fnsimpleDLL(int i);
> >
> > I then call the function with the line:
> > fnsimpleDLL(1);
> >
> > Any ideas?
>
>
>



Relevant Pages

  • Re: ffidl and pascal calling convention
    ... >TCL fails to find the DLL procedures when I try to use a DLL that used the ... >pascal calling convention. ... Windows DLLs via ffidl. ...
    (comp.lang.tcl)
  • Re: Marshal callback containing unsigned char * in signature
    ... It is possible to change the calling convention for a callback to __cdecl, ... This is a third party dll that I'm ...
    (microsoft.public.dotnet.framework.interop)
  • Re: Linking to DLL - update
    ... This error is usually caused by a mismatch in calling convention. ... I am now successfully calling the function in the DLL - the ... jumps to the subroutine and pushes the return address on the stack. ... case the callee does that. ...
    (microsoft.public.win32.programmer.tools)
  • Re: procedure doesnt works if the program compiled to native code...
    ... Even with an incompatible calling convention the function in the DLL is ... Incomaptibility of the calling convention is something that matters only ... since VB maybe corrects the stack pointer after it has detected the ...
    (microsoft.public.vb.winapi)
  • Re: Calling unmanaged C++ from C#
    ... Have you checked the calling convention setting in the VS2003 dll project. ... >> string strXMLFile, ...
    (microsoft.public.dotnet.framework.interop)