Click here to Skip to main content
15,894,107 members

Comments by maheshbisht (Top 14 by date)

maheshbisht 24-Sep-14 16:57pm View    
Hi Sergey Alexandrovich

can u help me on this.I have to use following function (In C language) from a dll-

int encrypt(unsigned char *key, unsigned char *dataToEncrypt,
unsigned int in_data_len, unsigned char *out_data,
unsigned int *out_data_len)

and i am using following c# code to access the function but its give me

error= "A call to PInvoke function 'ConsoleApplication1!ConsoleApplication1.abc::encrypt' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature."



Used C# code:

<pre lang="cs">using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
abc.crypto();
}
}

public static class abc
{
const string _dllLocation = @"E:\ConsoleApplication1\ConsoleApplication1\bin\Debug\ck.dll";
[DllImport(_dllLocation)]
public static extern int encrypt([In, Out] byte[] key, [In, Out] byte[] dataToEncrypt, uint in_data_len, [Out] byte[] out_data, ref uint out_data_len);


//int encrypt(unsigned char *key, unsigned char *dataToEncrypt, unsigned int in_data_len, unsigned char *out_data, unsigned int *out_data_len)

public static void crypto()
{
var key = new byte[Int16.MaxValue];
key = Encoding.ASCII.GetBytes("123456789012");

var dataToEncrypt = new byte[Int16.MaxValue];
dataToEncrypt = Encoding.ASCII.GetBytes("1232345456789012");

uint in_data_len = 64;

var out_data = new byte[Int16.MaxValue];
uint out_data_len = 0;

int i = encrypt(key, dataToEncrypt, in_data_len, out_data, ref out_data_len);
}
}


}</pre>
maheshbisht 24-Sep-14 13:55pm View    
Thanks
maheshbisht 20-Sep-14 15:33pm View    
sir i know that when there is any third party dll the we add have to register it with our system but want to know how?
maheshbisht 20-Sep-14 14:30pm View    
My project platform is Visual Studio 2012
maheshbisht 25-May-13 7:22am View    
no yara not from ajax control can we do it from asp.net and jquery ? welcome your suggestion on this.