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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:58:49+00:00 2026-06-09T12:58:49+00:00

I’m trying to import some functions from 32 bit and 64 bit DLLs written

  • 0

I’m trying to import some functions from 32 bit and 64 bit DLLs written in unmanaged C++ into my C# project. As a sample, I did this:

C++ DLL function

long mult(int a, int b) {
    return ((long) a)*((long) b);
}

C# code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace ConsoleApplication2
{
    class DynamicDLLImport
    {
        private IntPtr ptrToDll;
        private IntPtr ptrToFunctionToCall;

        [DllImport("kernel32.dll")]
        public static extern IntPtr LoadLibrary(string dllToLoad);

        [DllImport("kernel32.dll")]
        public static extern IntPtr GetProcAddress(IntPtr hModule, string procedureName);

        [DllImport("kernel32.dll")]
        public static extern bool FreeLibrary(IntPtr hModule);

        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
        private delegate int Multiply(int a, int b);
        private Multiply multiply;

        public DynamicDLLImport(string dllName)
        {
            ptrToDll = LoadLibrary(dllName);
            // TODO: Error handling.

            ptrToFunctionToCall = GetProcAddress(ptrToDll, "mult");
            // TODO: Error handling.

            // HERE ARGUMENTNULLEXCEPTION
            multiply = (Multiply)Marshal.GetDelegateForFunctionPointer(ptrToFunctionToCall, typeof(Multiply));
        }

        public int mult_func(int a, int b)
        {
            return multiply(a, b);
        }

        ~DynamicDLLImport()
        {
            FreeLibrary(ptrToDll);
        }
    }

    class DLLWrapper
    {
        private const string Sixtyfour = "c:\\Users\\Hattenn\\Documents\\Visual Studio 2010\\Projects\\ConsoleApplication2\\ConsoleApplication2\\easyDLL0_64.dll";
        private const string Thirtytwo = "c:\\Users\\Hattenn\\Documents\\Visual Studio 2010\\Projects\\ConsoleApplication2\\ConsoleApplication2\\easyDLL0.dll";
//        [DllImport(Sixtyfour)]
//        public static extern int mult(int a, int b);
        [DllImport(Thirtytwo)]
        public static extern int mult(int a, int b);
    }

    class Program
    {
        static void Main(string[] args)
        {
            int a = 5;
            int b = 4;
            DynamicDLLImport dllimp = new DynamicDLLImport("easyDLL0.dll");

            Console.WriteLine(DLLWrapper.mult(a, b));
            //Console.WriteLine(dllimp.mult_func(a, b));

            Console.ReadKey();
        }
    }
}

I can’t seem to get it to work. Here are the error messages that I get:

  1. When I use the DLLWrapper class with the 32 bit DLL file I get “DLLNotFoundException”, but the DLL file is exactly in that path.
  2. When I use the DLLWrapper class with the 64 bit DLL file and change the “Platform Target” property to “x64” I get the same “DLLNotFoundException”, if I try to build with “x86” then I get “BadImageException”.
  3. When I use the DynamicDLLImport class, I always get “ArgumentNullException” at the line commented with “HERE ARGUMENTNULLEXCEPTION” in the code.

What am I doing wrong?

  • 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-06-09T12:58:51+00:00Added an answer on June 9, 2026 at 12:58 pm

    The problem turned out to be that the dll was deployed in debug mode and not in a correct way. When it was deployed in release mode, everything seemed to work fine. Anyone having a similar problem should know that compiling the dll in debug mode and just copying it to another computer is not the right way to do it.

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

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Does anyone know how can I replace this 2 symbol below from the string
I am currently running into a problem where an element is coming back from
I have some data like this: 1 2 3 4 5 9 2 6
I am trying to understand how to use SyndicationItem to display feed which is

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.