Want to Join Us ?

you'll be able to discuss, share and send private messages.

Using Polarssl C libs in a gui

Discussion in 'C#' started by Rip Cord, Dec 4, 2020.

Share This Page

  1. Rip Cord

    Administrator Staff Member Admin 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 (Text):

    //_declspec(dllexport) int sha1_file( const char *path, unsigned char output[20] );
     
    becomes this in C# project:
    Code (Text):

    [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 (Text):

    public frmSHA1()
    {
    InitializeComponent();
    }
     
    and
    Code (Text):

    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.
     

    Attached Files:

    Last edited: Dec 6, 2020
  2. Rip Cord

    Administrator Staff Member Admin 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"
     
  3. Rip Cord

    Administrator Staff Member Admin 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.
     

    Attached Files:

    storm shadow likes this.
Top