tags:

views:

177

answers:

1

Am interoping a c++ dll and am attempting to access it's functions. Below is the dumpbin /exports output from the dll:

Dump of file C:\C#Processes\SummarizerApp\SummarizerApp\lib\summarizer37.dll
File Type: DLL
Section contains the following exports for summarizer37.dll

00000000 characteristics
458962FF time date stamp Wed Dec 20 11:21:19 2006
    0.00 version
       1 ordinal base
       4 number of functions
       4 number of names

ordinal hint RVA      name

      1    0 00002960 ?delete_summarization@inxight@@YAXPAVsummarization_interface@1@@Z
      2    1 00016240 ?delete_summarizer@inxight@@YAXPAVsummarizer_interface@1@@Z
      3    2 000105E0 ?make_summarization@inxight@@YAPAVsummarization_interface@1@AAVsummarizer_interface@1@AAVbyte_stream_interface@1@ABVsummarization_input_options@1@ABVsummarization_sentence_output@1@ABVsummarization_phrase_output@1@PBDI5@Z
      4    3 0001BC40 ?make_summarizer@inxight@@YAPAVsummarizer_interface@1@PBD00@Z

Summary

    4000 .data
    B000 .rdata
    4000 .reloc
   2E000 .text

Take note of ordinal #3. It includes several methods I need to call, specifically:
make_summarization
summarization_input_options
summarization_sentence_output
summarization_phrase_output

Have done a JNI wrap of this dll and know that the functions above (which are all class contructors) are available from "extern C" which JNI uses, in unmangled form. Can I use the calling convention property of dllimport to access them undecorated?

In the C++ world what does it mean when multiple functions are exported under the same ordinal and what is the method of accessing them? Thanks, Jim

A: 

The EntryPoint field of the DllImport attribute can be used to import functions by ordinal (prefix the ordinal with a #).
It can also be used to import functions by their mangled name.
If you really have pure "extern C" wrappers for all of the functionality exposed by the C++ library, that makes this easy.
If you do not, you can construct C++/CLI wrappers to bridge between managed and unmanaged.

undname.exe in the vc\bin folder can be used to demangle compiled C++ names:

class inxight::summarization_interface * __cdecl inxight::make_summarization(
   class inxight::summarizer_interface &,
   class inxight::byte_stream_interface &,
   class inxight::summarization_input_options const &,
   class inxight::summarization_sentence_output const &, 
   class inxight::summarization_phrase_output const &,
   char const *, unsigned int , char const *)
andras
OK, I see that the whole mess at ordinal 3 is the last function I call for this functionality and that what I thought were other functions are the parameters, which are all class objects. The first parameter I can construct (and have done so) because it's constructor is exported as ordinal 4 (it works fine using ordinal or mangled name). How do I get at the other constructors? They are available in C. Am I stuck?How does JNI make them visible? Is it how the dll is loaded?
Jim Jones
@Jim: probably the cleanest way to do this is to create a C++/CLI library to wrap the native functionality. This is - kind of - similar to what you have to do with JNI (in that you can work in native (unmanaged) code and expose objects/functions to the managed world.)
andras
Any good references as to how this is done?
Jim Jones
@Jim: Hmmm. I was just searching. Found a few, but this one seems to be the most useful (subjectively): http://www.sharpoblunto.com/News/2007/09/16/the-trip-to-c2b2bcli-with-unexpected-results
andras
OK thanks much for your time.
Jim Jones
@Jim: Another, in case you do not have the necessary import headers for the library. It gets tedious and IMHO fragile, though: http://entribute.com/usingcppdll.htm
andras
Thanks, will read in case I get in that situation. Now however, I do have headers, documentation, full binary SDK.Jim
Jim Jones
@Jim: If you ever need to make it portable (i.e. to run on Mono), you are better off creating a C wrapper and consuming that through P/Invoke. (Mono is not working and will probably not work even in the distant future with C++/CLI.)
andras