Re: PInvoke a legacy class?

From: Tim Johnson (tjohnson_at_high-point.com)
Date: 08/18/04


Date: Wed, 18 Aug 2004 13:54:45 -0700

Thanks for the info. But how do I come up with the right full mangled name
from a dumpbin output? For example the "void Disconnect();" method of my
CStack class is reported as:

         18 11 000052BC ?Disconnect@CStack@@QAAXXZ

Which parts actually constitute the mangled name DllImport is looking for?

-- 
Tim Johnson
High Point Software
www.high-point.com
(503) 312-8625
"Peter Foot [MVP]" <feedback@nospam-inthehand.com> wrote in message
news:eDyMy9VhEHA.556@tk2msftngp13.phx.gbl...
> You can P/Invoke to C++ functions with decorated names only if they are
> static functions, if they are instance members you can't, because
> instantiating a C++ class from managed code is not possible.
>
> If the functions are static, your only hurdle is to include the EntryPoint
> property of the DllImport attribute to the full mangled name of the method
/
> or the numeric ordinal - you can use dumpbin or depends to find out this
> information.
>
> You could write a native C++ dll which would expose a single method which
> created the class, called the method and then called the destructor, you
can
> then P/Invoke this from managed code.
>
> Peter
>
> -- 
> Peter Foot
> Windows Embedded MVP
> www.inthehand.com | www.opennetcf.org
>
> Do have an opinion on the effectiveness of Microsoft Windows Mobile and
> Embedded newsgroups?  Let us know!
> https://www.windowsembeddedeval.com/community/newsgroups
>
> "Tim Johnson" <tjohnson@high-point.com> wrote in message
> news:eyG%23x2VhEHA.1392@TK2MSFTNGP11.phx.gbl...
> > I've read up on how to use P/Invoke to work with unmanaged legacy dlls
> > with
> > a flat API.  But how do you do that for a legacy dll that is built as a
> > set
> > of classes?  If I do a dumpbin of the dll I get decorated names which
> > include the class name as well as the method name.  But I can't
determine
> > from that the right syntax for the DllImport expression in my C#
program.
> >
> > For example, for a dll that exports a class XXX with a constructor,
> > destructor, and 1 method named Foo a normal C++ program could call
things
> > like this:
> >
> > XXX:XXX();
> > XXX:~XXX();
> > int XXX:Foo(int i);
> >
> > But how/what to invoke from C# with P/Invoke - what's the right
signature
> > for the DllImport attribute?
> > -- 
> > Tim Johnson
> > High Point Software
> > www.high-point.com
> > (503) 312-8625
> >
> >
>
>


Relevant Pages

  • Re: PInvoke a legacy class?
    ... PInvoke as WINAPI and the you will still need a C++ wrapper to ... >> Which parts actually constitute the mangled name DllImport is looking ... >>> or the numeric ordinal - you can use dumpbin or depends to find out this ... But how do you do that for a legacy dll that is built as ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: Pocket PC 2005 C++ Managed Class Library
    ... Thanks for replying. ... using P/Invoke but I didn't know how to use DllImport for class methods ... You can use native DLL in C# via P/Invoke or COM interop. ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: DLL Injection
    ... You can write a C dll which injects ... use native functions from your C dll. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: PInvoke a legacy class?
    ... >> property of the DllImport attribute to the full mangled name of the ... >> or the numeric ordinal - you can use dumpbin or depends to find out this ... >> then P/Invoke this from managed code. ... But how do you do that for a legacy dll that is built as ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: GetprocAddress() error
    ... >> You will be enlightened to the problem when you use dumpbin /exports ... >> Michael Salamone ... >>> The dll was created by WCE DLL Wizard, ... >>>> verify the exports in your DLL, ...
    (microsoft.public.windowsce.embedded.vc)

Quantcast