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 4044824
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T13:20:24+00:00 2026-05-20T13:20:24+00:00

I have a C# form application…i created a Dll…now i want to launch that

  • 0

I have a C# form application…i created a Dll…now i want to launch that dll using this program. how do i do it?

#include <windows.h>

typedef int (*function1_ptr) ();

function1_ptr function1=NULL;

int APIENTRY WinMain(HINSTANCE, HINSTANCE, LPSTR, int) { 

HMODULE myDll = LoadLibrary("Dll1.dll"); 

    if(myDll!=NULL) {  
        function1 = (function1_ptr) GetProcAddress(myDll,"function1");  

        if(function1!=NULL)  
            function1();
        else
            exit(4);

        FreeLibrary(myDll);
    }
    else
        exit(6);
    GetLastError();

    return 0;
}

This was the code used to test my dll…i.e Dll1.dll..function1 was the function within dll1.dll…..can i do something similar with the C# code???

  • 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-20T13:20:25+00:00Added an answer on May 20, 2026 at 1:20 pm

    To do what your code example does, use the following C# code:

    public static class DllHelper
    {
        [System.Runtime.InteropServices.DllImport("Dll1.dll")]
        public static extern int function1();
    }
    
    private void buttonStart_Click(object sender, EventArgs e)
    {
        try
        {
            DllHelper.function1();
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }
    }      
    

    The above example is a C# program that calls a function in non .NET based DLL.
    The example below is a C# program that calls a function in a .NET based DLL.

    try
    {
        System.Reflection.Assembly dll1 = System.Reflection.Assembly.LoadFile("Dll1.dll");
        if (dll1 != null)
        {
            object obj = dll1.CreateInstance("Function1Class");
            if (obj != null)
            {
                System.Reflection.MethodInfo mi = obj.GetType().GetMethod("function1");
                mi.Invoke(obj, new object[0]);
            }
        }
    }
    catch (Exception ex)
    {
        Console.WriteLine(ex.Message);
    }
    

    Is any of the the 2 examples what you want?
    Or are you trying to call a C# function in a DLL from your example code?

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

Sidebar

Related Questions

I have a form in a Windows form application that I want to display
I have created a Windows Form Application using Visual C# 2008 Express Edition with
In a Windows Form application I have a Form with a UserControl that contains
I have an Windows Form application that supplies the User Name, Domain, and Password
I have a Windows form application that users can log into. The application is
I have a Windows Form application. What this application does, is let the user
I have this application (Windows form application written in Visual C++) from a colleague
I have a windows form application that needs to load a bunch of things
I have created a windows form application which uses an SQL database. The database
i have create a c# form application for parsing Html using Winista.html parser. Now

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.