G
Guest
I have a managed C++ DLL that contains the following:
MyLib.h:
// MyLib.h
#pragma once
using namespace System;
using namespace System::Runtime::InteropServices;
namespace MyLib
{
public __gc class MyClass
{
public:
Boolean MyMethod([Out] String *cParam);
};
}
MyLib.cpp
// This is the main DLL file.
#include "stdafx.h"
#include "MyLib.h"
namespace MyLib
{
Boolean MyClass::MyMethod([Out] String *cParam)
{
cParam = S"My String!";
return true;
}
}
I've added the resulting DLL as a reference to my C# console app and I can't
get the C# app to compile.
MyApp.cs:
using System;
using MyLib;
namespace MyApp
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
MyClass o = new MyClass();
string oStr;
o.MyMethod(out oStr);
Console.WriteLine(oStr);
}
}
}
I’m getting the following errors when compiling MyApp.cs:
--> D:\DlgProc\MyApp\Class1.cs(20): The best overloaded method match for
'MyLib.MyClass.MyMethod(string)' has some invalid arguments
--> D:\DlgProc\MyApp\Class1.cs(20): Argument '1': cannot convert from 'out
string' to 'string'
What am I doing wrong?
thanks
MyLib.h:
// MyLib.h
#pragma once
using namespace System;
using namespace System::Runtime::InteropServices;
namespace MyLib
{
public __gc class MyClass
{
public:
Boolean MyMethod([Out] String *cParam);
};
}
MyLib.cpp
// This is the main DLL file.
#include "stdafx.h"
#include "MyLib.h"
namespace MyLib
{
Boolean MyClass::MyMethod([Out] String *cParam)
{
cParam = S"My String!";
return true;
}
}
I've added the resulting DLL as a reference to my C# console app and I can't
get the C# app to compile.
MyApp.cs:
using System;
using MyLib;
namespace MyApp
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
MyClass o = new MyClass();
string oStr;
o.MyMethod(out oStr);
Console.WriteLine(oStr);
}
}
}
I’m getting the following errors when compiling MyApp.cs:
--> D:\DlgProc\MyApp\Class1.cs(20): The best overloaded method match for
'MyLib.MyClass.MyMethod(string)' has some invalid arguments
--> D:\DlgProc\MyApp\Class1.cs(20): Argument '1': cannot convert from 'out
string' to 'string'
What am I doing wrong?
thanks