#include #include //#using "hellocs.dll" //#using "hellocs.netmodule" //#include //gcroot cls; using namespace System; using namespace System::Runtime::InteropServices; extern "C" { __declspec(dllexport) int loaddll(void); __declspec(dllexport) char * methodcli1( const char * string01, const char * string02, char * buff00); __declspec(dllexport) char * methodcli2( const char * string01, const char * string02, const char * string03, char * buff00); } ref class refcls { public: static hellocs::hellocscls^ cls; }; void loadcsdll(void) { refcls::cls = gcnew hellocs::hellocscls(); } int loaddll(void) { try { loadcsdll(); } catch (Exception^ e) { return -1; } return 0; } char * methodcli1( const char * string01, const char * string02, char * buff00) { unsigned int len = strlen(buff00); unsigned int n = MultiByteToWideChar(CP_ACP, 0, string01, -1, NULL, 0); char * param1 = (char *)calloc(1,n*2); if (param1 == NULL) { strcpy_s(buff00, len + 1, "calloc error"); return buff00; } MultiByteToWideChar(CP_ACP, 0, string01, -1, (LPWSTR)param1, n); n = MultiByteToWideChar(CP_ACP, 0, string02, -1, NULL, 0 ); char * param2 = (char *)calloc(1,n*2); if (param2 == NULL) { strcpy_s(buff00, len + 1, "calloc error"); free(param1); return buff00; } MultiByteToWideChar(CP_ACP, 0, string02, -1, (LPWSTR)param2, n); char * ret01 = (char *)Marshal::StringToHGlobalAnsi(refcls::cls->methodcs1( (LPWSTR)param1, (LPWSTR)param2)).ToPointer(); n = strlen(ret01); if (len>=n) { strcpy_s(buff00, len + 1, ret01); } else { strcpy_s(buff00, len+1, "バッファが足りません(methodcli1)"); } Marshal::FreeHGlobal((IntPtr)ret01); free(param1); free(param2); return buff00; } char * methodcli2( const char * string01, const char * string02, const char * string03, char * buff00) { array^ arr = gcnew array(3); arr[0] = gcnew String(string01); arr[1] = gcnew String(string02); arr[2] = gcnew String(string03); char * ret01 = (char *)Marshal::StringToHGlobalAnsi(refcls::cls->methodcs2( arr)).ToPointer(); unsigned int len = strlen(buff00); unsigned int n = strlen(ret01); if (len>=n) { strcpy_s(buff00, len + 1, ret01); } else { strcpy_s(buff00, len + 1, "バッファが足りません(methodcli2)"); } Marshal::FreeHGlobal((IntPtr)ret01); return buff00; }