cristi_alonso
May 23rd, 2008, 12:54 PM
i have created DLL in C which i am going to use in my C# code .
DLL file is TestLib.DLL
C# file is Test_Net.cs
-----------------TestLib.dll ------------------------------------
#include <stdio.h>
extern "C"
{
__declspec(dllexport) char* DisplayHelloFromDLL()
{
char* x="bach ke kaha jaoge";
return x;
}
}
-------------------End of file TestLib---------------------------------
-------------------------Test_Net.cs------------------------------------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Reflection;
namespace Test_Net
{
public partial class Form1 : Form
{
[DllImport("TestLib.dll")]
public static unsafe extern char* DisplayHelloFromDLL();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
unsafe
{
char* y = DisplayHelloFromDLL();
label2.Text = Convert.ToString(y);
}
}
}
}
-----------------------------EOF Test_Net-----------------------
While Debuging i am getting an error saying that cannot convert from char* to object .can anyone tell me how to solve this problem?please anyone can tell me how to convert char* to string or char* to char it will be very usefull .
Any help appreciated
Thanks in advance.
DLL file is TestLib.DLL
C# file is Test_Net.cs
-----------------TestLib.dll ------------------------------------
#include <stdio.h>
extern "C"
{
__declspec(dllexport) char* DisplayHelloFromDLL()
{
char* x="bach ke kaha jaoge";
return x;
}
}
-------------------End of file TestLib---------------------------------
-------------------------Test_Net.cs------------------------------------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Reflection;
namespace Test_Net
{
public partial class Form1 : Form
{
[DllImport("TestLib.dll")]
public static unsafe extern char* DisplayHelloFromDLL();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
unsafe
{
char* y = DisplayHelloFromDLL();
label2.Text = Convert.ToString(y);
}
}
}
}
-----------------------------EOF Test_Net-----------------------
While Debuging i am getting an error saying that cannot convert from char* to object .can anyone tell me how to solve this problem?please anyone can tell me how to convert char* to string or char* to char it will be very usefull .
Any help appreciated
Thanks in advance.