Using Polarssl C libs in a gui

Rip Cord

Administrator
Staff member
Developer
this is a C# gui using sha1 library in C from polarssl

how to create the C dll is posted in the C forum here:
https://techbliss.org/posts/3685/

to import the dll into the C# project, include the function prototype to be imported in the code for the gui

C prototype in sha1dll.h:
Code:
//_declspec(dllexport) int sha1_file( const char *path, unsigned char output[20] );
becomes this in C# project:
Code:
[DllImport("sha1dll.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
unsafe public extern static int sha1_file(string path, byte[] output);

I put the prototype in frmSHA1.cs between:
Code:
public frmSHA1()
{
InitializeComponent();
}
and
Code:
private void btnSha1_Click(object sender, EventArgs e)
{
...
in the gui project properties check the box to allow unsafe code
also the dll must be put in the same directory with the gui .exe
SHA1-GUI.zip contains the visual studio project.
 

Attachments

  • SHA1-GUI.zip
    108.5 KB · Views: 0
Last edited:

Rip Cord

Administrator
Staff member
Developer
CharSet = CharSet.None is deprecated and is the same as CharSet.Ansi
either should be ok if the character set in the C dll project setting character set is set to "Not Set"
 

Rip Cord

Administrator
Staff member
Developer
this gui uses md5, sha1, and sha256 libs in one dll

the simple gui calculates the md5, sha1, and/or sha256 of a file.

note: dll and gui must be targeted to the same platform or it will yield a runtime error when the dll is invoked
if instead the .NET gui is targeted to "any PC", it will be loaded into 32 bit address space on 32 bit platform and 64 bit address space on 64 bit platform giving that runtime error if dll is targeted to the other.
 

Attachments

  • Checksum.zip
    82.9 KB · Views: 0
  • hashlibdll.zip
    1.1 MB · Views: 0
Top