Calling methods in C++ dll from C# without any info, only header files -


i have third-party dll trying write wrapper in c# , have c++ sample code, works, when try calling methods in dll, error:

unable find entry point named 'scan' in dll 'scard-com.dll'.

please point out problem:

here part of .h file used in sample c++ app

interface iscard_cardreaderdevices : iunknown { virtual uint __stdcall scan(void) = 0; virtual uint __stdcall getdevicecount(void) = 0; virtual const char * __stdcall getdevicename(uint id) = 0; virtual const char * __stdcall getserialname(uint id) = 0; virtual iscard_cardreader * __stdcall connectbyid(uint id) = 0; virtual iscard_cardreader * __stdcall connectbyname(const char *name) = 0; virtual iscard_cardreader * __stdcall connectbyserial(const char *serial) = 0; virtual bool __stdcall disconnect(iscard_cardreader *reader) = 0; virtual iscard_secmsg * __stdcall attachsecmsg(iscard_cardreader *reader) = 0; virtual void __stdcall detachsecmsg(iscard_secmsg *secmsg) = 0; virtual iscard_script * __stdcall attachscript(iscard_cardreader *reader) = 0; virtual void __stdcall detachscript(iscard_script *script) = 0; virtual iscard_isocard * __stdcall attachisocardbyreader(iscard_cardreader *reader) = 0; virtual iscard_isocard * __stdcall attachisocardbysecmsg(iscard_secmsg *secmsg) = 0; virtual void __stdcall detachisocard(iscard_isocard *isocard) = 0; virtual iscard_mtcos * __stdcall attachmtcosbyreader(iscard_cardreader *reader) = 0; virtual iscard_mtcos * __stdcall attachmtcosbysecmsg(iscard_secmsg *secmsg) = 0; virtual void __stdcall detachmtcos(iscard_mtcos *os) = 0; virtual iscard_icaoconverter * __stdcall attachicaoconverter(void) = 0; virtual void __stdcall detachicaoconverter(iscard_icaoconverter *icaoconv) = 0; virtual iscard_imageconverter * __stdcall attachimageconverter(void) = 0; virtual void __stdcall detachimageconverter(iscard_imageconverter *imgconv) = 0; #ifdef multiapp_ext virtual iscard_idlconverter * __stdcall attachidlconverter(void) = 0; virtual void __stdcall detachidlconverter(iscard_idlconverter *idlconv) = 0; virtual iscard_sscdconverter * __stdcall attachsscdconverter(void) = 0; virtual void __stdcall detachsscdconverter(iscard_sscdconverter *sscdconv) = 0; virtual iscard_ehealthconverter * __stdcall attachehealthconverter(void) = 0; virtual void __stdcall detachehealthconverter(iscard_ehealthconverter *ehealthconv) = 0; #endif // multiapp_ext }; 

in c# project, have added class:

public class scardwrapper {     [dllimport("scard-com.dll", callingconvention = callingconvention.cdecl)]     public static extern uint scan();  // , call this:  public int listreaders()     {         try         {             uint numreaders = scan();             if (numreaders < 1)             {                 return 0;             }             (int = 0; < numreaders; i++)             {                 intptr idevice = getdevicename(uint.parse(i.tostring()));                 string sdevice = marshal.ptrtostringauto(idevice);                 debug.writeline(string.format("{0} : " + sdevice, i));             }             return int.parse(numreaders.tostring());         }         catch         {             return -1;         }     } } 

but hits scan() method, error above. appreciated!

p/invoke doesn't really support c++. you're trying call method on interface, not c-style function.

there hacks can results want, far best option writing c++/cli interop library can use c# project.

also, in general, header files aren't enough call native library. need documentation - there's noöne hold hand on issues "how big string buffer supposed be? responsible allocating/freeing memory? happens when buffer isn't large enough? possible error conditions?" if don't have documentation, there's little can enjoy reverse engineering :)


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -