writing char* data from unmanaged dll to managed string

P

paul f

How do I write value of (unmanaged) OutputData char* into a string
(managed) with c#.
I am getting error:
Attempted to read or write protected memory. This is often an
indication that other memory is corrupt.

Do I need to enabling marchalling?
 
C

Cor Ligthert[MVP]

Paul,

At least you need some code, did you write that?

And then show it here.

Cor
 
P

paul f

How do I write value of (unmanaged) OutputData char* into a string
(managed) with c#.
I am getting error:
Attempted to read or write protected memory. This is often an
indication that other memory is corrupt.

Do I need to enabling marchalling?

here is my code:
[DllImport("C:\\EnDecryption.dll",EntryPoint ="Decrypto")]
[MarshalAs(UnmanagedType.ByValArray,SizeConst=25)]

static extern int function(System.String inputdata1,
System.String OutputData , System.UInt32 iLenData, System.String
inputdata2, System.UInt32 iLen);

public Form1()
{
System.String inputdata2 = "xxcddfdfggf
System.String inputdata1= "gfdgdfgdfgfd";
System.String OutputData ="";
uint Length = 25;
uint SeedLength = 32;
int ret;
ret = 99;
ret = function
(EncryptedData,output ,Length,Seed,SeedLength);
InitializeComponent();

}
 
P

paul f

How do I write value of (unmanaged) OutputData char* into a string
(managed) with c#.
I am getting error:
Attempted to read or write protected memory. This is often an
indication that other memory is corrupt.
Do I need to enabling marchalling?

here is my code:
[DllImport("C:\\EnDecryption.dll",EntryPoint ="Decrypto")]
        [MarshalAs(UnmanagedType.ByValArray,SizeConst=25)]

        static extern int function(System.String inputdata1,
System.String OutputData , System.UInt32 iLenData, System.String
inputdata2, System.UInt32 iLen);

        public Form1()
        {
            System.String inputdata2 = "xxcddfdfggf
            System.String inputdata1= "gfdgdfgdfgfd";
            System.String OutputData ="";
            uint Length = 25;
            uint SeedLength = 32;
            int ret;
            ret = 99;
            ret = function
(EncryptedData,output ,Length,Seed,SeedLength);
            InitializeComponent();

        }


sorry wrong code, here is correct code:

public partial class Form1 : Form
{
[DllImport("C:\\paul.dll",EntryPoint ="function")]

static extern int function(String input1data, ref String
OutputData, System.UInt32 iLenData, String input2data,System.UInt32
iLen);

public Form1()
{
System.String input1data= "xxxyydfdfd@+!";
System.String input2data= "dfdsfs45¬";
System.String output ="";
uint Length = 25;
uint SeedLength = 32;
int ret;
ret = function
(input1data,output ,Length,input2data,SeedLength);
InitializeComponent();

}

private void Form1_Load(object sender, EventArgs e)
{


}
}
 
P

Pavel Minaev

public partial class Form1 : Form
    {
        [DllImport("C:\\paul.dll",EntryPoint ="function")]

        static extern int function(String input1data, ref String
OutputData, System.UInt32 iLenData, String input2data,System.UInt32
iLen);

        public Form1()
        {
            System.String input1data= "xxxyydfdfd@+!";
            System.String input2data= "dfdsfs45¬";
            System.String output ="";
            uint Length = 25;
            uint SeedLength = 32;
            int ret;
            ret = function
(input1data,output ,Length,input2data,SeedLength);
            InitializeComponent();

        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
    }

Good; now, can you show the source of "function" as well? I have
strong suspicions, particularly with your mention of "char*" in C++
and the sight of "ref String" in method signature, but seeing the code
on the other side would make everything clear.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top