passing wstring, string and reference to enum variable from C# to C++(unmanaged DLL) -
i have c++ dll in following functions exported.
double getdouble(std::wstring filename, std::string id, status &stcode); int getint(std::wstring filename, std::string id, status &stcode); float getfloat(std::wstring filename, std::string id, status &stcode); string getstring(std::wstring filename, std::string id, status &stcode); int* getintarray(std::wstring filename, std::string id, status &stcode); float* getfloatarray(std::wstring filename, std::string id, status &stcode); string* getstringarray(std::wstring filename, std::string id, status &stcode);
where status of enum type...
now want use dll in c#.net app... can tell me how delclare respected methods in c# , can make call methods.... in advance...
[dllimport("external.dll", setlasterror = true, callingconvention = callingconvention.cdecl)] public static extern mbstatus queue_accept( int reader, [marshalas(unmanagedtype.lpstr)] string status);
lookup parameters dllimport attribute. depending on dll might need adjusted!
side note: wrap external dll in interface , code layer decouple tests , load dependency injection. don't change naming conventions.
public interface iexternaldllinterop { mb_status queue_accept(int reader, string status); } public class ambinterop : iambinterop { public mbstatus queue_accept(int reader, string status) { return staticambinterop.mb_queue_accept(reader, message, status); } }
Comments
Post a Comment