Hey, ive had some problems building a correct .dll from a c++-project to my c#-project. I played around with the c++-project-properties and got a .dll file which i can add and refer to in my c# web-project. I use Dllimport to make a function call to the .dll like this:
[DllImport("Filename.dll", CallingConvention=CallingConvention.Cdecl)]
static extern void Function1(byte[] src,
UInt32 srcLen,
[MarshalAs(UnmanagedType.LPStr)] StringBuilder dst,
UInt32 dstLen);
The c++ function header is:
__declspec(dllimport) void Function1(unsigned char *src,
unsigned long srclen,
unsigned char *dst,
unsigned long dstlen);
Im calling Function1 in c# with this:
StringBuilder d = new StringBuilder(50);
byte[] src = System.Text.Encoding.ASCII.GetBytes(stringFromDBWithencrypteddata);
Function1(src, srcLength, d, (uint)50);
No exceptions or errors are occuring, though im not getting the output im expecting. The function is a decrypting method that takes an encrypted string(src) and returns the decrypted version of this (dst).
Is it the way ive generated the .dll file or is it the wrong way im calling the function? Im running out of ideas ive tried most combinations.
Thanks in advice!
Loading
VulpesPosted Apr 13, 2011, 6:25 AM
If you know C++/CLI, you could try creating a quick project to see if you can call it successfully from managed C++ code. If you can, then you could turn that project into a managed dll which you could then consume from C#.
Joakim BorjessonPosted Apr 13, 2011, 5:59 AM
VulpesPosted Apr 13, 2011, 5:54 AM
Joakim BorjessonPosted Apr 13, 2011, 5:25 AM
Could it be that the dll isnt built correctly from the c++ project? Any ideas?
VulpesPosted Apr 13, 2011, 5:19 AM