[Mono-list] Problems Using P/Invoke

Jeremy Tan jun_m_tan at yahoo.com.sg
Thu Nov 10 10:51:11 EST 2005


Hello All,

I am trying to write some C# bindings for the C++ libdar library
(http://dar.sourceforge.net) as a personal project which which will be
released as open source at a later time when I can get something
working. The problem I am having now is that I can't seem to find a way
to bind this library into C# APIs due to the way the functions are
declared. I've tried searching the internet but I can't seem to find any
information on this. I'm stuck at the first function that I'm trying to
import and I can't go any further from this point as almost all the
functions in the library are declared this way:

extern void get_compile_time_features(bool & ea, 
	bool & largefile, 
	bool & nodump, 
	bool & special_alloc, 
	U_I & bits, 
	bool & thread_safe,
        bool & libz, 
	bool & libbz2, 
	bool & libcrypto);

The problem I have here is the way the parameters are defined. Note that
the U_I type is just a typedef to unsigned int in libdar. In my source
file, i declared it like this because I can't seem to find a way to
specify "&" in the method signature:

[DllImport(library, CallingConvention = CallingConvention.Cdecl)]
            private unsafe extern static void get_compile_time_features(
                    ref bool EAttributes,
                    ref bool LFile,
                    ref bool NDunp,
                    ref bool SAllocation,
                    ref uint bits,
                    ref bool TSafe,
                    ref bool LZ,
                    ref bool LBZ2,
                    ref bool LCrypto);

and I called the function like this:

get_compile_time_features(
                    ref ExtendedAttributes,
                    ref LargeFile,
                    ref NoDump,
                    ref SpecialAllocation,
                    ref Bits,
                    ref ThreadSafe,
                    ref LibZ,
                    ref LibBZ2,
                    ref LibCrypto);

This compiles fine with mcs but when i try to run it, I get this error:

Unhandled Exception: System.EntryPointNotFoundException:
get_compile_time_features
in (wrapper managed-to-native) LibDar.LibDar:get_compile_time_features
(bool&,bool&,bool&,bool&,uint&,bool&,bool&,bool&,bool&)
in <0x00054> LibDar.LibDar:GetCompileTimeFeatures ()
in <0x00026> LibDar.Tester:Main (System.String[] args)

I've been stuck here for a few days and I've done a lot of reading on
P/Invoke but to no avail. Can you point me to the right direction on how
this can be done?

Cheers,
Jeremy Tan




More information about the Mono-list mailing list