私はC ++が初めてです。
C++ プロジェクトで呼び出したい C# dll があります。
C# の関数は、次のように宣言します。
public int ShowStringReturn(out string str)
{
str = "Message from c#";
return 0;
}
次に、C++ プロジェクトで呼び出します。
__declspec(dllexport)
int ShowStringCSharpReturn (std::string &strOut)
{
try
{
String^ str;
IngWrapper::Ingressus_Instance->xIMUobject->ShowStringReturn(str);
using System::Runtime::InteropServices::Marshal;
const char* chars = (const char*)(Marshal::StringToHGlobalAnsi(str)).ToPointer( );
strOut = chars;
return 0;
}
catch (Exception^ ex)
{
MessageBox::Show(ex->Message,"Error",MessageBoxButtons::OK,MessageBoxIcon::Error);
return -1;
}
}
コンパイルできますが、Windows フォーム アプリケーションで ActiveX DLL を呼び出すと、「外部コンポーネントが例外をスローしました」というエラーが表示されます。関数を宣言して呼び出すにはどうすればよいですか?