Groups | Blog | Home
all groups > dotnet clr > may 2004 >

dotnet clr : how to call an unmanaged __fastcall function from CLR in C/Winforms ?


andrea catto'
5/5/2004 10:06:10 AM
I 'managed' to be able to call a regular unmagaged function from within a
clr bases winforms, but....
I can not call functions that are compiled as __fastcall....

there has to be a way, otherwise how would be possible for the world to
migrate or use old static libraries ???

andrea catto'
5/6/2004 9:18:32 AM
sorry I forgot to be specific, I only use VC++.
I am beginning to love the win forms, so I'd like to start using it and yet
my static libraries written in C are all __fastcall.
how about this now ? any help ?

[quoted text, click to view]

Brian Tyler
5/6/2004 10:12:26 AM
Depends on the language you are using, but the DllImportAttribute has a
property called CallingConvention. So in C#, it would look something like

[DllImport("myoldcode.dll", CallingConvention=CallingConvention.FastCall)]
void foo();

Getting calls to native methods correct can be difficult as some of the
rules are subtle. I recommend getting a copy of Adam Nathan's book (.NET and
COM) and checking out the PInvoke website (http://pinvoke.net/).

Brian

[quoted text, click to view]

Brian Tyler
5/6/2004 3:17:59 PM
I don't do alot of managed C++, but the example is in MSDN...

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemRuntimeInteropServicesDllImportAttributeClassTopic.asp


[quoted text, click to view]

cody
5/7/2004 1:32:03 PM
[quoted text, click to view]

You have to create an unmanaged wrapper dll then.

--
cody

Freeware Tools, Games and Humour
http://www.deutronium.de.vu || http://www.deutronium.tk

Brian Tyler
5/10/2004 3:22:20 PM
Ouch, just realized I missed an important word: "static". Cody is right, a
static library is just a blob of assembly waiting to be made into something
that can be executed (DLL or EXE). The easiest thing to do would be either

1) Do what cody said
2) Rebuild the library but specify a DLL rather than LIB build, and expose
the calls you want access to.

[quoted text, click to view]

AddThis Social Bookmark Button