Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6005329
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:22:56+00:00 2026-05-23T01:22:56+00:00

After taking some small courses and using WPF and C# a bit I’ve decided

  • 0

After taking some small courses and using WPF and C# a bit I’ve decided to rewrite an application I have been working on. I have most of the functions working perfectly in a C++ DLL i created and imported into my WPF application.

I’m having a bit of trouble with a few of them though. One’s where I had previously passed variables from other functions or used dialogues and messageboxes.

Here is an example of one of the C++ functions i need to put into the DLL. The function generates a MD5 hash code of a list of files in a listbox that were added there by using the OpenFileDialog.

array<Byte>^ Hash()
{
    array<Byte>^ Buffer = nullptr;
    int x = 0;
    for each(String^ Files in listBox2->Items)
    {
        try
        {
            IO::FileStream^ FileStream = gcnew IO::FileStream(Files, IO::FileMode::Open, IO::FileAccess::Read);

            IO::BinaryReader^ BinaryReader = gcnew IO::BinaryReader(FileStream);

            IO::FileInfo^ FileInfo = gcnew IO::FileInfo(Files);

            System::Int64 TotalBytes = FileInfo->Length;

            Buffer = BinaryReader->ReadBytes(safe_cast<System::Int32>(TotalBytes));

            FileStream->Close();
            delete FileStream;
            BinaryReader->Close();

            MD5^ md5 = gcnew MD5CryptoServiceProvider;

            array<Byte>^ Hash = md5->ComputeHash(Buffer);

            String^ FileHex = BitConverter::ToString(Hash);

            listBox3->Items->Add(FileHex);

            x = x + 1;
        }
        catch(Exception^ e)
        {
            MessageBox::Show(e->Message->ToString());
            listBox1->Items->RemoveAt(listBox1->SelectedIndex);
        }
    }
    return Buffer;
}

This code works perfectly in my C++ app that i made. So what i tried to do was take everything within the try statement and use that as the code for the method however my problem comes from the first line where obviously “Files” is a variable or at least i think it is where the issue is.

Is there a way i can still use this code as is and create a variable in C# and then pass it to this method?

I attempted to do so using the following code in my C# app

private void button2_Click(object sender, RoutedEventArgs e)
{
    DllTest.Funtions Functions = new DllTest.Funtions();

    foreach (String Files in listBox1.Items)
    {
        String File = Files;
        File = Functions.HashFunction();

        listBox2.Items.Add(File);
    }
}

However when i run the application i only get the catch messages appearing in the listbox. this is the error in the compiler when i use the method “A first chance exception of type ‘System.ArgumentNullException’ occurred in mscorlib.dll”

Is there anyway i can do this without rewritting the method in C#?

Sorry if my code isn’t the greatest i’m still pretty new to C++ and C#

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T01:22:57+00:00Added an answer on May 23, 2026 at 1:22 am

    Consulting my psychic debugger, I’ve determined that you want this in C++/CLI:

        String^ HashFunction(String^ filename)
        {
            array<Byte>^ Buffer = IO::File::ReadAllBytes(filename);
            array<Byte>^ Hash = MD5CryptoServiceProvider().ComputeHash(Buffer);
            return BitConverter::ToString(Hash);
        }
    

    and this in C#:

    private void button2_Click(object sender, RoutedEventArgs e)
    {
        foreach (String filename in listBox1.Items)
        {
            try {
                listBox2.Items.Add(Functions.HashFunction(filename));
            }
            catch (Exception ex) {
                MessageBox.Show(e.Message);
            }
        }
    }
    

    But my psychic debugger often malfunctions.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I go back to school after Thanksgiving, I'll be taking a course in
After reading the Head First Design Patterns book and using a number of other
After lots of attempts and search I have never found a satisfactory way to
After reading a bit more about how Gnutella and other P2P networks function, I
In our office, we regularly enjoy some rounds of foosball / table football after
Today I released a small asp.net beta web application which allows internal staff to
I've been experiencing a high degree of flicker and UI lag in a small
So here I believe I have a small buffer overflow problem I found when
I've been tinkering with small functions on my own time, trying to find ways
I have a question regarding some JavaScript, there is a big picture and the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.